zoj 1008 Gnome Tetravex
2015-12-12 19:51
363 查看
开放式存储阵列为每平方米有几个,否则,超时……
#include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <stack> #include <set> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <time.h> using namespace std; int mp[30][5],n,flag,p[10][10],sum[30],cnt; int check(int k,int i) { int x,y,f=1; x=k/n; y=k%n; if(x==0&&y==0) return 1; if(x-1>=0) { if(mp[i][1]!=mp[p[x-1][y]][3]) f=0; } if(y-1>=0) { if(mp[i][4]!=mp[p[x][y-1]][2]) f=0; } if(f) return 1; else return 0; } void dfs(int k) { int i,j,x,y; if(k==n*n) { flag=1; return; } for(i=0; i<cnt; i++) { if(sum[i]==0) continue; if(check(k,i)) { x=k/n; y=k%n; p[x][y]=i; sum[i]--; dfs(k+1); sum[i]++; if(flag==1) return; } } return; } int main() { int cas=0,i,j,a,b,c,d; while(~scanf("%d",&n)&&n) { cnt=0; memset(sum,0,sizeof(sum)); if(cas) printf("\n"); for(i=0; i<n*n; i++) { scanf("%d%d%d%d",&a,&b,&c,&d); for(j=0; j<cnt; j++) { if(mp[j][1]==a&&mp[j][2]==b&&mp[j][3]==c&&mp[j][4]==d) break; } if(j<cnt) sum[j]++; else { cnt++; sum[j]=1; mp[j][1]=a; mp[j][2]=b; mp[j][3]=c; mp[j][4]=d; } } flag=0; dfs(0); printf("Game %d: ",++cas); if(flag) printf("Possible\n"); else printf("Impossible\n"); } return 0; }
相关文章推荐
- M阶B树具体实现
- 使用了非标准扩展:“xxx”使用 SEH,并且“xxx”有析构函数
- 篮桥杯入门训练 圆的面积
- 农行网银软件导致XP死机
- Lua语言教程0 ——编译环境搭建
- [javase学习笔记]-3.2 switch语句
- 【NuGet】远程服务器返回错误:<403>已禁止
- 链表的基本功能实现
- jwt(json-web-token)在rest中的实现--jersey
- linux内存泄漏检测
- APUE:实际用户ID和有效用户ID(euid)
- 推荐几篇学习rest风格的文章
- Mantle源代码阅读笔记 一
- (Fun)*((int*)*(int*)(&b)); http://bbs.csdn.net/topics/320008423
- 20151212jquery学习笔记--工具函数
- codeforces 418 C Square Table (随机算法)
- SAX解析XML文件
- VS2013下 开发简单的MFC小程序
- linux C 学习---函数指针
- JavaScript、CSS、HTML 实现用户注册页面与信息校验