码迷,mamicode.com
首页 > 其他好文 > 详细

kiki's game

时间:2017-02-06 23:50:57      阅读:261      评论:0      收藏:0      [点我收藏+]

标签:imp   play   check   stat   ssi   each   tin   sub   nbsp   

kiki‘s game

Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 40000/1000 K (Java/Others)
Total Submission(s): 253 Accepted Submission(s): 41
 
Problem Description
Recently kiki has nothing to do. While she is bored, an idea appears in his mind, she just playes the checkerboard game.The size of the chesserboard is n*m.First of all, a coin is placed in the top right corner(1,m). Each time one people can move the coin into the left, the underneath or the left-underneath blank space.The person who can‘t make a move will lose the game. kiki plays it with ZZ.The game always starts with kiki. If both play perfectly, who will win the game?
 
Input
Input contains multiple test cases. Each line contains two integer n, m (0<n,m<=2000). The input is terminated when n=0 and m=0.

 
Output
If kiki wins the game printf "Wonderful!", else "What a pity!".
 
Sample Input
5 3
5 4
6 6
0 0
 
Sample Output
What a pity!
Wonderful!
Wonderful!
 
Author
月野兔
 
Source
HDU 2007-11 Programming Contest
 
Recommend
威士忌
 
/*
题意:就是一个n*m的棋盘,棋子在右上角(1,m),轮流走棋子,向左,向下,向左下,如果有人无法再走了,那么这个人就输了。

初步思路:递推,左下角是必败点,然后推,如果n*m是奇数那么先走的人一定输,反之则赢

#错误:直接判断奇偶会爆内存?!!要单独判断n m......单独判断还是炸
    看了原题,这个内存弄错了,这不是摆明了要用java么
*/
#include<stdio.h>
int main(){
    int n,m;
    while(scanf("%d%d",&n,&m)!=EOF&&(n+m)){
        if((n&1)&&(m&1)) printf("What a pity!\n");
        else printf("Wonderful!\n");
    }
}

java版的

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
    // write your code here
        Scanner cin=new Scanner(System.in);
        int n,m;
        while(cin.hasNext()){
            n=cin.nextInt();
            m=cin.nextInt();
            if(n==0&&m==0) break;
            if(n%2==1&&m%2==1) System.out.println("What a pity!");
            else System.out.println("Wonderful!");
        }
    }
}

 

kiki's game

标签:imp   play   check   stat   ssi   each   tin   sub   nbsp   

原文地址:http://www.cnblogs.com/wuwangchuxin0924/p/6372028.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!