BZOJ3109: [cqoi2013]新数独
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=3109
搜索一遍。读入注意一下。。
#include<cstring> #include<cstdio> #include<iostream> #include<algorithm> #include<cmath> #define rep(i,l,r) for (int i=l;i<=r;i++) #define down(i,l,r) for (int i=l;i>=r;i--) #define clr(x,y) memset(x,y,sizeof(x)) #define maxn 1000500 using namespace std; bool bx[10][10],by[10][10],bz[10][10][10]; int mpd[100][100],mpr[100][100],mp[100][100],chx[10],chy[10]; int cnt1,cnt2,flag; char ch; int read(){ int x=0,f=1; char ch=getchar(); while (!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();} while (isdigit(ch)) {x=x*10+ch-'0'; ch=getchar();} return x*f; } bool jud(int x,int y,int val){ if (bx[x][val]||by[y][val]||bz[(x-1)/3][(y-1)/3][val]) return 0; if (mpr[x][y-1]!=0) { if (mpr[x][y-1]==1&&mp[x][y-1]<val) return 0; if (mpr[x][y-1]==-1&&mp[x][y-1]>val) return 0; } if (mpd[x-1][y]!=0){ if (mpd[x-1][y]==1&&mp[x-1][y]<val) return 0; if (mpd[x-1][y]==-1&&mp[x-1][y]>val) return 0; } return 1; } void print(){ rep(i,1,9) { rep(j,1,8) printf("%d ",mp[i][j]); printf("%d\n",mp[i][9]); } } void dfs(int x,int y){ if (x==10) {flag=1; print(); return;} if (flag) return; rep(i,1,9) if (jud(x,y,i)) { bx[x][i]=1; by[y][i]=1; bz[(x-1)/3][(y-1)/3][i]=1; mp[x][y]=i; if (y==9) dfs(x+1,1); else dfs(x,y+1); bx[x][i]=0; by[y][i]=0; bz[(x-1)/3][(y-1)/3][i]=0; } } int main(){ //freopen("in.txt","r",stdin); rep(t,0,2){ cnt1=cnt2=0; rep(i,1,5){ if (i&1){ cnt1++; rep(j,1,6) { ch=getchar(); while (ch!='<'&&ch!='>') ch=getchar(); if (ch=='<') chx[j]=-1; else chx[j]=1; } // rep(j,1,6) printf("%d ",chx[j]); puts(""); rep(j,0,2) rep(k,1,2) mpr[cnt1+t*3][k+j*3]=chx[j*2+k];//,printf("%d %d %d\n",cnt1+t*3,k+j*3,mpr[cnt1+t*3][k+j*3]); } else { cnt2++; rep(j,1,9) { ch=getchar(); while (ch!='v'&&ch!='^') ch=getchar(); if (ch=='v') chy[j]=1; else chy[j]=-1; } rep(j,0,2) rep(k,1,3) mpd[cnt2+t*3][k+j*3]=chy[j*3+k];//,printf("%d %d %d\n",cnt2+t*3,k+j*3,mpd[cnt2+t*3][k+j*3]); } } } dfs(1,1); return 0; }