HDU 1175 See

Source: Internet
Author: User

Watch Time limit:20000/10000ms (java/other) Memory limit:65536/32768k (Java/other) total submission (s): Accepted Submission (s): 29font:times New Roman | Verdana | Georgiafont Size:←→problem Description "repeatedly see" believe that a lot of people have played. It doesn't matter if you have not played, let me introduce you to the rules of the game: in a chessboard, put a lot of pieces. If two identical pieces can be connected by a line (this line cannot pass through other pieces), and the number of transitions of the line is not more than two times, then the two pieces can be eliminated on the board. Sorry, because I have not played a long time to see, consulted the views of the students, the connection can not be around the past, but in fact it is wrong. Now has become a catastrophe, you can only will wrong, wiring can not be bypassed from the periphery.
The player mouse has clicked on two pieces, trying to eliminate them, and then the game's background to determine whether the two squares can be eliminated. Now your task is to write this daemon. Input data has multiple groups. The first row of each group of data has two positive integer n,m (0<n<=1000,0<m<1000), representing the number of rows and columns of the board, respectively. In the next n rows, each row has a m nonnegative integer describing the checkerboard's grid distribution. 0 means there is no pawn in this position, and a positive integer indicates the type of pawn. The next line is a positive integer q (0<q<50), which indicates that there is a Q query below. In the next Q line, there are four positive integer x1,y1,x2,y2 per line, which indicates that the pieces with the X1 row y1 column and the first X2 row y2 column can be eliminated. When n=0,m=0, the input ends.
Note: There is no relationship between inquiries, it is for the current state! Output each set of input data corresponds to a row of outputs. If you can eliminate the output "YES", you cannot output "no". Sample Input
3 41 2 3 40 0 0 04 3 2 141 1 3 41 1 2 41 1 3 32 1 2 43 40 1 4 30 2 4 10 0 0 021 1 2 41 3 2 30 0
Sample Output
Yesnonononoyes
Authorlwg

#include <iostream>#include<cstdio>#include<deque>#include<cstring>using namespacestd;structnode{intX,y,num;}; Deque<node>s;inti,n,m,j,sx,sy,tx,ty,t;intvis[1002][1002],a[1002][1002];intdr[4][2]={ {1,0},{0,1},{0,-1},{-1,0} };intBFS () {node p; P.x=SX; P.Y=Sy; P.num=-1; Vis[sx][sy]=1;    S.push_back (P);  while(!S.empty ())        {node T; T=S.front ();  for(intI=0;i<4; i++)        {            intxx=t.x+dr[i][0]; intyy=t.y+dr[i][1];  while(xx>0&& xx<=n && yy>0&& yy<=m && a[xx][yy]==0)            {                if(!Vis[xx][yy]) {p.x=xx; P.Y=yy; P.num=t.num+1; VIS[XX][YY]=1;                S.push_back (P); } xx=xx+dr[i][0]; YY=yy+dr[i][1]; }            if(Xx==tx && yy==ty)if(t.num+1>2)return 0; Else return 1;    } s.pop_front (); }    return 0;}intMain () { while(~SCANF ("%d%d", &n,&m) && n!=0 )    {         for(i=1; i<=n;i++)             for(j=1; j<=m;j++) scanf ("%d",&A[i][j]); scanf ("%d",&t);  for(;t>0; t--) {scanf ("%d%d%d%d",&sx,&sy,&tx,&ty); if(A[sx][sy]!=a[tx][ty] | | a[sx][sy]==0|| a[tx][ty]==0) {printf ("no\n"); Continue;            } s.clear (); memset (Vis,0,sizeof(VIS)); if(BFS ()) printf ("yes\n"); Elseprintf"no\n"); }    }    return 0;}

HDU 1175 See

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.