Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:增加水题ac人数。。。

Posted by gdczcpy at 2010-07-11 14:28:50 on Problem 3364
In Reply To:Re:这题用什么算法好啊?我用递归Memory: 1636K Time: 390MS,太差劲了 Posted by:D00050 at 2008-07-24 16:02:52
> 算右下角是白色格子的8*8棋盘个数
> ans=((m-7)*(n-7)+c)/2
//Black and white painting

#include <stdio.h>

int n, m, c;

void deal()
{
	int white_sum;
	if (m % 2 == 0)
		white_sum = n * (m / 2);
	else
	{
		white_sum = (n / 2) * (m / 2 + 1 + m / 2);
		white_sum += (n % 2) * (m / 2 + 1);
	}
	if (c == 0)
		white_sum = n * m - white_sum;
	if (m % 2 == 0)   //处理第8列  right
	{
		if (c == 1)
		{
		    if (n % 2 == 1)
		    	white_sum -= 4;
	    	else
		    	white_sum -= 3;
		}
		else
		{
			if (n % 2 == 1)
				white_sum -= 3;
			else
				white_sum -= 4;
		}
	}
	else
	{
		if (c == 0)
		{
			if (n % 2 == 1)
				white_sum -= 4;
			else
	            white_sum -= 3;
		}
		else
		{
            if (n % 2 == 1)
		    	white_sum -= 3;
	    	else
		    	white_sum -= 4;
		}
	}
	white_sum -= 7 * (n / 2);     //处理前7列
	if (c == 1)
	{
	    if (m % 2 == 1)	
		    white_sum -= 4 * (n % 2);
	    else
		    white_sum -= 3 * (n % 2);
	}
	else
	{
		if (m % 2 == 1)	
		    white_sum -= 3 * (n % 2);
	    else
		    white_sum -= 4 * (n % 2);
	}
	white_sum -= 7 * ((m - 8) / 2);     //处理前7行,去掉重复
	if (c == 1)
	{
        if (n % 2 == 0)	
		    white_sum -= 3 * ((m - 8) % 2);
    	else
	    	white_sum -= 4 * ((m - 8) % 2);
	}
	else
	{
		if (n % 2 == 0)	
		    white_sum -= 4 * ((m - 8) % 2);
    	else
	    	white_sum -= 3 * ((m - 8) % 2);
	}
    printf("%d\n", white_sum);
}

void input()
{
	while (scanf("%d%d%d", &n, &m, &c) && (n || m || c))
		   deal();
}

int main()
{
	input();
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator