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 lesileqin at 2019-08-25 18:48:19 on Problem 1386
#include<iostream>
#include<vector>
#include<cstring>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<algorithm>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define MAXN 30
#define INF 999999

int V,E;
bool G[MAXN][MAXN];
//vector<int> edge[MAXN];
int in[MAXN];
int out[MAXN];
bool vis[MAXN];
int MIN,MAX,n;

void dfs_lt(int v){
	n++;
	vis[v]=true;
	for(int i=0;i<MAXN;i++){
		if(G[v][i]==true&&vis[i]==false){
			dfs_lt(i);
		}
	}
}

int main(){
	ios::sync_with_stdio(false);
	int T;
	cin >> T;
	while(T--){
		cin >> V;
		mem(G,false);
		mem(in,0);
		mem(out,0);
		mem(vis,false);
		n=0;
		char str[1005];
		MAX=-INF;MIN=INF;
		for(int i=0;i<V;i++){
			cin >> str;
			int len=strlen(str);
			int a = str[0]-'a';
			int b = str[len-1]-'a';
		//	cout << *str.begin() << " " << str.at(str.size()-1) << endl;
		//	cout << a << " " << b << endl;
			MIN = min(MIN,min(a,b));
			MAX = max(MAX,max(a,b));
			G[a][b]=true;
			//edge[a].push_back(b);
			in[b]++;
			out[a]++;
		}
		vis[MIN]=true;
	//	cout << MIN << endl;
		dfs_lt(MIN);
		V=0;
		for(int i=0;i<MAXN;i++)
			if(in[i]!=0||out[i]!=0)
				V++;
//		cout << V << endl;
		if(n==V){
			int cnt=0;
			int xx[5];
			for(int i=0;i<MAXN;i++)
				if(in[i]!=out[i])
					xx[cnt++]=i;
			if(cnt==2)
				if((in[xx[0]]-1==out[xx[0]]&&in[xx[1]]+1==out[xx[1]])||(in[xx[0]]==out[xx[0]]-1&&in[xx[1]]==out[xx[1]]+1))
					cout << "Ordering is possible.\n";
				else
					cout << "The door cannot be opened.\n";
			else if(cnt==0)
				cout << "Ordering is possible.\n";
			else
				cout << "The door cannot be opened.\n";
		}else
			cout << "The door cannot be opened.\n";
	}
	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