• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            USACO Section 2.3 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
            Analysis
            This problem is a graph travelling problem. The DFS is needed. Here I provide the official analysis.

            The method used here to solve the problem is as follows. We keep track of which companies control which other companies, and every time we hear that so and so owns this much percent of so and so, we update our information.
            The array "owns" keeps track of how much of company j is owned by company i, whether directly or via controlled companies. The array "controls" keeps track of which companies are controlled by which other companies.

            code

            /*
            ID:braytay1
            PROG:concom
            LANG:C++
            */

            #include 
            <iostream>
            #include 
            <fstream>
            #include 
            <string>
            using namespace std;
            ofstream fout(
            "concom.out");
            ifstream fin(
            "concom.in");
            int stock[101][101],cx[101],n;
            bool con[101][101],vis[101];

            void DFS(int com){
                
            if (vis[com]) return;
                vis[com]
            =true;
                
            for (int i=1;i<=100;i++){
                    cx[i]
            +=stock[com][i];
                    
            if (cx[i]>50&&i!=com){            
                        DFS(i);
                    }

                }

            }

            int main(){
                fin
            >>n;
                memset(stock,
            0,sizeof(stock));
                
            for (int k=1;k<=n;k++){
                    
            int i,j,p;
                    fin
            >>i>>j>>p;
                    stock[i][j]
            =p;
                }

                
            for (int i=1;i<=100;i++) stock[i][i]=100;
                memset(cx,
            0,sizeof(cx));
                memset(vis,
            false,sizeof(vis));
                memset(con,
            false,sizeof(con));
                
            for(int i=1;i<=100;i++){
                    DFS(i);
                    
            for(int j=1;j<=100;j++){
                        
            if (cx[j]>50) con[i][j]=true;
                    }

                    memset(cx,
            0,sizeof(cx));
                    memset(vis,
            false,sizeof(vis));
                }

                
            for(int i=1;i<=100;i++){
                    
            for(int j=1;j<=100;j++){
                        
            if (con[i][j]&&i!=j) fout<<i<<" "<<j<<endl;
                    }

                }

                
            return 0;
            }

            posted on 2008-08-12 17:16 幻浪天空領(lǐng)主 閱讀(460) 評論(0)  編輯 收藏 引用 所屬分類: USACO

            <2025年8月>
            272829303112
            3456789
            10111213141516
            17181920212223
            24252627282930
            31123456

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            留言簿(1)

            隨筆檔案(2)

            文章分類(23)

            文章檔案(22)

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久精品国产亚洲AV忘忧草18| 2021国产精品午夜久久| 国产午夜精品理论片久久影视| 青青青青久久精品国产| 亚洲国产成人久久笫一页| 欧美黑人激情性久久| 久久国产高清一区二区三区| 色欲久久久天天天综合网 | 久久精品一区二区| 人妻无码精品久久亚瑟影视| www.久久热.com| 久久久久亚洲av综合波多野结衣| 亚洲一区中文字幕久久| 久久精品国产99国产精品导航| 国产精品久久久久久久久| 久久国语露脸国产精品电影| 日本亚洲色大成网站WWW久久 | 久久精品亚洲日本波多野结衣 | 精品伊人久久大线蕉色首页| 久久99精品国产麻豆蜜芽| 一本色道久久88精品综合| 无码任你躁久久久久久久| 91超碰碰碰碰久久久久久综合| 久久综合国产乱子伦精品免费| 亚洲精品久久久www| 久久高清一级毛片| 久久亚洲国产精品123区| 91亚洲国产成人久久精品网址| 久久久婷婷五月亚洲97号色| 久久综合亚洲鲁鲁五月天| 香港aa三级久久三级老师2021国产三级精品三级在 | 久久久精品2019免费观看| 婷婷久久五月天| 久久亚洲精品国产精品婷婷| 中文字幕精品无码久久久久久3D日动漫 | 国内精品久久久久久久亚洲 | 久久久久这里只有精品 | 久久嫩草影院免费看夜色| 国产亚洲色婷婷久久99精品91| 亚洲综合精品香蕉久久网97| 91久久精品视频|