栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

poj 1359 Spacecraft Malfunction

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

poj 1359 Spacecraft Malfunction

#include<cstdio>#include<cstring>#include<string>#include<iostream>#include<algorithm>#include<cmath>#include<queue>#include<map>#include<vector>#define LG long longusing namespace std;int n,m,N[105],Y[105],fa[105],res[105];map<int ,int>mp,re;int main(){int T,x,y,z,pos=0,len;char ch[10],sh[10];scanf("%d",&T);while(T--){mp.clear();re.clear(),pos=1;memset(N,0,sizeof(N));memset(Y,0,sizeof(Y));memset(fa,0,sizeof(fa));scanf("%d",&n);int flag=0,ans=0;for(int i=0;i<n;i++){scanf("%d",&x);if(mp[x]==0)mp[x]=pos,re[pos]=x,x=pos++;else x=mp[x];scanf("%d",&y);scanf("%s",ch);if(mp[y]==0)mp[y]=pos,re[pos]=y,y=pos++;else y=mp[y];scanf("%d",&z);scanf("%s",sh);if(mp[z]==0)mp[z]=pos,re[pos]=z,z=pos++;else z=mp[z];if(ch[0]=='N'&&sh[0]=='N')flag=1,ans=x;else if(ch[0]=='N')N[y]++,fa[y]=x,Y[z]++;else if(sh[0]=='N')N[z]++,fa[z]=x,Y[y]++;else Y[z]++,Y[y]++;}if(flag==1)printf("%dn",re[ans]);else{len=0;for(int i=1;i<pos;i++){if(N[i]>=2){ans=i;break;}else if(N[i]==1)res[len++]=i;}if(len==1&&Y[fa[res[0]]]!=0)ans=res[0];else if(len==2){if(Y[fa[res[0]]]!=0)ans=res[0];else if(Y[fa[res[1]]]!=0)ans=res[1];}if(ans==0)puts("impossible");else printf("%dn",re[ans]);}}return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/373294.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号