zoukankan      html  css  js  c++  java
  • kiki's game

    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!
    ");
            else printf("Wonderful!
    ");
        }
    }

    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!");
            }
        }
    }
  • 相关阅读:
    与非
    抄卡组
    数据结构》关于差分约束的两三事(BZOJ2330)
    刷题向》图论》BZOJ1179 关于tarjan和SPFA的15秒(normal)
    图论算法》关于tarjan算法两三事
    图论算法》关于SPFA和Dijkstra算法的两三事
    刷题向》DP》值得一做》关于对DP问题的充分考虑(normal)
    数据结构》关于线段树两三事(新手向)(工具向)
    图论算法》关于匈牙利算法的两三事
    关于羊和车的问题
  • 原文地址:https://www.cnblogs.com/wuwangchuxin0924/p/6372028.html
Copyright © 2011-2022 走看看