Jump and Jump...
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 102 Accepted Submission(s): 72
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.
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 integern (2≤n≤3) ,
indicating the number of kids. For the nextn lines,
each line contains three integersai,bi and ci (1≤ai,bi,ci,≤300 ),
indicating the distance for each jump of thei -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).
indicating the number of test cases. For each test case: The first line contains an integer
indicating the number of kids. For the next
each line contains three integers
indicating the distance for each jump of the
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. Thei -th
integer indicating the rank ofi -th
kid.
separated by one space. The
integer indicating the rank of
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 2HintFor the first case, the farthest distance each kid can jump is 10, 30 and 20. So the rank is 3, 1, 2.
代码:
# include<cstdio> # include<iostream> # include<algorithm> using namespace std; # define MAX 5 struct node { int id; int jump; int rk; }b[MAX]; int a[MAX]; int cmp( const struct node & x,const struct node & y ) { return x.jump>y.jump; } int cmp2( const struct node & x,const struct node & y ) { return x.id < y.id; } int main(void) { int t;cin>>t; while ( t-- ) { int n;cin>>n; int j = 1; for ( int t = 1;t <= n;t++ ) { for ( int i = 1;i <= 3;i++ ) { cin>>a[i]; } sort(a+1,a+1+3); b[j++].jump = a[3]; //j++; } for ( int i = 1;i <= n;i++ ) { b[i].id = i; } sort(b+1,b+1+n,cmp); for ( int i = 1;i <= n;i++ ) { b[i].rk = i; } sort(b+1,b+1+n,cmp2); for ( int i = 1;i <= n-1;i++ ) { cout<<b[i].rk<<" "; } cout<<b[n].rk<<endl; //cout<<endl; } return 0; }