• uva 11748(求可达矩阵)


    题意:有若干个然参加选举,然后会每次挑选来两个人出来选,赢得那个能继续参选,输的就被淘汰了。问你若你是每次挑人的那个人,你很自私能不能让你想赢的那个人赢。

    思路:对于(a,b)若b能战胜a我们建有向边a->b,最终判断若是所有的节点都能到达你想要的那个人就是可以战胜的。写法类似于floyd。

    代码如下:

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstdlib>
     4 #include <cmath>
     5 #include <cstring>
     6 #include <algorithm>
     7 #include <queue>
     8 #include <stack>
     9 #include <vector>
    10 #include <set>
    11 #include <map>
    12 #define MP(a, b) make_pair(a, b)
    13 #define PB(a) push_back(a)
    14 
    15 using namespace std;
    16 
    17 typedef long long ll;
    18 typedef pair<int ,int> pii;
    19 typedef pair<unsigned int, unsigned int> puu;
    20 typedef pair<int ,double> pid;
    21 typedef pair<ll, int> pli;
    22 typedef pair<int, ll> pil;
    23 
    24 const int INF = 0x3f3f3f3f;
    25 const double eps = 1e-6;
    26 const int LEN = 102;
    27 int Map[LEN][LEN], cad[LEN][LEN], win, n, m;
    28 
    29 int main()
    30 {
    31 //    freopen("in.txt", "r", stdin);
    32 
    33     int pos;
    34     while(scanf("%d%d%d", &n, &m, &win)!=EOF){
    35         if(!n && !m && !win) break;
    36         for(int i=0; i<m; i++){
    37             for(int j=0; j<n; j++){
    38                 scanf("%d", &pos);
    39                 cad[i][pos-1] = j;
    40             }
    41         }
    42         memset(Map, 0, sizeof Map);
    43         for(int i=0; i<n; i++){
    44             for(int j=0; j<n; j++){
    45                 if(i==j){Map[i][j] = 1;continue;}
    46                 int cnt = 0;
    47                 for(int k=0; k<m; k++){
    48                     if(cad[k][i] > cad[k][j]) cnt++;
    49                 }
    50                 if(cnt>m/2) Map[i][j] = 1;
    51             }
    52         }
    53         for(int k=0; k<n; k++)
    54         for(int i=0; i<n; i++){
    55             for(int j=0; j<n; j++){
    56                 if(Map[i][k] && Map[k][j])Map[i][j] = 1;
    57             }
    58         }
    59         int ans = 1;
    60         for(int i=0; i<n; i++)if(Map[i][win-1]==0)ans = 0;
    61         if(ans)printf("yes
    ");
    62         else printf("no
    ");
    63     }
    64     return 0;
    65 }
    View Code
    奔跑吧!少年!趁着你还年轻
  • 相关阅读:
    npm私服包管理-发布
    搭建npm私服
    vue.js框架搭建
    基于cropper实现图片上传,剪切,下载
    base64转图片
    获取file的路径
    如何制定好测试策略(一)
    让测试团队慢慢死去!-有同感,转载
    2016-2016自动化测试的趋势
    2016-安全性测试
  • 原文地址:https://www.cnblogs.com/shu-xiaohao/p/3533967.html
Copyright © 2020-2023  润新知