hdu 2094 产生冠军 是脑筋急转弯不是拓扑

关于思路:

在拓扑题集里发现了这只,怎么想怎么奇怪,产生冠军当且仅当整个拓扑序打出来是联通的,并且到尽头不能有两个以上出度为0的点,这咋判断?

根据冠军的定义,没输过,开两个set,一个存赢家,一个存输家,若赢家没在输家名单里出现过,则cnt++;

产生冠军当且仅当cnt=1;

 

关于实现:

实现过程中学到了set的几个用法

遍历时:

set<string>::iterator it=x.begin();

for(;it!=x.end();it++)

*it,表示it所取的string 或者 数字

x.find()返回的是地址,如果存在就返回地址啦,不存在就返回it.end()

--

复制代码
#include <iostream>
#include <math.h>
#include <string.h>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <algorithm>
#include <cstdio>
#include <set>
using namespace std;
set<string>win,lose;
int main()
{

    
    int n;
    while(cin>>n)
    {   
        win.clear();
        lose.clear();
        
        if(n==0)  break;
        
        
        
        for(int i=1;i<=n;i++)
        {
            string winer,loser;
            cin>>winer>>loser;
            win.insert(winer);
            lose.insert(loser);
        //    cout<<winer<<endl;
        }
        
       set<string>::iterator  to=win.begin();
       
       int ok=0;
       
       for(;to!=win.end();to++)
       {
           
           //cout<<*to<<endl;
            if(lose.find(*to)==lose.end())
            {
              ok++;
         }
       }
       
       if(ok==1)
       {
           cout<<"Yes"<<endl;
       }
       else cout<<"No"<<endl;
    }
}
复制代码

 

posted @   liyishui  阅读(22)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
点击右上角即可分享
微信分享提示