您的位置:首页 > 其它

poj 2605 Simple game on a grid

2011-11-22 12:52 281 查看
Simple game on a grid

Time Limit: 1000MSMemory Limit: 65536K
Total Submissions: 847Accepted: 435
Description

There is an infinite grid and an m*n rectangle of stones on it (1 <= m,n <= 1000). The stones are located in the knots of the grid.

A following game for a single player is being played. One stone can jump over another along a vertical or a horizontal line. A stone which had been overjumped is taken away. The purpose of the game is to minimize number of stones on a grid.

Given a pair of numbers m and n separated with one space in an input file you are to write a program which should determine a minimal number of the stones left on the grid.
Input

Numbers m and n separated by space.
Output

The minimal number of the stones left on the grid.
Sample Input

3 4

Sample Output

2


#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;
}



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: