计蒜客————King's Heir
来源:互联网 发布:石家庄淘宝模特 编辑:程序博客网 时间:2024/06/10 20:30
- 56.93%
- 2000ms
- 262144K
The king is dead, long live the king! After the sudden death of the king Fert XIII the people of theFlatland Kingdom are going to welcome the new king. Unfortunately, there is a problem, Fert has too many sons.
Actually, he has n sons and he loved each new son more than all of his previous sons. Well, probably he just stopped loving his sons because of their bad behavior. Anyway, after the new son was born Fert made the new testament that declared that the newly born son would be the heir.
However, there is a problem. Only the king’s son who is at least 18 years old at the moment of the king’s death can become a new king. Now the ministers of the government are trying to find the correct new king, but they seem to fail. Help them!
Input
The first line of the input contains three integers: d,m and y — the day, the month and the year of the king’s death, d is from 1 to 31, m is from 1 to 12,y is from 1 to 9999. It is guaranteed that there exists day d in month m, all months have the same number of days in Flatland as in our country, except thatFlatland calendar doesn’t have leap years, so February (month 2) always has 28 days.
The second line contains n (1 ≤ n ≤ 100) — the number of king’s sons. The following n lines contain three integers each di, mi and yi and specify the birth dates of king’s sons. All dates are correct and no son is born after or on the day of king’s death. The king had no twins, so no two sons were born on the same date.
Output
Output one integer — the number of the son that would become the king, or −1 if none of them is at least 18 years old. The sons are numbered from 1 to n in order they are described in the input. The youngest son who is at least 18 years old at the moment of the king’s death would become the king. If the son has his 18th birthday exactly on the day of the king’s death, he can become a king.
样例输入1
22 10 2016728 2 199922 7 199521 10 199823 10 19983 9 20001 4 201317 12 2004
样例输出1
3
样例输入2
22 10 2016128 2 1999
样例输出2
-1
给出国王的死亡日期,找出最年轻的大于等于18的王子。
#include<iostream>#include<cstdio>#include<algorithm>using namespace std;#define trans(x,y,z) z+0.01*y+0.0001*xint main(){ int x,y,z; while(~scanf("%d%d%d",&x,&y,&z)){ double X=trans(x,y,z),val=99999; int n,flag=-1; scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d%d%d",&x,&y,&z); double t=trans(x,y,z); if(X-t>=18.0&&X-t<val){ flag=i; val=X-t; } } printf("%d\n",flag); } return 0;}
- 计蒜客————King's Heir
- Codeforces Gym 101142 K. King's Heir
- Gym 101142K King's Heir
- King Arthur's Knights —— 结题报告!
- HDU 4337 King Arthur's Knights——回溯法
- King's Quest —— POJ1904(ZOJ2470)Tarjan缩点
- 约瑟夫环问题——(Hdu-5643,King's Game)
- Gulliver's Travels——7、At the King's palace
- The Love of a King——6、The King is Dead!Long Live the King
- 搜索算法king——A*初识
- The Love of a King——4、The Meeting
- The Love of a King——5、Wallis
- The Love of a King——7、The Church
- The Love of a King——8、The Storm
- The Love of a King——10、The Wedding
- The Love of a King——11、Paris
- Willlam Shakespeare——8、A Scottish King for England
- SCOI2005——互不侵犯King(状压DP)
- 调优经验
- SpringCloud教程 | 第二篇: 服务消费者(rest+ribbon)
- 基于HTML5 Canvas的工控SCADA模拟飞机飞行
- Linux内核开发(一)-----动手实现第一个helloworld程序
- JAVA byte有无符号数的转换
- 计蒜客————King's Heir
- 12、javascript中数组常用的函数操作总结
- c++虚函数
- Quartz定时任务
- 补间动画效果
- 手机无线连接电脑、抓取日志、日志检索命令
- node.js 异步流程控制async
- 牛顿法及拟牛顿法
- shell脚本打印多行文本到文件