hrbust 1774 succession【思维】好题

原创 2016年08月28日 22:54:49

succession
Time Limit: 1000 MS Memory Limit: 32768 K
Total Submit: 29(9 users) Total Accepted: 12(9 users) Rating:  Special Judge: No
Description
The 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.
Input
The 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.
Output
A 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 2
edwardi
charlesi edwardi diana
philip charlesi mistress
wilhelm mary philip
matthew wilhelm helen
edwardii charlesi laura
alice laura charlesi
helen alice bernard
henrii edwardii roxane
charlesii elizabeth henrii
charlesii
matthew
4 5
andrew
betsy andrew flora
carol andrew betsy
dora andrew carol
elena andrew dora
carol
dora
elena
flora
gloria
Sample Output
matthew
elena
Source
NCPC 2010
Recommend
`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小白有写的不好不对的地方请指出~

相关文章推荐

ZCMU—1774

1774: 最短的串 Time Limit: 1 Sec  Memory Limit: 128 MB [Submit][Status][Web Board] Description 给出一个字符串...
  • jnxxhzz
  • jnxxhzz
  • 2016年12月07日 20:42
  • 140

Problem A Succession

Problem A SuccessionNCPC 2010 Problem A: Succession 1 Problem A Succession The king in Utopia has di...

hrbust 1662 凸多边形【最短路SPFA+建图+思维】好题

凸多边形 Time Limit: 2000 MS Memory Limit: 32768 K Total Submit: 61(17 users)...

Hrbust 1517 Summits【Bfs+思维+贪心】好题~

Summits Time Limit: 3000 MS Memory Limit: 65535 K Total Submit: 8(5 users...

hrbust 1828 剪纸条【类Floyd的dp+思维】好题!

剪纸条 Time Limit: 1000 MS Memory Limit: 32768 K Total Submit: 12(6 users) Total Accepted: ...

hrbust 1539 选课【思维+贪心】好题

选课 Time Limit: 1000 MS Memory Limit: 65535 K Total Submit: 63(21 users) ...

Hrbust 2318 Mod【思维+连续二分】好题!

Mod Time Limit: 1000 MS Memory Limit: 100000 K Total Submit: 367(103 user...

Hrbust 1980 Failed【思维】好题!

Failed Time Limit: 1000 MS Memory Limit: 32768 K Total Submit: 16(11 user...

Hrbust 2048 Thrall’s Dream【强连通+拓扑排序+思维】好题!

Thrall’s Dream Time Limit: 1000 MS Memory Limit: 32768 K Total Submit: 70...

Hrbust 1688 数论中的异或【思维+数论异或】好题~

数论中的异或 Time Limit: 1000 MS Memory Limit: 32768 K Total Submit: 42(27 users) Total Accept...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:hrbust 1774 succession【思维】好题
举报原因:
原因补充:

(最多只允许输入30个字)