标签:for put time als chess input represent ant sum
http://poj.org/problem?id=2446
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 18560 | Accepted: 5857 |
Description
Input
Output
Sample Input
4 3 2 2 1 3 3
Sample Output
YES
Hint
Source
1 #include <algorithm> 2 #include <cstring> 3 #include <cstdio> 4 5 using namespace std; 6 7 const int N(32*32); 8 int n,m,p,x,y,ans; 9 int match[N][N][2],lose[N][N]; 10 int vis[N][N],sumvis; 11 int fx[4]={1,0,-1,0}; 12 int fy[4]={0,1,0,-1}; 13 14 bool DFS(int x,int y) 15 { 16 for(int i=0;i<4;i++) 17 { 18 int xx=x+fx[i], yy=y+fy[i]; 19 if(vis[xx][yy]!=sumvis&&!lose[xx][yy]) 20 { 21 vis[xx][yy]=sumvis; 22 if(!match[xx][yy][0]||DFS(match[xx][yy][0],match[xx][yy][1])) 23 { 24 match[xx][yy][0]=x; 25 match[xx][yy][1]=y; 26 return true; 27 } 28 } 29 } 30 return false; 31 } 32 33 int main() 34 { 35 while(~scanf("%d%d%d",&n,&m,&p)) 36 { 37 if((n*m-p)%2) 38 { 39 printf("NO\n"); 40 continue; 41 } 42 ans=sumvis=0; 43 memset(vis,0,sizeof(vis)); 44 memset(lose,0,sizeof(lose)); 45 memset(match,0,sizeof(match)); 46 for(int i=1;i<=p;i++) 47 { 48 scanf("%d%d",&x,&y); 49 lose[y][x]=1; 50 } 51 for(int i=0;i<=n;i++) 52 lose[i][0]=lose[i][m+1]=1; 53 for(int i=0;i<=m;i++) 54 lose[0][i]=lose[n+1][i]=1; 55 for(int i=1;i<=n;i++) 56 for(int j=1;j<=m;j++) 57 if((i+j)%2==0&&!lose[i][j]) 58 { 59 sumvis++; 60 if(DFS(i,j)) ans++; 61 } 62 if(ans*2+p==m*n) printf("YES\n"); 63 else printf("NO\n"); 64 } 65 return 0; 66 }
标签:for put time als chess input represent ant sum
原文地址:http://www.cnblogs.com/Shy-key/p/6901269.html