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,给的那些测试数据都是对的,但就是WA,高手麻烦给看看:

Posted by zhb_msqx at 2007-08-21 21:56:22 on Problem 1719
#include <iostream>
#include <fstream>
using namespace std;

int row,col;
int data[1000][1000];//保存白颜色的格子
int mark[1000];     //标记第j列是否已经选过了
int coln[1000];     //记录每一列的第一个白格子的首地址,方便最后输出。

int result[1000];  //记录被选中的第j列的相应的行数 i

bool compute(int p){ //第p行
	if(p>row)return true;
	else{
		for(int j=1;j<=col;j++){
			if(data[p][j]==1&&mark[j]==0){
				mark[j]=1;
				result[j]=p;
				int test=compute(p+1);
				if(test)return true;
				mark[j]=0;
			}
		}
		if(j==col+1)return false;
	}
	return false;
}

void main(){
//	ifstream cin("data.txt");
	int testcase;
	cin>>testcase;
	for(int i=0;i<testcase;i++){
		cin>>row>>col;
		memset(data,0,sizeof(data));
		memset(result,0,sizeof(result));
		memset(mark,0,sizeof(mark));
		memset(coln,0,sizeof(coln));

		for(int j=1;j<=col;j++){
			int x1,x2;
			cin>>x1>>x2;
			data[x1][j]=1;
			data[x2][j]=1;
			coln[j]=x1;
		}
		bool test=compute(1);
		if(test){
			for(int tmp=1;tmp<col;tmp++){
				if(result[tmp]==0){
					cout<<coln[j]<<" ";  //随意输出一个
				}else{
					cout<<result[tmp]<<" ";
				}
			}
			if(result[col]==0){
				cout<<coln[col]<<endl;
			}else{
				cout<<result[col]<<endl;
			}
			//cout<<"Yes"<<endl;
		}else cout<<"No"<<endl;
	
	}



}

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