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小白有写的不好不对的地方请指出~ 举报

相关文章推荐

hrbust 1774 succession【思维】好题

succession Time Limit: 1000 MS Memory Limit: 32768 K Total Submit: 29(9 u...

Hrbust 1980 Failed【思维】好题!

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

精选:深入理解 Docker 内部原理及网络配置

网络绝对是任何系统的核心,对于容器而言也是如此。Docker 作为目前最火的轻量级容器技术,有很多令人称道的功能,如 Docker 的镜像管理。然而,Docker的网络一直以来都比较薄弱,所以我们有必要深入了解Docker的网络知识,以满足更高的网络需求。

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

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

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

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

思维题(好题)

思维题(好题)

hrbust 1356 Leyni,罗莉和队列【思维+逆向思维】好题~

Leyni,罗莉和队列 Time Limit: 1000 MS Memory Limit: 65536 K Total Submit: 124(2...

Hrbust 1846 方格涂色【dp+递推思维】好题!好题!好题!

方格涂色 Time Limit: 1000 MS Memory Limit: 32768 K Total Submit: 31(14 users)...

Hrbust 2063 萌萌哒十五酱的情书~【思维】好题!好题!好题!

萌萌哒十五酱的情书~ Time Limit: 150 MS Memory Limit: 1515 K Total Submit: 76(25 us...

2道不错的cf题诶

题目链接:http://codeforces.com/problemset/problem/567/C C. Geometric Progression t...

Hrbust 1410 Leyni VS XianGe II【思维】好题!趣味题!

Leyni VS XianGe II Time Limit: 1000 MS Memory Limit: 65536 K Total Submit...
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

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