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\n",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\n",s[j].a,s[j].b);
num[j].ro=(find(s[j].a,n)+find(s[j].b,n))/2;
//printf("num[%d]=%.6lf\n",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\n",flag);
if(max<flag)
{
max=flag;
ans=i;
}
}
printf("%s\n",temp[ans].na);
}
return 0;
}

Succession的更多相关文章

  1. UVALive 4685 Succession 树DP+背包

    一.前言 这道题同样来自于红书P142,作为树DP专题中的一道比较难的题目,A了一天左右的时间,看上去事实证明,这题的难度理我本身的实力还是有些太远了,于是正确的做法应该是分析一下题目之后进行解析什么 ...

  2. 多线程爬坑之路-Thread和Runable源码解析

    多线程:(百度百科借一波定义) 多线程(英语:multithreading),是指从软件或者硬件上实现多个线程并发执行的技术.具有多线程能力的计算机因有硬件支持而能够在同一时间执行多于一个线程,进而提 ...

  3. Java多线程系列--“JUC锁”03之 公平锁(一)

    概要 本章对“公平锁”的获取锁机制进行介绍(本文的公平锁指的是互斥锁的公平锁),内容包括:基本概念ReentrantLock数据结构参考代码获取公平锁(基于JDK1.7.0_40)一. tryAcqu ...

  4. Java多线程系列--“JUC锁”04之 公平锁(二)

    概要 前面一章,我们学习了“公平锁”获取锁的详细流程:这里,我们再来看看“公平锁”释放锁的过程.内容包括:参考代码释放公平锁(基于JDK1.7.0_40) “公平锁”的获取过程请参考“Java多线程系 ...

  5. 【神器】vimum在浏览器中键盘操作选择、复制、粘贴,键盘党的最爱

    1.下载: http://files.cnblogs.com/files/quejuwen/vimum_extension_1_56.zip 2.开源:https://github.com/philc ...

  6. although 和 although 的区别

    作为连词的时候,although 和 though 是可以互换的.Although 一般被认为更加正式一些.比如,以下的这些句子: Growth in Europe is maintaining mo ...

  7. [CodeWars][JS]实现链式加法

    在知乎上看到这样一个问题:http://www.zhihu.com/question/31805304; 简单地说就是实现这样一个add函数: add(x1)(x2)(x3)...(xn) == x1 ...

  8. Java并发编程基础--基本线程方法详解

    什么是线程 线程是操作系统调度的最小单位,一个进程中可以有多个线程,这些线程可以各自的计数器,栈,局部变量,并且能够访问共享的内存变量.多线程的优势是可以提高响应时间和吞吐量. 使用多线程 一个进程正 ...

  9. 【静默安装】configToolAllCommands响应文件问题

    [静默安装]configToolAllCommands响应文件问题 客户在静默安装RAC 12.1.0.2的时候有如下的输出: Successfully Setup Software. As inst ...

随机推荐

  1. SPOJ 10232. Distinct Primes

    Arithmancy is Draco Malfoy's favorite subject, but what spoils it for him is that Hermione Granger i ...

  2. tyvj 1004 滑雪 记忆化搜索

    滑雪 Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://www.tyvj.cn/p/1004 Description     trs喜欢滑雪.他来 ...

  3. mySql---or和in的效率问题(和<=、>=、between之间的关系)

    写在前面: 本文是直接拿取的别人的实验数据作参考,然后对数据作分析. 参考网友的测试数据结果: 在网上一直看到的是or和in的效率没啥区别,一直也感觉是这样,前几天刚好在看<mysql数据库开发 ...

  4. PostgreSQL增强版命令行客户端(pgcli)

    效果: 安装: https://www.pgcli.com/install 官网: https://www.pgcli.com/

  5. asp.net MVC 3/4 equivalent to a response.filter

    am in a need to intercept all of the html that will be sent to the browser and replace some tags tha ...

  6. MVC中使用CKEditor01-基础

    本篇体验在MVC中使用CKEditor,仅仅算思路.基础,暂没有把验证等与CKEditor结合在一起考虑. □ 1 使用NUGET引入CKEditorPM> Install-Package CK ...

  7. window与linux文件传输工具

    window与linux文件传输工具 [一般用于SecureCRT ssh中使用] 法一:直接用yum安装lrzsz(推荐) yum install lrzsz -y 注意:rhel安装完系统后 直接 ...

  8. C语言编程规范

    C语言编程规范 6 函数与过程 6.1 函数的功能与规模设计 函数应当短而精美,而且只做一件事.不要设计多用途面面俱到的函数,多功能集于一身的函数,很可能使函数的理解.测试.维护等变得困难. 6.2 ...

  9. Nginx缓存使用官方教程及常见问题解答

    原文地址:http://www.kuqin.com/shuoit/20150804/347388.html 我们都知道,应用程序和网站一样,其性能关乎生存.但如何使你的应用程序或者网站性能更好,并没有 ...

  10. 用wubi安装的Ubuntu在重装Windows 7系统后,如何恢复(转)

    原文链接:双系统Win7+Ubuntu,重装Win7后找不到Ubuntu启动引导项问题 1.把安装ubuntu->winboot文件夹下wubidr和wubidr.mbr两个文件拷到C盘根目录下 ...