Codeforces Gym 101142 K. King's Heir
来源:互联网 发布:java scala 混合编程 编辑:程序博客网 时间:2024/05/19 12:40
题意
根据国王的死亡日期或他的 n 个儿子的出生日期,找出在国王死亡时刻满 18 周岁且最年轻的儿子。
解题思路
模拟
代码
#include<bits/stdc++.h>using namespace std;struct Age { int d, m, y, idx;} age[120], norm;bool operator<(Age a, Age b) { if(a.y == b.y) { if(a.m == b.m) return a.d > b.d; return a.m > b.m; } return a.y > b.y;}bool jug(int i){ if(age[i].y < norm.y) return true; if(age[i].y > norm.y) return false; if(age[i].m < norm.m) return true; if(age[i].m > norm.m) return false; if(age[i].d > norm.d) return false; return true;}int main(){ freopen("king.in", "r", stdin); freopen("king.out", "w", stdout); scanf("%d %d %d",&norm.d, &norm.m, &norm.y); int n; scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d %d %d", &age[i].d, &age[i].m, &age[i].y); age[i].idx = i; } sort(age+1, age+n+1); norm.y -= 18; for(int i=1;i<=n;i++) { if(jug(i)) { printf("%d\n", age[i].idx); return 0; } } printf("-1\n");}
阅读全文
0 0
- Codeforces Gym 101142 K. King's Heir
- Gym 101142K King's Heir
- Codeforces Gym 100792K King's Rout
- Gym 100792K King’s Rout
- Codeforces Gym 100792K King's Rout(优先队列+拓扑排序)
- Gym 100792K King's Rout(拓扑排序)
- 计蒜客————King's Heir
- GYM 100792k King's Rout (拓扑排序+优先队列)
- codeforces [Gym-100814K]
- Codeforces gym 101149 K 想法
- Codeforces gym 101102 K 想法
- codeforces Gym 101341 K Competitions
- Codeforces Gym 100819S Surf
- Codeforces Gym 101484 K Counting Good Teams
- Codeforces 30D King's Problem? 模拟
- codeforces 30D King's Problem? 数学
- Codeforces Gym 100623K Problem K. Key to Success
- Codeforces Gym 101142 F. Folding
- volatile
- UNIX环境高级编程-读书笔记-epoll
- google自动驾驶的rviz界面长啥样?
- unity中实现一个非常简单的fpsController
- android html5点击输入框页面变大
- Codeforces Gym 101142 K. King's Heir
- 欢迎使用CSDN-markdown编辑器
- android Spannable修改text颜色
- 线段树
- Accessible Map——访问地图
- 前端调试必备技巧(控制台使用完全指南)
- POJ1860---Currency Exchange (最短路:验证是否存在正环)
- prevent deception,舞步学院教你预防爱情网骗
- Eclipse快捷键 10个最有用的快捷键