POJ 2605 数学


http://poj.org/problem?id=2605


Simple game on a grid
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 931 Accepted: 482

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

Source


题目大意:

给你一个n*m的矩阵,尽可能多的消去里面所有的石头,最后剩下几颗


其实就是找规律,表示和同学一起也找了半天

①如果是3*n的话,那么最后肯定能变成3*1的类型的,那么就是剩下两个。

②如果是2*n(n不能被3整除)或者是1*n(同2*n)的话,那么就是(n+1)/2。

③如果是4*n,5*n(n不能被3整除,且大于2)的话,那么就也只是剩下一个。(具体的操作自己去划一下才有感觉)

于是我们通过归纳得到,

当n大于3的时候,如果n和m在都不能被3整除,那么就是1。

当n=3的时候就是2

当n=1和2的时候就是(n+1)/2;

#include
   
   
    
    
#include
    
    
     
     
#include
     
     
      
      

using namespace std;


int main(){
    int n, m;
    while (scanf("%d%d", &n, &m) == 2){
        if (n > m) swap(n, m);
        int res = 0;
        if (n == 1){
            res = (m + 1) / 2;
        }
        else if (n % 3 == 0 || m % 3 == 0){
            res = 2;
        }
        else res = 1;
        printf("%d\n", res);
    }
    return 0;
}
     
     
    
    
   
   


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值