| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
非常无聊的水题,怎么没什么人AC#include <iostream>
#include <stdio.h>
#include <map>
#include <vector>
using namespace std;
int cnt;
map<int, int> idx;
int fanIdx[233];
int test[233][2];
int res[233][2];
int getID(int yid){
map<int, int>::iterator it = idx.find(yid);
if(it != idx.end()){
return it->second;
}
idx.insert(pair<int, int>(yid, cnt));
fanIdx[cnt] = yid;
cnt++;
return cnt-1;
}
int main() {
int t;
scanf("%d", &t);
for(int ii = 0; ii < t; ii++){
int n;
scanf("%d", &n);
idx.clear();
cnt = 0;
vector<int> posN;
int used[233] = {0};
for(int i = 0; i < n; i++){
int a,b,c;
char f1,f2;
scanf("%d\n%d\n%c\n%d\n%c", &a, &b, &f1, &c, &f2);
int ida = getID(a), idb = getID(b), idc = getID(c);
test[ida][0] = idb, test[ida][1] = idc;
res[ida][0] = (f1=='Y'), res[ida][1] = (f2=='Y');
if(!res[ida][0]){
if(!used[idb]) posN.push_back(idb);
used[idb]++;
}
if(!res[ida][1]){
if(!used[idc]) posN.push_back(idc);
used[idc]++;
}
}
int huai = 0;
int arg = -1;
int sz = posN.size();
for(int i = 0; i < sz; i++){
int idh = posN[i];
bool kywh = 1;
for(int j = 0; j < cnt; j++){
if(j==idh) continue;
if((res[j][0] && test[j][0]==idh) || (!res[j][0] && test[j][0]!=idh)){
kywh=0; break;
}
if((res[j][1] && test[j][1]==idh) || (!res[j][1] && test[j][1]!=idh)){
kywh=0; break;
}
}
if(kywh){
huai++;
arg=idh;
if(huai>=2) break;
}
}
if(huai-1){
printf("impossible\n");
}
else{
printf("%d\n", fanIdx[arg]);
}
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator