hdu 5162 Jump and Jump...(模拟)
2016-07-16 11:09
330 查看
Jump and Jump...
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1500 Accepted Submission(s): 787
Problem Description
There are n kids
and they want to know who can jump the farthest. For each kid, he can jump three times and the distance he jumps is maximum distance amount all the three jump. For example, if the distance of each jump is (10, 30, 20), then the farthest distance he can jump
is 30. Given the distance for each jump of the kids, you should find the rank of each kid.
Input
There are multiple test cases. The first line of input contains an integer T (1≤T≤100),
indicating the number of test cases. For each test case: The first line contains an integer n (2≤n≤3),
indicating the number of kids. For the next n lines,
each line contains three integers ai,bi and ci (1≤ai,bi,ci,≤300),
indicating the distance for each jump of the i-th
kid. It's guaranteed that the final rank of each kid won't be the same (ie. the farthest distance each kid can jump won't be the same).
Output
For each test case, you should output a single line contain n integers,
separated by one space. The i-th
integer indicating the rank of i-th
kid.
Sample Input
2
3
10 10 10
10 20 30
10 10 20
2
3 4 1
1 2 1
Sample Output
3 1 2
1 2
HintFor the first case, the farthest distance each kid can jump is 10, 30 and 20. So the rank is 3, 1, 2.
题意:n个孩子,每个孩子跳3下,最远的一下为孩子的跳远距离,输入保证不会有两个孩子的最远跳远距离相等。
输出1~n号孩子的排名
思路:直接模拟即可
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
struct Node
{
int id,dis;
}kid[10];
bool cmp(Node a,Node b)
{
return a.dis>b.dis;
}
int ans[10];
int main()
{
int T,n;
int dis,dis1,dis2;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d %d %d",&dis,&dis1,&dis2);
dis=max(dis,dis1);
kid[i].dis=max(dis,dis2);
kid[i].id=i;
}
sort(kid+1,kid+1+n,cmp);
for(int i=1;i<=n;i++)
ans[kid[i].id]=i;
for(int i=1;i<n;i++)
printf("%d ",ans[i]);
printf("%d\n",ans
);
}
return 0;
}
相关文章推荐
- STM32注释风格参考
- 【gcc】warning: control reaches end of non-void function
- s-palindrome
- 某单位OTT TV解决方案 20140710
- selenium测试(Java)--告警框处理(十四)
- 关于Python2中utf8,gbk,ascii的编码问题
- 10. Regular Expression Matching
- mysql安装 for windows
- Subversion实现原理介绍及钩子的使用
- 华为OTT交流材料
- 3. Longest Substring Without Repeating Characters
- PHP与MYSQL学习笔记-基础篇3(结构化编程)
- 给Windows + Apache 2.2 + PHP 5.3 安装PHP性能测试工具 xhprof_0.10.3_php53_vc9.dll
- xilium CefGlue集成包
- MVC学习系列6--使用Ajax加载分部视图和Json格式的数据
- 002——hibernate的介绍&优缺点&工作流程
- ajax 即点即改
- mysql 开启远程连接
- 金庸笔下的编程秘籍
- for clause in Java