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

复杂的表面下是如此的简洁!

Posted by sxtpy at 2006-11-15 14:43:26 on Problem 2605
#include <stdio.h>

int main()
{
	int m,n,t;
	while(scanf("%d%d",&m,&n)!=EOF)
	{
		if(n>m) {t=n;n=m;m=t;}
		if(n==1 || n==2) printf("%d\n",(m+1)/2);
		else if(n%3==0 || m%3==0) printf("2\n");
		else printf("1\n");
	}
	return 0;
}
/* 复杂的表面下是如此的简洁!
   1,如果在边界上连续的三个,并且其内层有x的情况则可消去,如下:
	  --x  --- --- --x
	  xxx  xx- --x --- (此为边界层)
	  ---  --x --x ---
   2,不妨假设n<=m,则在n>=3的情况下,如n,m中有一数可被3整除,则可消成xxx的情况,如下:
         n=4行,m=6列  消去前n%3行的前m-3个x        消去前m-3列          由下往上消去n-1行
	xxxxxx		---xxx			---xxx		 ---xxx
	xxxxxx		xxxxxx			---xxx		 ------
	xxxxxx		xxxxxx			---xxx		 ------
	xxxxxx		xxxxxx			---xxx		 ------
   3,在2的假设下,但n,m都不被3整除.则通过消去构造被3整除的情况,如下:
        n=4行,m=5列  消去前n%3行的前m-m%3个x    根据2,把第n%3+1行到第n行消成:
	xxxxx		---xx		   ---xx
	xxxxx		xxxxx		   --xxx
	xxxxx		xxxxx		   -----
	xxxxx		xxxxx		   -----
  
        再根据1最终结果为	
	  ---xx
	  -----
	  -----
           -----
	   不难证明最后留下的区域大小为n%3行,m%3列,而这总可以消成只剩1个x。
    4,最后讨论一下n=1,2的情况
      其实n=2等同n=1,第2行所有x跨过第1行即可,所以只考虑n=1.
         m=4	    中间的x往两边跳	最终结果为(m+1)/2个x
	xxxx	     x----x
 */

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