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 xihushuzi at 2011-07-29 22:30:44 on Problem 1130
#include<iostream>
#include<queue>
using namespace std;
queue<int> q;// 定义队列

int *m;
int mark[101][101];
bool dfs(int nod_father,int nod,int et,int **c,int n){
	if(nod_father==et){// 从 nod 开始找 到了
		return true;
	}
	for(int l=0;l<n;l++){
		if(l!=nod && c[nod_father][l]==1 && !mark[nod_father][l]){
			mark[nod_father][l]=1;
			dfs(l,nod,et,c,n);
			mark[nod_father][l]=0;
		}
	}
	return false;
}

bool seatch(int nod,int e,int n,int **c){// 找到 nod 的父结点是否有不经过过 nod 找到 e 点的 ,有则返回 false
	for(int r=0;r<n;r++){
		if(c[r][nod]==1){// 找到 nod 父节点 r
			memset(mark,0,sizeof(mark));
			if(!dfs(r,nod,e,c,n)){
				return true;
			}
		}
	}
	return false;
}
void solve(int **c,int n,int e){//
	int et=e;
	for(int i=0;i<n;i++){// i 表示的是行值
			if(c[i][et]==1 && m[i]==0){// 找到离 ET 最近的点 nod
				q.push(i);
				m[i]=1;
			}
	}
	while(!q.empty()){
		et=q.front();
		q.pop();
		for(int i=0;i<n;i++){// i 表示的是行值
			if(c[i][et]==1 && m[i]==0){// 找到离 ET 最近的点 nod
				q.push(i);
				m[i]=1;
			}
		}
		if(seatch(et, e, n,c)){
			cout<<"Put guards in room "<<et<<"."<<endl;
			return ;
		}
	}
}
int main(void){
	int n,e,**c;

	int i,j;
	int *v;
	cin>>n>>e;
	c=new int*[n];
	m=new int[n];
	v=new int[n];
	for( i=0;i<n;i++){
		m[i]=0;
		v[i]=0;
		c[i]=new int[n];
		for( j=0;j<n;j++){
			c[i][j]=0;
			mark[i][j]=0;
		}
	}
	int t=n;
	int a,b;
	while(cin>>a>>b){
		c[a][b]=1;
	}
	solve(c,n,e);
	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