| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:实不相瞒弱菜学妹 做了两天没做成功..贴上代码,求大神指正,小妹不胜感激In Reply To:实不相瞒弱菜学妹 做了两天没做成功..贴上代码,求大神指正,小妹不胜感激 Posted by:ninesun127 at 2016-10-20 13:35:59 > #include<iostream>
> #include<cstring>
> #define N (((x-1)/3)*3+ (y-1)/3+1)
> //#define (!book_row[i][j]&&!book_col[i][j]&&!book[N][j])
> using namespace std;
>
> int map[10][10];
> char _map[10][10];
>
> int bookr[10][10];//进行行的标记
> int bookc[10][10];//进行列的标记
> int booka[10][10];//进行小块的标记
> int flag;
>
> /*怎么判断第i行第j列位于第几块(行主序)是重点;
> area=((i-1)/3)*3+ j/3+1;
> 跑一个:
> 1 1 1 2 2 2 3 3 3
> 1 1 1 2 2 2 3 3 3
> 1 1 1 2 2 2 3 3 3
> 4 4 4 5 5 5 6 6 6
> 4 4 4 5 5 5 6 6 6
> 4 4 4 5 5 5 6 6 6
> 7 7 7 8 8 8 9 9 9
> 7 7 7 8 8 8 9 9 9
> 7 7 7 8 8 8 9 9 9
>
> --------------------------------
> Process exited after 0.04042 seconds with return value 0
> 请按任意键继续. . .
> */
>
> void dfs(int x,int y)
> {
> if(flag)return;
>
> if(x==9&&y==10)
> {
> flag=1;
> for(int i=1;i<=9;i++)
> {
> for(int j=1;j<=9;j++)
> cout<<map[i][j];
>
> cout<<endl;
> }
> return;
>
>
> }
>
>
>
> if(x<1||x>9||y<1||y>9)return;
>
>
> if(map[x][y])
> {
> //cout<<"x: "<<x<<" y: "<<y<<" map[x][y] "<<map[x][y]<<endl;
> dfs(x,y+1);
> dfs(x+1,1);
> }
>
> int k;
> for( k=1;k<=9;k++)
> {
> if(!bookr[x][k]&&!bookc[y][k]&&!booka[N][k])
> {
> bookr[x][k]=1;
> bookc[y][k]=1;
> booka[N][k]=1;
> map[x][y]=k;
> //cout<<"x: "<<x<<" y: "<<y<<" map[x][y] "<<map[x][y]<<" N: "<<N<<endl;
>
> dfs(x,y+1);
> dfs(x+1,1);
>
> bookr[x][k]=0;
> bookc[y][k]=0;
> booka[N][k]=0;
> }
> }
>
> }
> int main()
> {
> int t;
> cin>>t;
>
> while(t--)
> {
> flag=0;
> memset(bookr,0,sizeof(bookr));
> memset(bookc,0,sizeof(bookc));
> memset(booka,0,sizeof(booka));
>
> for(int i=1;i<=9;i++)
> for(int j=1;j<=9;j++)
> {
> cin>>_map[i][j];
> map[i][j]=_map[i][j]-'0';
>
> if(map[i][j])
> { int x=i;int y=j;
> bookr[i][map[i][j]]=1;
> bookc[j][map[i][j]]=1;
> booka[N][map[i][j]]=1;
> // cout<<i<<' '<<j<<" "<<N<<endl;
> }
>
> }
>
> dfs(1,1);
>
>
> }
>
> return 0;
> }
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator