USACO-Controlling Companies
2016-06-12 13:50
281 查看
Some companies are partial owners of other companies because they have acquired part of their total shares of stock. For example, Ford at one point owned 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
题意:给出你i公司在j公司占有p的股份,输出从属关系。
dfs。
代码:
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
题意:给出你i公司在j公司占有p的股份,输出从属关系。
dfs。
代码:
/* ID:iam666 PROG:concom LANG:C++ */ #include <cstdio> #include <algorithm> #include <cstring> #include <iostream> bool flag[105],own[105]; int a[105][105]={},cnt[105],maxx; using namespace std; void dfs(int x) { if(flag[x]) return; flag[x]=true; for(int i=1;i<=maxx;i++) { cnt[i]+=a[x][i]; if(cnt[i]>50) { own[i]=true; dfs(i); } } } int main (void) { freopen("concom.in","r",stdin); freopen("concom.out","w",stdout); int n,u,v,w; cin>>n; while(n--) { scanf("%d %d %d",&u,&v,&w); a[u][v]+=w; if(u>maxx)maxx=u; if(v>maxx)maxx=v; } for(int i=1;i<=maxx;i++) { fill_n(cnt+1,maxx,0); fill_n(flag+1,maxx,false); fill_n(own+1,maxx,false); dfs(i); for(int j=1;j<=maxx;j++) if(own[j]&&i!=j) printf("%d %d\n",i,j); } return 0; }
相关文章推荐
- libuv学习笔记(6)
- mq完成代码是 2,原因为 2009
- C语言位运算符:与、或、异或、取反、左移与右移介绍
- 游戏中图片格式的选取
- SQLSERVER排查CPU占用高的情况
- gdb使用累积汇总
- js滑动切换效果
- cron表达式
- Mongodb 的基本操作
- IOS 控件常识
- spring mvc常用的注解:
- Java 六种异常处理的陋习
- 基于css3新属性transform及原生js实现鼠标拖动3d立方体旋转
- CPU概念和调度算法
- Centos更换yum源,使用国内163源
- mysql优化
- jQuery.ajax的简单应用实例
- [BZOJ4196][NOI2015]软件包管理器
- BLE Hacking:使用Ubertooth one扫描嗅探低功耗蓝牙
- 分布式服务框架 Zookeeper -- 管理分布式环境中的数据