SCU 3132 (game)

Source: Internet
Author: User

Portal: Windy and Mercury-Mercury Games 1

Test instructions: On a chessboard composed of N*m, the K Knight is placed on the board of each knight (Xi,yi), indicating the first XI line, the Knight row if the current position is (x, y), a step can go to the position of

(x-2,y-1)

(x-2,y+1)

(x-1,y-2)

(x+1,y-2)

Two people, each move a knight, at the same time can have more than one knight in the same lattice, who can not move who loses now given the initial chess face, ask the initiator whether there is a winning strategy?

Analysis: The K Knight as a K-game, and then find the K game of the SG value, and then the problem into a K heap stone, each heap has sg[i] a stone, the initiator can choose a heap to take 1~sg[i] a stone, take the final stone people win, it becomes the naked Nim game, All SG values are different or judged to be 0.

#include <cstdio>#include<cstring>#include<algorithm>#defineN 110using namespacestd;intn,m,k;intSg[n][n];intdx[]={-2,-2,-1,1};intdy[]={-1,1,-2,-2};BOOLJudgeintAintb) {    returna>=0&&a<n&&b>=0&&b<m;}intDfsintXinty) {    if(~sg[x][y])returnSg[x][y]; intvis[5],temp; memset (Vis,false,sizeof(VIS));  for(intI=0;i<4; i++)    {        inta=x+dx[i],b=y+Dy[i]; if(!judge (A, B))Continue; if((Temp=sg[x][y]) ==-1) temp=Dfs (A, b); Vis[temp]=1; }     for(intI=0;i<5; i++)    {        if(Vis[i])Continue; returnsg[x][y]=i; }}intMain () { while(SCANF ("%d%d%d", &n,&m,&k) >0) {memset (SG,-1,sizeof(SG));  for(intI=0; i<n;i++)             for(intj=0; j<m;j++)            if(sg[i][j]==-1) DFS (I,J); intx,y,flag=0;  while(k--) {scanf ("%d%d",&x,&X); if(Sg[x][y]) flag=1; }        if(flag) puts ("Yes"); ElsePuts"No"); }}
View Code

SCU 3132 (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.