zoukankan      html  css  js  c++  java
  • 2.3.5 Controlling Companies

    Controlling Companies

    Some companies are partial owners of other companies because they have acquired part of their total shares of stock. For example, Ford owns 12% of Mazda. It is said that a company A controls company B if at least one of the following conditions is satisfied:

    • Company A = Company B
    • Company A owns more than 50% of Company B
    • Company A controls K (K >= 1) companies denoted C1, ..., CK with each company Ci owning xi% of company B and x1 + .... + xK > 50%.

    Given a list of triples (i,j,p) which denote company i owning p% of company j, calculate all the pairs (h,s) in which company h controls company s. There are at most 100 companies.

    Write a program to read the list of triples (i,j,p) where i, j and p are positive integers all in the range (1..100) and find all the pairs (h,s) so that company h controls company s.

    PROGRAM NAME: concom

    INPUT FORMAT

    Line 1: n, the number of input triples to follow
    Line 2..n+1: Three integers per line as a triple (i,j,p) described above.

    SAMPLE INPUT (file concom.in)

    3
    1 2 80
    2 3 80
    3 1 20
    

    OUTPUT FORMAT

    List 0 or more companies that control other companies. Each line contains two integers that denote that the company whose number is the first integer controls the company whose number is the second integer. Order the lines in ascending order of the first integer (and ascending order of the second integer to break ties). Do not print that a company controls itself.

    SAMPLE OUTPUT (file concom.out)

    1 2
    1 3
    2 3
    

    {
    ID: makeeca1
    PROG: concom
    LANG: PASCAL
    }
    program concom;
    const maxn=100;
    var n,m:longint;
        map:array[0..maxn,0..maxn]of longint;
        c:array[0..maxn]of longint;
        b:array[0..maxn]of boolean;
    function max(xx,yy:longint):longint;
    begin if xx>yy then exit(xx)else exit(yy);end;
    procedure init;
    var x,y,z,i:longint;
    begin
      readln(m);
      for i:=1 to m do
      begin
        readln(x,y,z);
        n:=max(n,max(x,y));
        map[x,y]:=z;
      end;
    end;
    procedure dfs(x:longint);
    var i:longint;
    begin
      b[x]:=true;
      for i:=1 to n do inc(c[i],map[x,i]);
      for i:=1 to n do
      if (c[i]>50) and not b[i]then dfs(i);
    end;
    procedure work;
    var i,j:longint;
    begin
      for i:=1 to n do
      begin
        fillchar(c,sizeof(c),0);
        fillchar(b,sizeof(b),0);
        dfs(i);
        for j:=1 to n do
         if (i<>j)and(c[j]>50)then writeln(i,' ',j);
      end;
    end;
    begin
      assign(input,'concom.in');reset(input);
      assign(output,'concom.out');rewrite(output);
      init;
      work;
      close(output);
    end.
  • 相关阅读:
    Redis的各种用途以及使用场景【转】
    Cron表达式
    容器绑固定物理核
    【转】Kubernetes和Docker到底有啥关系?
    memtier_benchmark安装
    压测工具
    Linux下traceroute的安装和使用
    计算机科学自学指南
    配置服务器SSH PAM防止暴力破解
    How to Enable or Disable Check for Windows Updates/Check For Updates Greyed Out
  • 原文地址:https://www.cnblogs.com/makeecat/p/3274588.html
Copyright © 2011-2022 走看看