hdu 2094 谁是冠军(STL,拓扑排序)
2017-09-29 21:46
197 查看
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2094
这题简直太水了,开始觉得拓扑,后来写着写着发现大部分代码没用,就删成这样了。只要入度唯一即可输出yes
stl是真好用,特别是auto定义迭代器遍历map,set等。
但是这题确实写错了,光写flag没判断入度均不为0时,应该是No,而之前写的忘判断flag==0时size是不是0;
这题简直太水了,开始觉得拓扑,后来写着写着发现大部分代码没用,就删成这样了。只要入度唯一即可输出yes
stl是真好用,特别是auto定义迭代器遍历map,set等。
但是这题确实写错了,光写flag没判断入度均不为0时,应该是No,而之前写的忘判断flag==0时size是不是0;
#include<cstdio> #include<iostream> #include<queue> #include<string> #include<cstring> #include<map> using namespace std; const int maxn=2005; int n; string x[maxn],y[maxn]; map<string,int> in; void toposort(){ queue<string> s; int flag=0; for(auto it:in){ //cout<<it.second<<endl; if(it.second==0) //收入入度为0的点 s.push(it.first); if(s.size()>1) flag=1; } if(flag==1||s.size()==0) printf("No\n"); else printf("Yes\n"); } int main(){ while(scanf("%d",&n)&&n){ in.clear(); for(int i=0;i<n;i++){ cin>>x[i]>>y[i]; in[y[i]]=0; in[x[i]]=0; } for(int i=0;i<n;i++){ in[y[i]]++; } toposort(); for(int i=0;i<n;i++){ x[i].clear(); y[i].clear(); } } return 0; }
相关文章推荐
- HDU 2094 产生冠军(拓扑排序)
- HDU 2094 产生冠军 (STL:set用法)
- HDU 2094 产生冠军(STL 集合set)
- hdu 2094 产生冠军(水题,拓扑排序)
- HDU-2094产生冠军-拓扑排序
- hdu 2094 产生冠军 (拓扑排序)
- 【HDU】2094 - 产生冠军(拓扑 & STL)
- 产生冠军 HDU 2094 【拓扑排序】
- hdu 2094 产生冠军(拓扑排序)
- HDU 2094 产生冠军(STL & 拓扑)
- hdu 2094 产生冠军 拓扑排序
- HDU 2094产生冠军(拓扑排序)
- hdu 2094 产生冠军 实实在在的水题啊!就是连拓扑排序都不要。直接统计入度就可以了
- hdu 2094 产生冠军(拓扑排序)
- hdu 2094 产生冠军(拓扑排序 easy)
- hdu 2094 产生冠军(STL,set)
- HDU 2094(产生冠军)
- hdu 2094 产生冠军
- hdu 2094 产生冠军
- hdu 2094 产生冠军(水题)