zoukankan      html  css  js  c++  java
  • USACO Controlling Companies chapter 2.3 已跪

    dfs搞了半天硬是没过,看了别人的题解我感觉却更加迷惑了..

     1 /*
     2 
     3 ID: hubiao cave
     4 
     5 PROG: concom
     6 
     7 LANG: C++
     8 
     9 */
    10 
    11 
    12 #include <iostream>  
    13 #include <fstream>  
    14 #include <string>  
    15 #include<memory.h>  
    16 using namespace std;  
    17 int have[101][101];  
    18 int control[101][101];  
    19 int main() {  
    20     ofstream fout ("concom.out");  
    21     ifstream fin ("concom.in");  
    22     int N,i,j,p,num;  
    23     fin>>N;  
    24     memset(control,0,sizeof(control));  
    25     for(int a=0;a<101;a++)  
    26       control[a][a]=1;  
    27     for(int a=0;a<N;a++)  
    28     {  
    29       fin>>i>>j>>p;  
    30       have[i][j]=p;  
    31       if(p>50)  
    32       control[i][j]=true;  
    33     }  
    34     bool judge=true;  
    35     while(judge)  
    36     {  
    37       judge=false;  
    38       for(int a=1;a<101;a++)  
    39         for(int b=1;b<101;b++)  
    40         {  
    41           if(!control[a][b])//在不知道a是否能控制b的情况下  
    42            {  
    43              num=0;  
    44              for(int c=1;c<101;c++)//累加通过a控制多个c从而使a拥有的b的股份达到50以上  
    45                 if(b!=c&&control[a][c])  
    46                   num+=have[c][b];  
    47              if(num>50)  
    48             {  
    49                 control[a][b]=true;  
    50                    judge=true;  
    51             }  
    52            }  
    53         }  
    54     }  
    55    for(int a=1;a<101;a++)  
    56      for(int b=1;b<101;b++)  
    57      {  
    58        if(control[a][b]&&a!=b)  
    59         fout<<a<<" "<<b<<endl;  
    60      }  
    61     return 0;  
    62 }  
  • 相关阅读:
    Minimum Sum
    Prefix and Suffix
    BBuBBBlesort!
    Wanna go back home
    The Chosen One+高精度
    一元三次方程
    文本文件比对
    nginx日志文件切割
    nginx启动脚本
    nginx
  • 原文地址:https://www.cnblogs.com/cavehubiao/p/3314511.html
Copyright © 2011-2022 走看看