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.
  • 相关阅读:
    ajax 通过回调函数获取异步数据
    (淘宝无限适配)手机端rem布局详解(转载非原创)
    rem在响应式布局中的应用
    移动端页面适配解决方案
    flex 布局,flex-grow 宽度未等比放大问题解决办法
    flex 布局
    bootstrap Modal 模态框垂直居中
    require.js实现单页web应用(SPA)
    解决 html5 input type='number' 类型可以输入e
    jquery 的ready() 与window.onload()的区别
  • 原文地址:https://www.cnblogs.com/makeecat/p/3274588.html
Copyright © 2011-2022 走看看