zoukankan      html  css  js  c++  java
  • TZOJ--5449: King of the Waves(拓扑排序)

    5449: King of the Waves 

    时间限制(普通/Java):5000MS/15000MS     内存限制:65536KByte

    描述

    You are organising a king of the hill tournament, the Buenos Aires Paddleboarding Competition (BAPC), with n participants. In a king of the hill tournament, one person starts as a “king” and is then challenged by another person, the winning person becomes the new king. This is repeated until all participants have challenged exactly once (except for the starting person). In a paddleboarding match, there are no draws. The person which ends up as king, wins the tournament. Since you are the organiser, you get to choose the starting person and the order in which they challenge the king. 

    Someone is offering you a substantial amount of money in case one of the participants, Henk, ends up winning the tournament. You happen to know, for any two participants x and y, which of the two would win if they were to match during the tournament. Consequently, you choose to do the unethical: you will try to rig the game. Can you find a schedule that makes Henk win the tournament?

    输入

    The first line contains an integer 1 ≤ n ≤ 1000, the number of participants. The participants are numbered 0, . . . , n − 1, where Henk is 0. 

    • Then n lines follow, where each line has exactly n characters (not counting the newline character). These lines represent the matrix with the information of who beats who, as follows. On line i the jth character is (note that 0 ≤ i, j < n): 

    – ’1’ if person i will win against person j. 

    – ’0’ if person i will lose against person j. 

    – ’X’ if i = j.

    输出

    If there exists a way to rig the game such that Henk wins, print "Yes", else "No".

    样例输入

    3
    X10
    0X1
    10X

    样例输出

     Yes

    题目来源

    BAPC 2017

     

    题目链接:http://tzcoder.cn/acmhome/problemdetail.do?&method=showdetail&id=5449

     

    题目大意:有N个人,给你一幅N*N的图,第i行第J列表示i和j的比赛结果,1表示赢,2表示输,问你能否寻找一种方案使得0号选手获胜。那么即寻找一种方案使得拓扑排序后0大于所有即可。(这题时间好长,应该其他方法瞎搞也可以过)

     

     

    #include <bits/stdc++.h>
    using namespace std;  
    #define LL long long  
    void closeio(){
    	cin.tie(0);
       	ios::sync_with_stdio(0);
    }
    vector<int>g[1010];
    char ma[1010][1010];
    int vis[1001],n,ans;
    int flag = 0;
    void dfs(int v){
    	vis[v] = 1;
    	if(ans == n-1){
    		flag = 1;
    		return;
    	}
    	for(int i = 0 ; i < g[v].size() ; i ++){
    		if(!vis[g[v][i]]){
    			ans++;
    			dfs(g[v][i]);
    		}
    	}
    }
    int main()
    {
    	scanf("%d",&n);
    	flag = ans =0;
    	for(int i = 0 ; i < n ; i++) g[i].clear();
    	for(int i = 0 ; i < n ; i++){
    		scanf("%s",ma[i]);
    		for(int j = i + 1 ; j < n ; j++){
    			if(ma[i][j] == '1'){
    				g[i].push_back(j);
    			}
    			else{
    				g[j].push_back(i);
    			}
    		}
    	}
    	if(n <= 1){
    		puts("Yes");return 0;
    	}
    	memset(vis,0,sizeof(vis));
    	dfs(0);
    	if(flag)puts("Yes");
    	else puts("No");
    	return 0;
    }
    

     

      

     

     

  • 相关阅读:
    VS Code 快捷键(中英文对照版)
    Linux下SVN提交时强制写日志
    如何搞定SVN目录的cleanup问题和lock问题
    Unity3D中利用Action实现自己的消息管理(订阅/发布)类
    Unity3D热更新之LuaFramework篇[03]--prefab加载和Button事件
    Unity3D热更新之LuaFramework篇[02]--用Lua创建自己的面板
    Unity3D热更新之LuaFramework篇[01]--从零开始
    Unity UI性能优化技巧
    Unity中雾效的开启
    解决Unity中模型部件的MeshCollider不随动画一起运动的问题
  • 原文地址:https://www.cnblogs.com/Anidlebrain/p/10029187.html
Copyright © 2011-2022 走看看