Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:开心

Posted by sjkshl at 2014-10-18 20:10:06 on Problem 1166
In Reply To:开心 Posted by:hzgood at 2012-07-10 10:27:52
> #include<cstdio>
> #include<iostream>
> using namespace std;
> int f[9]={0};
> int a[9]={9};
> int flag;
> int m[9][9] ={ {1,1,0,1,1,0,0,0,0},
> {1,1,1,0,0,0,0,0,0},
> {0,1,1,0,1,1,0,0,0},
> {1,0,0,1,0,0,1,0,0},
> {0,1,0,1,1,1,0,1,0},
> {0,0,1,0,0,1,0,0,1},
> {0,0,0,1,1,0,1,1,0},
> {0,0,0,0,0,0,1,1,1},
> {0,0,0,0,1,1,0,1,1}};
> 
> void out()
> {
>     for (int i = 0; i<9; i++)
>         for (int j = 0; j < f[i];j++)
>             printf("%d ",i+1);
>     printf("\n");
> }
> int tmp[9] = {0};
> int judge()
> {
>     int i,j;
> 
>     for (i = 0; i < 9; i++)
>         {
>             tmp[i] = a[i];
>             //cout<<tmp[i]<<' ';
>             for (j = 0; j < 9; j++)
>             {
>                 tmp[i]+=f[j]*m[j][i];
>             }
>             if (tmp[i] % 4) break;
>         }
>     //cout<<i<<endl;
>     if (i == 9)
>     {
> 
>         flag = 0;
>         return 1;//!!
>     }
>     return 0;//!!
> }
> 
> void dfs(int n)
> {
>     if (n == 9)
>     {
>     if ( judge())
>         {
>             flag = 0;
>             out();
>             return;
>         }
>         return;
>     }
>     if (flag)
>         {
>             for (int i = 0; i<4; i++)
>             {
>                 f[n] = i;
>                 dfs(n+1);
>                 if (flag == 0) return;
>                 f[n] = 0;
>             }
>         }
> }
> 
> int main()
> {
>     //freopen("1166.txt","r",stdin);
> 
>     for (int i = 0; i<9; i++) scanf("%d",&a[i]);
>     flag = 1;
>     dfs(0);
> 
> }
哈哈

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator