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 ...
随机推荐
- XMOJ 1133: 膜拜大牛 计算几何/两圆相交
1133: 膜拜大牛 Time Limit: 1 Sec Memory Limit: 131072KiBSubmit: 9619 Solved: 3287 题目连接 http://acm.xmu. ...
- ASP.NET Web API 记录请求响应数据到日志的一个方法
原文:http://blog.bossma.cn/dotnet/asp-net-web-api-log-request-response/ ASP.NET Web API 记录请求响应数据到日志的一个 ...
- 你的C/C++程序为什么无法运行?揭秘Segmentation fault (2)
什么让你对C/C++如此恐惧? 本篇将继续上一篇来讨论段错误(Segmentation fault). 上一篇: 你的C/C++程序为什么无法运行?揭秘Segmentation fault(1) 追溯 ...
- 新型穿墙监控雷达Range-R:让你的隐私无所遁形(转)
还是隐私问题,原帖地址:http://www.freebuf.com/news/57446.html 在我们的认知中,政府对民众的监控已经成为一种常态.从电话.电子邮件到通信聊天.社交网络,一切细节都 ...
- 探究Linux下参数传递及查看和修改方法
http://m.blog.csdn.net/blog/moonvs2010/11392959
- Google In-App Billing 实现(内含Unity 实现经验)
实现内购计费 傻逼目录 Adding the AIDL file Updating Your Manifest Creating a ServiceConnection Making In-app ...
- Android之ConnectivityManager
在android平台中ConnectivityManager主要负责查询网络连接状态以及在连接状态有变化的时候发出通知.其主要的功能职责如下: 1. 监视网络状态,包括(Wi-Fi.GPRS.UMT ...
- Extjs Gridpanel 动态加载
colMArray_ljdj=[smQd, {header : /*"代销机构代码"*/"机构", dataIndex : "dxjgdm" ...
- AndroidMainifest标签使用说明1——<action>
1.<action> 格式: <action android:name="string" /> 父标签: <intent-filter> 描写叙 ...
- 如何构建Win32汇编的编程环境(ONEPROBLEM个人推荐)
如何构建Win32汇编的编程环境(ONEPROBLEM个人推荐)1.首先要下载我提供的软件包(里面已经包含所有所需软件); 2.把它解压到D盘根目录下(如果需要安装在其它的地方,请注意设好路径); ...