zoukankan      html  css  js  c++  java
  • Succession

    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 followsNlines 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 followsMlines 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

    HINT

    分析:纯模拟n遍即可,每次模拟,更新一次数据。

     

    #include<iostream>
    #include<stdio.h>
    #include<cstring>
    using namespace std;
    struct in
    {
        char a[11];
        char b[11];
    }s[55];
    struct name
    {
        char na[11];
        double ro;
    };
    name num[55],temp[55];
    double find(char *p,int n)
    {
        //printf("-->%s  ",p);
        for(int i=0;i<=n;i++)
            if(strcmp(num[i].na,p)==0)
            {
                //printf("%s %lf
    ",num[i].na,num[i].ro);
                return num[i].ro;
            }
        return 0;
    }
    int main()
    {
        int n,m;
        while(scanf("%d%d",&n,&m)!=EOF)
        {
            for(int i=0;i<=n;i++)
                num[i].ro=0;
            scanf("%s",&num[0].na);
            num[0].ro=1<<30;//赋值为1后面小数会很小,超出范围
            for(int i=1;i<=n;i++)
                scanf("%s%s%s",&num[i].na,&s[i].a,&s[i].b);
            for(int i=1;i<=n;i++)
            {
                for(int j=1;j<=n;j++)
                {
                    //printf("s[j].a=%s s[j].b=%s
    ",s[j].a,s[j].b);
                    num[j].ro=(find(s[j].a,n)+find(s[j].b,n))/2;
                    //printf("num[%d]=%.6lf
    ",j,num[j].ro);
                }
            }
            double max=0;
            int ans;
            for(int i=0;i<m;i++)
            {
                scanf("%s",&temp[i].na);
                double flag=find(temp[i].na,n);
                //printf("flag=%lf
    ",flag);
                if(max<flag)
                {
                    max=flag;
                    ans=i;
                }
            }
            printf("%s
    ",temp[ans].na);
        }
        return 0;
    }
    


  • 相关阅读:
    Beef McNuggets USACO 4.1(数论公约数问题+背包阵亡)
    Raucous Rockers USACO 3.4 (dp背包?)
    Electric Fence USACO 3.4
    大雾....
    American Heritage USACO 3.4 (二叉树前序中序求后序)
    Closed Fences USACO 3.4(阵亡)
    cvte酱油一把
    算法导论之计算几何学小记 33.1
    A Game USACO 3.3 (DP阵亡)
    [bx]和loop指令
  • 原文地址:https://www.cnblogs.com/suncoolcat/p/3281526.html
Copyright © 2011-2022 走看看