这是bestcoder #27的第一题,一般都是水题,由于本人仍是个渣渣,所以卡在了最后如何标记排序的序号上,犯了2个错误:
1,我是用结构体做的,记录每个人最大值排序后,不会改变相应编号,其实就是数组的套用,类似b[a[i].k]这样。(一直在纠结如何换过来,原来这么简单,自己太渣了)
2,在用标志变量的时候,为了方便,重复利用了一些,结果各种错,但是逻辑是对的,相当无奈,所以又重新定义了一些变量。(也不知道编译器是怎么处理的)
Jump and Jump...
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 120 Accepted Submission(s): 86
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
a
i
,b
i![]()
and
c
i![]()
(
1≤a
i
,b
i
,c
i
,≤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
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int b[1010];
struct E
{
int n;
int k;
}a[1010],c[1010];
int cmp(E a,E b)
{
return a.n>b.n;
}
int main()
{
int t,m,i,j;
scanf("%d",&t);
while(t--)
{
scanf("%d",&m);
memset(b,0,sizeof(b));
memset(a,0,sizeof(a));
for(i=0;i<m;i++)
{
for(j=0;j<3;j++)
scanf("%d",&a[j].n);
sort(a,a+3,cmp);
c[i].n=a[0].n;
c[i].k=i+1;
}
sort(c,c+m,cmp);
int r=1;
for(i=0;i<m;i++)
{
b[c[i].k]=r++;
}
for(i=1;i<m;i++)
printf("%d ",b[i]);
printf("%d",b[m]);
printf("\n");
}
return 0;
}