博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
usaco-Section 2.3-Controlling Companies
阅读量:5237 次
发布时间:2019-06-14

本文共 2078 字,大约阅读时间需要 6 分钟。

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)

31 2 802 3 803 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 21 32 3 一道简单的dfs题,把每一个公司都作为总公司,分别得出占有其他公司的股份。 代码如下:
/*ID: yizeng21PROB: concomLANG: C++*/#include
#include
#include
using namespace std;bool vist[1000];int n;int chun[1000][1000];int q[1000][1000];void dfs(int pos,int s){ for(int i=1;i<=100;i++) if(chun[pos][i]!=0){ if(vist[i]==1)continue; q[s][i]+=chun[pos][i]; if(q[s][i]>50){ vist[i]=1; dfs(i,s); } }}struct hh{ int x,y;}w[10000];bool cmp(hh i,hh j){ if(i.x

 

转载于:https://www.cnblogs.com/buffms/p/5155679.html

你可能感兴趣的文章
架构图-模型
查看>>
黑马程序员_Java基础枚举类型
查看>>
UIImage 和 iOS 图片压缩UIImage / UIImageVIew
查看>>
疯狂JAVA16课之对象与内存控制
查看>>
django ORM创建数据库方法
查看>>
php7 新特性整理
查看>>
RabbitMQ、Redis、Memcache、SQLAlchemy
查看>>
知识不是来炫耀的,而是来分享的-----现在的人们却…似乎开始变味了…
查看>>
口胡:[HNOI2011]数学作业
查看>>
数据库锁机制及乐观锁,悲观锁的并发控制
查看>>
03 线程池
查看>>
手机验证码执行流程
查看>>
python 基础 ----- 变量
查看>>
设计模式课程 设计模式精讲 2-2 UML类图讲解
查看>>
Silverlight 的菜单控件。(不是 Toolkit的)
查看>>
初识lua
查看>>
我是插件狂人,jDuang,jValidator,jModal,jGallery
查看>>
jquery的contains方法
查看>>
python3--算法基础:二分查找/折半查找
查看>>
Perl IO:随机读写文件
查看>>