zoukankan      html  css  js  c++  java
  • 洛谷P1475 控制公司 Controlling Companies

    洛谷P1475 控制公司 Controlling Companies
    一种类似dijstra的算法

     1 #include <bits/stdc++.h> 
     2 #define LL long long 
     3 #define For(i,j,k) for(int i=j;i<=k;i++) 
     4 #define Dow(i,j,k) for(int i=j;i>=k;i--) 
     5 using namespace std ; 
     6 
     7 const int N = 111 ; 
     8 int m,n,id ; 
     9 int mp[N][N],dist[N] ; 
    10 bool visit[N] ; 
    11 
    12 inline int read() 
    13 {
    14     int x = 0 , f = 1 ; 
    15     char ch = getchar() ; 
    16     while(ch<'0'||ch>'9') { if(ch=='-') f = -1 ; ch = getchar() ; } 
    17     while(ch>='0'&&ch<='9') { x = x * 10+ch-48 ; ch = getchar() ; } 
    18     return x * f ;  
    19 }
    20 
    21 inline void write(int x) 
    22 {
    23     if( x < 0 ) putchar('-') ; 
    24     if( x > 9 ) write(x/10) ; 
    25     putchar(x%10+48) ; 
    26 } 
    27 
    28 inline void writeln(int x) 
    29 {
    30     write(x) ;
    31     putchar('
    ') ; 
    32 }
    33 
    34 int main() 
    35 {
    36     m = read() ; 
    37     For(i,1,m) {
    38         int x,y ; 
    39         x = read() ; y = read() ; n = max(n,x) ; n = max(n,y) ;  
    40         mp[x][y] = read() ; 
    41     }
    42     
    43     For(node,1,n) {
    44         For(i,1,n) dist[i] = mp[node][i] ; 
    45         For(i,1,n) visit[i] = 0 ; 
    46         visit[node] = 1 ; 
    47         while(1) {
    48             For(i,1,n) {
    49                 id = i ; 
    50                 if(!visit[id] && dist[id]>50) break ;  // 没被控制且能被控制  
    51             }
    52             if(!(!visit[id] && dist[id]>50)) {
    53                 For(i,1,n) 
    54                     if(i!=node&&visit[i]) printf("%d %d
    ",node,i) ; 
    55                 break ; 
    56             }
    57             visit[id] = 1 ; 
    58             For(j,1,n) dist[j]+=mp[id][j] ;     
    59         }
    60     }
    61     return 0 ; 
    62 }

      

  • 相关阅读:
    JS定时执行,循环执行
    Ecshop(二次开发)
    百度歌曲接口
    给大家讲讲在哪些地方发外链最好
    360浏览器默认以兼容模式或急速模式方式打开页面
    子iframe 怎么调用 父级的JS函数
    ASP 发送邮件
    PHP发送邮件
    php表单数据验证类
    js获取url传递参数
  • 原文地址:https://www.cnblogs.com/third2333/p/7660555.html
Copyright © 2011-2022 走看看