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. BZOJ 2743: [HEOI2012]采花 离线树状数组

    2743: [HEOI2012]采花 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=2743 Description 萧芸斓是Z国的公主, ...

  2. BZOJ 1059: [ZJOI2007]矩阵游戏 匈牙利算法

    1059: [ZJOI2007]矩阵游戏 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2351  Solved: 1156 题目连接 http:// ...

  3. SQLite3知识(1)--教程

    1.SQLite3教程 [1].SQLite 教程 2.选择数据库: [2]. SQLite Select 语句 3.更新数据库: [3]. SQLite Update 语句 4.插入数据库: [4] ...

  4. 仿querySeletor 兼容IE 67

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. 编写简单登陆和注册功能的demo时遇到的问题

    一.注册功能中添加数据不成功 给数据库添加EditText中的内容后,数据库中找不到添加后的数据,并且存在字符串为空的数据 解决方法:EditText registerAccount = (EditT ...

  6. blkblock 2工具

    http://blog.yufeng.info/archives/tag/blktrace

  7. RPM 打包技术与典型 SPEC 文件分析

    一 .rpm 介绍 1. 概述 RPM全称是 Red Hat Package Manager(Red Hat包管理器).几乎所有的 Linux 发行版本都使用这种形式的软件包管理安装.更新和卸载软件. ...

  8. C# string byte[] Base64 常用互相转换

    参考: http://www.cnblogs.com/zxx193/p/3605238.html?utm_source=tuicool http://www.cnblogs.com/freeliver ...

  9. 机器学习算法之旅A Tour of Machine Learning Algorithms

    In this post we take a tour of the most popular machine learning algorithms. It is useful to tour th ...

  10. Oracle中表列由VARCHAR2类型改成CLOB

    情景 原来表中的列定义成VARCHAR2类型,众所周知,VARCHAR2类型最大支持长度为4000.假设因为业务须要.想把此列转换为CLOB类型,在Oracle中直接通过ALTER语句转换是行不通的. ...