Light OJ 1393 Crazy Calendar (Nim game)

Source: Internet
Author: User


C-crazy Calendar Time Limit:4000MS Memory Limit:32768KB 64bit IO Format:%LLD &%llusubmit Status Practice Lightoj 1393


Description



is a crazy year. Many people all over the world proposed on 11-11-11, married on 11-11-11, some even went through surgery-only for have 11-1 1-11 as their child ' s birth date. How crazy people can be! Don ' t They see there is a "hidden"? What did you do? A very elegant solution came from ARR, a very famous and funny character-why does we need to follow Christian (or some CAL ls it gregorian) calendar? Why don ' t do we start our own calendar on the day of marriage? And those to celebrate their marriage ceremony too frequent, why don ' t they declare is only 1 day per year. In this fashion they can celebrate their anniversary every day. And May is one minute a year or a second or ... Uh.. Getting complex. Let's back to the title. From now, we start to has a new calendar system, "Kisu Pari Na". And we hope to update this calendar on every national contest.



The purpose of this calendar is-we all would try our best to learn something new in every year. For the first year of let ' s learn some combinatory. It reminds me of my first year in college. I faced this problem but could not solve this then.


  

 


 


 


  

 

   


 

        

                  



Say you start from the upper left cell and the want to go to the lower right cell. The only restriction are can only move downward or rightward. How many ways is there? How to solve it? Not that difficult. Three times right (whichever-go) to reach the goal from the starting cell, Righ T? So the answer are number of ways you can arrange a D (represents down) and three R (represent right). 2 same characters and 3 same characters, total 5 characters. So it is:



Or =D+RCR. Easy isn ' t it?



Ok enough with learning. Now the back to problem, given a grids and at each cell there is some coins. Inky and Pinky is playing a game getting inspiration from the above problem. At each turn, a-player chooses a non empty cell and then removes-one or more coins from this cell and put them to the cell Exactly right of it or exactly beneath it. A player can ' t divide the coins and put one part to right and others to down. Note that, for the cells in the right column of the player can ' t move it to more right, and same for the Bottom-most row. So-a player can ' t move coins from the lower right cell. The game would finish when no moves is available and the player moved last would win. Now inky being very modest asked Pinky to move first. Can you say if Pinky would win if both play perfectly?



Input



Input starts with an integer T (≤100), denoting the number of test cases.



Each case starts with a line containing the integers r C (1≤r * c≤50000), where R denotes the number of rows and C denotes the number of columns of the grid respectively. Each of the next R lines contains C space separated integers denoting the grid. These integers lie in the range [0, 109].



Output



For every test case, the output case number followed by "Win" if Pinky can win or "lose".



Sample Input



1



2 2



1 1



1 1



Sample Output


Case 1:lose
Test instructions
Given a square of n*m, each square contains x stones, Pinky the initiator, each move to the right or down, who cannot move who loses.
 
#include <iostream> #include <stdio.h> using namespace std; int main()
{ int i,j,n,m,t,x,cas=1;
    cin>>t; while(t--)
    { int ans=0;
        cin>>n>>m; int tmp=(n+m)%2; for(i=0;i<n;i++)
        { for(j=0;j<m;j++)
            {
                cin>>x; int a=(i+j)%2; if(a!=tmp)
                ans^=x;
            }
        } if(ans)
            printf("Case %d: win\n",cas++); else printf("Case %d: lose\n",cas++);



    } return 0;
}





Light OJ 1393 Crazy Calendar (Nim game)


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.