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;
    }
    

     

      

     

     

  • 相关阅读:
    [TJOI2013]单词
    [AHOI2005]病毒检测
    [SCOI2016]围棋
    [SDOI2008]Sandy的卡片
    [POI2005]Sza-Template
    [Usaco2015 Feb]Censoring
    浅谈算法——KMP
    yii2邮件配置教程,报Expected response code 250 but got code "553"原因
    yii2设置发送邮件的一些配置
    js 的正则表达式 部分展示test()方法的验证功能
  • 原文地址:https://www.cnblogs.com/Anidlebrain/p/10029187.html
Copyright © 2011-2022 走看看