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

为什么WA了。。。跪求教!

Posted by appleleaves at 2015-03-08 10:39:54 on Problem 2965
#include<stdio.h>
bool pan[4][4];
struct sit
{
	int x,y;
}sits[16];
bool ok(bool pan[4][4])
{
	int i,j;
    for(i=0;i<4;++i){
        for(j=0;j<4;++j){
            if(pan[i][j]==0)return 0;
        }
    }
    return 1;
}
void flip(int x,int y)
{
	int i;
    pan[x][y]=!pan[x][y];
    for(i=0;i<4;++i){
		pan[i][y]=!pan[i][y];
		pan[x][i]=!pan[x][i];
	}
}
bool work(int n,int x)
{
    if(n==0){
        if(ok(pan))return 1;
        else return 0;
    }
	int t=1;
	int i,j;
    for(i=x/4;(i<4)&&t;++i){
        for(j=x%4;(j<4)&&t;++j){
            flip(i,j);
            if(work(n-1,i*4+j+1)){
				t=0;
				sits[n-1].x=i+1;
				sits[n-1].y=j+1;
			}
			flip(i,j);
        }
    }
	return !t;
}

int main()
{
    int k;
	int i,j;
    for(i=0;i<4;++i){
        char row[8];
        scanf("%s",row);
        for(j=0;j<4;++j){
            pan[i][j]=(row[j]=='+')?0:1;
        }
    }
    for(k=0;k<=16;++k){
        if(work(k,0)){
            printf("%d\n",k);
			for(i=k-1;i>=0;--i){
				printf("%d %d\n",sits[i].x,sits[i].y);
			}
            return 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