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; }
相关推荐
在本资源"Controlling-Companies.zip"中,我们聚焦于一个特定的编程问题,即"controlling company",这是USACO(美国计算机奥林匹克)竞赛中的一个问题。USACO是一项面向高中生的在线编程比赛,旨在提升参赛者的算法...
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》有详细的介绍。
### 控制具有回差的机械系统 #### 回差的概念及其影响 回差(backlash)是机械系统中一个重要的非线性因素,它限制了速度和位置控制的性能,在工业、机器人技术、汽车制造、自动化以及其他应用领域都有显著的影响...
标题:“Controlling-Profitability Analysis with SAP”表明这本书是一本关于如何使用SAP软件系统来进行成本控制和盈利能力分析的专业书籍。成本控制和盈利能力分析是企业财务管理中的重要环节,对于企业来说,通过...
在推荐系统中,可以将用户-项目偏好矩阵看作是缺失的,而矩阵补全的目的是基于已知的偏好信息来预测未知的偏好值。矩阵补全问题可以通过凸优化方法解决,其中迹范数(trace norm)作为矩阵秩的凸替代量,用于正则化...
【7011财务会计与控制】:这个主题主要涵盖了企业内部的财务管理和生产计划方面的内容,特别是关于Master Production Scheduling (MPS)和Material Requirements Planning (MRP)的运用。 MPS,即主生产排程,是企业...
Workflow based invoice controlling for SAP R/3
越过山顶 这打算使用 NodeJS 实现另一个 Socksv5 代理。 规划功能如: ... | Traffic Monitoring and Controlling | | +------------------------------------+ \|/ +----------+ +--------+-----------+
### 工作流为基础的过程控制 (Workflow-based Process Controlling) #### 概述 《工作流为基础的过程控制》一书由Michael zur Muehlen撰写,该书深入探讨了如何利用工作流技术来提升企业的业务流程管理水平。随着...
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 ...
controlling of the agv in the final year project
录像49_product cost controlling,60分钟
《控制基础》(Foundations of Controlling) 是一份关于企业管理的重要文档,主要探讨了控制理论在组织中的应用和重要性。以下是对文档内容的详细解释: 1. **控制的定义**:控制是管理过程的一个关键组成部分,它...
Walking is the most common terrestrial form of locomotion in animals. Its great versatility and flexibility has led to many attempts at building walking machines with similar capabilities....
### Expect - Scripts for Controlling Interactive Processes #### 一、引言与背景介绍 《Expect - Scripts for Controlling Interactive Processes》是一篇由Don Libes撰写的关于如何使用Expect脚本控制交互式...
混沌动力系统的控制是当代非线性科学中的一个重要分支,它主要研究如何利用微小的调整,来改变一个系统的行为,尤其是那些表现得像随机行为但实际上由确定性规则支配的动力系统。混沌现象在自然科学和工程系统中广泛...
Configuring SAP R3 FICO The Essential Resource for Configuring the Financial and Controlling Modules
Controlling_EMI_Emmissions_From PCB_Edges_WhitePaper_iss01