poj 2585
来源:互联网 发布:linux ansi 绿色 编辑:程序博客网 时间:2024/06/14 22:45
构图 然后toposort就OK了
#include<stdio.h>#include<string.h>#include<iostream>#include<string>#include<queue>using namespace std;int sx[10]={0,1,1,1,2,2,2,3,3,3};int sy[10]={0,1,2,3,1,2,3,1,2,3};int my[4]={0,0,1,1};int mx[4]={0,1,0,1};int judge[15][15];int sum[15];int a[10][10];int toposort(){ //printf("yes\n"); int cnt; queue<int> q; for(int i=1;i<=9;i++){ if(sum[i]==0) q.push(i); } cnt=0; while(!q.empty()){ //printf("yes\n"); int t=q.front(); q.pop(); cnt++; for(int i=1;i<=9;i++){ if(judge[t][i]==1) { sum[i]--; //judge[t][i]=0; if(sum[i]==0) q.push(i); } } } if(cnt==9) return 1; else return 0;}int main(){ string d="ENDOFINPUT"; string s; cin>>s; while(s!=d){ memset(judge,0,sizeof(judge)); memset(sum,0,sizeof(sum)); //printf("yes\n"); for(int i=1;i<=4;i++){ for(int j=1;j<=4;j++){ scanf("%d",&a[i][j]); } } cin>>s; //printf("yes"); /* for(int i=1;i<=4;i++){ for(int j=1;j<=4;j++) { printf("%d",a[i][j]); } printf("\n"); }*/ for(int i=1;i<=9;i++){ int ssx=sx[i]; int ssy=sy[i]; for(int j=0;j<4;j++){ int nx=ssx+mx[j]; int ny=ssy+my[j]; if(a[nx][ny]!=i&&judge[a[nx][ny]][i]==0){ judge[a[nx][ny]][i]=1; sum[i]++; } } } //for(int i=1;i<=9;i++) printf("%d\n",sum[i]); //printf("yes"); int yes=toposort(); if(yes==1){ printf("THESE WINDOWS ARE CLEAN\n"); } else if(yes==0){ printf("THESE WINDOWS ARE BROKEN\n"); } cin>>s; } return 0;}
0 0
- poj 2585
- poj 2585
- poj 2585
- POJ 2585 拓扑排序
- poj 2585 Window Pains
- poj 2585& zoj 2193
- POJ 2585 拓扑排序
- POJ-2585 Window Pains
- poj 2585 Window Pains
- POJ-2585 Window Pains
- POJ 2585Window Pains
- 【POJ】[2585]Window Pains
- Window Pains POJ 2585
- POJ
- poj
- POJ
- POJ
- poj
- 【Linux 入门笔记】文件系统基本结构和操作
- MyEclipse连接MySQL的方法
- ubuntu12.04 安装KVM
- 项目一(3)。复制构造函数
- HDU 2159 FATE (二维费用背包)
- poj 2585
- 墓碑移动 LA3708(圆上点的移动)
- TInifile(1)
- xcode更新到5.1,"Cast from pointer to smaller type 'int' loses information” in EAGLView.mm
- JXTA PeerGroupFactory类替换
- Plugin org.apache.maven.plugins:maven-compiler-plugin:2.0.2 or one of its dependencies could not be
- 004
- Monkeyrunner学习之三(如何使用坐标去点击的方法)
- 打印螺旋矩阵