hrbust 1774 succession【思维】好题
来源:互联网 发布:java实现接口的方法 编辑:程序博客网 时间:2024/05/21 15:02
successionTime Limit: 1000 MSMemory Limit: 32768 KTotal Submit: 29(9 users)Total Accepted: 12(9 users)Rating: Special Judge: NoDescriptionThe king in Utopia has died without an heir. Now several nobles in the country claim
the throne. The country law states that if the ruler has no heir, the person who is most
related to the founder of the country should rule.
To determine who is most related we measure the amount of blood in the veins of a
claimant that comes from the founder. A person gets half the blood from the father and
the other half from the mother. A child to the founder would have 1/2 royal blood, that
child's child with another parent who is not of royal lineage would have 1/4 royal blood,
and so on. The person with most blood from the founder is the one most related.InputThe rst line contains two integers, N (2 ≤ N ≤ 50) and M (2 ≤M ≤ 50).
The second line contains the name of the founder of Utopia.
Then follows N lines describing a family relation. Each such line contains three names,
separated with a single space. The rst name is a child and the remaining two names are
the parents of the child.
Then follows M lines containing the names of those who claims the throne.
All names in the input will be between 1 and 10 characters long and only contain the
lowercase English letters 'a'-'z'. The founder will not appear among the claimants, nor
be described as a child to someone else.OutputA single line containing the name of the claimant with most blood from the founder. The
input will be constructed so that the answer is unique.
The family relations may not be realistic when considering sex, age etc. However, every
child will have two unique parents and no one will be a descendent from themselves. No
one will be listed as a child twice.Sample Input
the throne. The country law states that if the ruler has no heir, the person who is most
related to the founder of the country should rule.
To determine who is most related we measure the amount of blood in the veins of a
claimant that comes from the founder. A person gets half the blood from the father and
the other half from the mother. A child to the founder would have 1/2 royal blood, that
child's child with another parent who is not of royal lineage would have 1/4 royal blood,
and so on. The person with most blood from the founder is the one most related.InputThe rst line contains two integers, N (2 ≤ N ≤ 50) and M (2 ≤M ≤ 50).
The second line contains the name of the founder of Utopia.
Then follows N lines describing a family relation. Each such line contains three names,
separated with a single space. The rst name is a child and the remaining two names are
the parents of the child.
Then follows M lines containing the names of those who claims the throne.
All names in the input will be between 1 and 10 characters long and only contain the
lowercase English letters 'a'-'z'. The founder will not appear among the claimants, nor
be described as a child to someone else.OutputA single line containing the name of the claimant with most blood from the founder. The
input will be constructed so that the answer is unique.
The family relations may not be realistic when considering sex, age etc. However, every
child will have two unique parents and no one will be a descendent from themselves. No
one will be listed as a child twice.Sample Input
9 2edwardicharlesi edwardi dianaphilip charlesi mistresswilhelm mary philipmatthew wilhelm helenedwardii charlesi lauraalice laura charlesihelen alice bernardhenrii edwardii roxanecharlesii elizabeth henriicharlesiimatthew4 5andrewbetsy andrew floracarol andrew betsydora andrew carolelena andrew doracaroldoraelenafloragloriaSample Output
matthewelenaSourceNCPC 2010Recommend`wind
题目大意:
有n对关系,m个候选人。对应n对关系,有三个名字,第一个表示孩子的名字,后两个表示其父母的名字。
有这样一个规则:
孩子生下来的时候继承其夫亲的1/2血液,继承其母亲1/2的血液。
现在帝王死了,想要找一个继承人。设定帝王的皇室血统为100%
那么帝王的儿子就是50%(其父亲100%/2+其母亲0%/2);
帝王的儿子的儿子就是25%(其父亲50%/2+其母亲0%/2);
当然如果帝王的女儿也是50%,但是如果帝王再和其女儿生一个孩子(好污...),那么其孩子是(100%/2+50%/2);
本题数据及其可怕,乱伦+乱伦+乱伦.............................而且样例2至少证明了这个帝王活了100岁(这泥马都是什么国家.....)
思路:
1、首先如果真的设定帝王的初始值为1,那么一直/2/2/2/2/2..........数据会变得非常非常小,显然会Wa.那么初始化帝王的血纯度需要大一些.
2、当我们对应输入n对关系的时候,我们直接模拟出儿子的纯度=父亲的纯度/2+母亲的纯度/2.虽然在处理一遍之后儿子的纯度绝对不是最终的纯度,但是这时候父亲的纯度和母亲的纯度也都随着改变了,然后我们这个时候假如再处理一次。那么儿子的纯度就更加逼近了真正的纯度。那么我们处理N次之后,其父亲的纯度和母亲的纯度相当于达到了最终的纯度,然后我们第N+1次处理的时候,其儿子也就达到了最终的纯度。
Ac代码:
#include<stdio.h>#include<string.h>using namespace std;struct node{ char a[15]; char b[15]; char c[15]; double output;}e[1000];char a[100][100];int n,m;double find(char a[100]){ for(int i=0;i<=n;i++) { if(strcmp(e[i].a,a)==0)return e[i].output; } return 0;}int main(){ while(~scanf("%d%d",&n,&m)) { scanf("%s",e[0].a); e[0].output=(1<<30); for(int i=1;i<=n;i++) { scanf("%s%s%s",e[i].a,e[i].b,e[i].c); e[i].output=0; } for(int i=1;i<=n+1;i++) { for(int j=1;j<=n;j++) { e[j].output=(find(e[j].b)+(find(e[j].c)))/2; } } double maxn=0; int ans; for(int i=0;i<m;i++) { scanf("%s",a[i]); double tmp=find(a[i]); if(tmp>maxn) { maxn=tmp; ans=i; } } printf("%s\n",a[ans]); }}
0 0
- hrbust 1774 succession【思维】好题
- hrbust 1539 选课【思维+贪心】好题
- Hrbust 1980 Failed【思维】好题!
- hrbust 1662 凸多边形【最短路SPFA+建图+思维】好题
- Hrbust 1517 Summits【Bfs+思维+贪心】好题~
- Hrbust 2222 应援团补完计划【并查集+思维】好题~
- Hrbust 1650 Mac and Sequence【二进制思维】好题~
- Hrbust 2318 Mod【思维+连续二分】好题!
- Hrbust 2063 萌萌哒十五酱的情书~【思维】好题!好题!好题!
- Hrbust 1846 方格涂色【dp+递推思维】好题!好题!好题!
- hrbust 1356 Leyni,罗莉和队列【思维+逆向思维】好题~
- hrbust 1857 koko的能量值公式【思维+二分】好题!好题!
- Hrbust 1849 商品中心【贪心+思维+并查集】好题!好题!
- Succession
- hrbust 1759 Lawnmower【思维题】
- Hrbust 1256 Province Region Competition Team Play【状压dp+分段处理思想+思维】好题!好题!好题!
- Hrbust 1390 Leyni, LOLI and Numbers【思维+树状数组+二分+双向链表模拟】好题!好题!好题!
- Hrbust 1410 Leyni VS XianGe II【思维】好题!趣味题!
- 适配器模式
- 图解 TCP IP 协议:三次握手、四次挥手
- 转:javascript闭包的理解
- 【用Cocos Creator给暗恋的女生写一个游戏(1)】——Cocos Creator初遇见
- codeforces710c
- hrbust 1774 succession【思维】好题
- UVA 1225 Digit Counting
- Android Studio从安装到配置
- 【用Cocos Creator给暗恋的女生写一个游戏(2)】——要做一个什么样的游戏?
- C++ 基础:传参的基本形式-基本类型,对象,引用和指针
- Android自定义View
- CSS(1)
- 字符串流操作
- 整站下载命令