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
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
betsy andrew flora
carol andrew betsy
dora andrew carol
elena andrew dora
carol
dora
elena
flora
gloria
Sample Output
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的更多相关文章
- UVALive 4685 Succession 树DP+背包
一.前言 这道题同样来自于红书P142,作为树DP专题中的一道比较难的题目,A了一天左右的时间,看上去事实证明,这题的难度理我本身的实力还是有些太远了,于是正确的做法应该是分析一下题目之后进行解析什么 ...
- 多线程爬坑之路-Thread和Runable源码解析
多线程:(百度百科借一波定义) 多线程(英语:multithreading),是指从软件或者硬件上实现多个线程并发执行的技术.具有多线程能力的计算机因有硬件支持而能够在同一时间执行多于一个线程,进而提 ...
- Java多线程系列--“JUC锁”03之 公平锁(一)
概要 本章对“公平锁”的获取锁机制进行介绍(本文的公平锁指的是互斥锁的公平锁),内容包括:基本概念ReentrantLock数据结构参考代码获取公平锁(基于JDK1.7.0_40)一. tryAcqu ...
- Java多线程系列--“JUC锁”04之 公平锁(二)
概要 前面一章,我们学习了“公平锁”获取锁的详细流程:这里,我们再来看看“公平锁”释放锁的过程.内容包括:参考代码释放公平锁(基于JDK1.7.0_40) “公平锁”的获取过程请参考“Java多线程系 ...
- 【神器】vimum在浏览器中键盘操作选择、复制、粘贴,键盘党的最爱
1.下载: http://files.cnblogs.com/files/quejuwen/vimum_extension_1_56.zip 2.开源:https://github.com/philc ...
- although 和 although 的区别
作为连词的时候,although 和 though 是可以互换的.Although 一般被认为更加正式一些.比如,以下的这些句子: Growth in Europe is maintaining mo ...
- [CodeWars][JS]实现链式加法
在知乎上看到这样一个问题:http://www.zhihu.com/question/31805304; 简单地说就是实现这样一个add函数: add(x1)(x2)(x3)...(xn) == x1 ...
- Java并发编程基础--基本线程方法详解
什么是线程 线程是操作系统调度的最小单位,一个进程中可以有多个线程,这些线程可以各自的计数器,栈,局部变量,并且能够访问共享的内存变量.多线程的优势是可以提高响应时间和吞吐量. 使用多线程 一个进程正 ...
- 【静默安装】configToolAllCommands响应文件问题
[静默安装]configToolAllCommands响应文件问题 客户在静默安装RAC 12.1.0.2的时候有如下的输出: Successfully Setup Software. As inst ...
随机推荐
- dos系统下的游戏~ 不断更新中
#include <cstdio> #include <cmath> #include <cstring> #include <ctime> #incl ...
- hibernate核心配置
# hibernate核心配置 注意: - hibernate.cfg.xml默认放在src目录下(这样可以自动加载该文件) - 必须配置的参数: * 数据库的四大参数和方言 - 可选配置的参 ...
- 力特ZE398C驱动光盘-USB转RS232-支持Windows 10/Mac
这个工具是USB1.1的,相对来说比较老,一开始做小白鼠不知道买了USB1.1的,所以我不建议买这个,还有其它的型号,支持USB2.0和USB3.0,不过价格也相对来说比较贵,这个才30块钱左右. 关 ...
- [转载] MFC绘制动态曲线,用双缓冲绘图技术防闪烁
转载的原文地址 先上效果图 随着时间的推移,曲线向右平移,同时X轴的时间坐标跟着更新. 一.如何绘制动态曲线 所谓动画,都是一帧一帧的图像连续呈现在用户面前形成的.所以如果你掌握了如何绘制静态曲线,那 ...
- memcached-session-manager配置
原文地址: http://chenzhou123520.iteye.com/blog/1650212 声明:本篇文章是根据memcached-session-manager官方配置方法wiki页面翻译 ...
- 将数据处理逻辑集中到一处进行管理,逐步实现真正有效的 MVC 分层结构
将数据处理逻辑集中到一处进行管理,逐步实现真正有效的 MVC 分层结构.
- 演示Microsoft Advertising SDK for Windows Phone 8.1
演示Microsoft Advertising SDK for Windows Phone 8.1,Only for Windows Phone 8.1 1.在References上点右键,添加引用, ...
- 算法:合并排序(Merge Sort)
算法定义 合并排序是一种递归算法,思路如下: 如果源数组长度为 1,立即返回. 将源数组平分为两个新数组:Left 和 Right. 对 Left 执行递归排序. 对 Right 执行递归排序. 将排 ...
- pytest文档16-用例a失败,跳过测试用例b和c并标记失败xfail
前言 当用例a失败的时候,如果用例b和用例c都是依赖于第一个用例的结果,那可以直接跳过用例b和c的测试,直接给他标记失败xfail 用到的场景,登录是第一个用例,登录之后的操作b是第二个用例,登录之后 ...
- glassfish3 读不到web程序的jar包
现在项目中用到glassfish3,部署了一个web程序.可以访问到首页,但是在登陆的时候提示找不到数据库的驱动包.这个jar包我是放在web-inf/lib下的.但是glassfish就是报找不到j ...