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
题意:
给出 N,代表给出 N 条信息。每条信息包含i,j,p(1 <= i,j,p <= 100),代表 i 控制了 j 公司百分之 p 的股份。输出公司之间的控制关系。
A 公司控制 B 公司的条件为(满足其中之一):
1.A = B(即 A 控制了 B 百分之百的股份);
2.A 控制了 B 超过百分之 50 的股份;
3.A 控制了一系列的公司 ,这一系列的公司控制 B 公司股份之和超过 50,则 A 控制 B 公司。
思路:
DFS,邻接矩阵保存关系,判断过程中记得判重即可。
AC:
/* TASK:concom LANG:C++ ID:sum-g1 */ #include<stdio.h> #include<string.h> int cont[105][105],val[105][105]; int vis[105],sum[105],now; void dfs(int num) { if(vis[num]) return; //判重 vis[num] = 1; for(int i = 1;i <= 100;i++) { sum[i] += val[num][i]; if(sum[i] > 50) { cont[now][i] = 1; dfs(i); } } } int main() { freopen("concom.in","r",stdin); freopen("concom.out","w",stdout); int n; scanf("%d",&n); memset(val,0,sizeof(val)); memset(cont,0,sizeof(cont)); while(n--) { int a,b,num; scanf("%d%d%d",&a,&b,&num); val[a][b] = num; } //每次都是以一个节点向下搜索 //vis是判重,sum是累加 for(now = 1;now <= 100;now++) { memset(vis,0,sizeof(vis)); memset(sum,0,sizeof(sum)); dfs(now); } for(int i = 1;i <= 100;i++) { for(int j = 1;j <= 100;j++) if(i != j && cont[i][j]) printf("%d %d\n",i,j); } return 0; }
相关推荐
In this introduction, I explain the meaning of the acronym SAP, the origin of SAP, and the concept of SAP implementation. We will go further to look at Enterprise Resource Plan
路由器配备很大的入站缓冲区,以便不惜一切代价避免丢包(分组)。可是这种做法破坏了TCP的拥塞预防机制,导致网络中产生较长且可变的延迟时间。...ACM的这篇论文《Controlling Queue Delay》有详细的介绍。
主要介绍机械系统控制建模辨识等方面的内容,对于一些初学者来说非常有用。
the solution to the usaco problem controlling company
Robot Programming: A Guide to Controlling Autonomous Robots: Covers both ARM9 and ARM7 micro-controllers, including the newest LEGO Mindstorms EV3 and Wowee RS Media Robots.
Controlling-Profitability Analysis with SAP Controlling-Profitability Analysis with SAP
Foundations of Controlling.ppt
Workflow-based Process Controlling,作者:Michael zur Muehlen
Controlling external windows
Controlling Chaotic Dynamical Systems via OGY Control Method Based on Targeting
详细介绍了MPS.MRP
Workflow based invoice controlling for SAP R/3
Controlling Media Servers SIP
Controlling Radiated EMI Through PCB Stack
Controlling privacy in recommender systems,推荐系统中的隐私问题。
Adaptive green traffic signal controlling using vehicular communication
越过山顶 这打算使用 NodeJS 实现另一个 Socksv5 代理。 规划功能如: ... | Traffic Monitoring and Controlling | | +------------------------------------+ \|/ +----------+ +--------+-----------+
Backstepping approach for controlling a quadrotor using .pdf
Mechanism of Controlling Cross-linking Polymerization Progress,栗方星,Sun Ruimin, A mechanism of controlling cross-linking polymerization process is reported in this paper. Chain propagation of ...