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. Codeforces Round #359 (Div. 2) A. Free Ice Cream 水题

    A. Free Ice Cream 题目连接: http://www.codeforces.com/contest/686/problem/A Description After their adve ...

  2. Perforce-Server迁移

    Author: JinDate: 20140827System: Windows 2008 R2 从Windows 2008 R2迁移到Windows 2008 R2 linux版本迁移官方文档htt ...

  3. ISO 7816-4: Interindustry Commands for Interchange

    5. Basic Organizations 5.1 Data structures5.2 Security architecture of the card 5.3 APDU message str ...

  4. 什么叫NAT,设置NAT的两个方法

    NAT是网络地址翻译就是把公网IP翻译成私有地址, 又叫端口映射或端口转发. 采用路由方式是指ADSL拥有一个动态或固定的公网IP,ADSL直接接在HUB或交换机上,所有的电脑共享上网.这时ADSL的 ...

  5. CHM编写软件

    工具选择 1.         HTML编辑工具:就是用什么软件写文档的问题.一直都是做.NET开发,所以选择HTML编辑也大都在MS阵营里选.主要有以下几种HTML编辑器. (1)       Dr ...

  6. SQL:查询学习笔记

    SQL 查询命令 SELECT 语法 SELECT "column_name" FROM "table_name"; 返回一列 SELECT Username ...

  7. windows下的Nginx+Squid+Tomcat+Memcached集群

  8. 触发器系列(2) DataTrigger

    触发条件: DataTrigger是以控件DataContext的属性作为触发条件 本例效果说明: <!--当值为1时将外边框的背景色改为黑色--> <!--当值为2时 改变透明度达 ...

  9. MapReduce任务分析与讨论MapReduce job explained

    In the last post we saw how to run a MapReduce job on Hadoop. Now we're going to analyze how a MapRe ...

  10. Informatica 常用组件Lookup缓存之二 使用永久查找高速缓存

    可以将"查找"转换配置为使用非永久或永久高速缓存.基于"查找高速缓存永久"属性的会话成功后,PowerCenter 将保存或删除查找高速缓存文件. 如果查找表在 ...