题意:根据获得的等级排名次,等级相同的获得相同的名次,出现相同等级的下一个名次,获得他的真实名次(等级在他前面的人数 + 1),比如等级为 3 3 1,则根据规则前两人获得名次1, 第三人获得名次在他前面的人数 + 1, 就是3 输出 1 1 3.
解题思路:结构数组记录他们的位置和等级, 根据等级排降序,根据上述规则给他们指定名次就好了。
Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest.
In total, n students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to n. Let's denote the rating of i-th student as ai. After the contest ends, every student will end up with some positive integer position. GukiZ expects that his students will take places according to their ratings.
He thinks that each student will take place equal to . In particular, if student A has rating strictly lower then student B, A will get the strictly better position than B, and if two students have equal ratings, they will share the same position.
GukiZ would like you to reconstruct the results by following his expectations. Help him and determine the position after the end of the contest for each of his students if everything goes as expected.
The first line contains integer n (1 ≤ n ≤ 2000), number of GukiZ's students.
The second line contains n numbers a1, a2, ... an (1 ≤ ai ≤ 2000) where ai is the rating of i-th student (1 ≤ i ≤ n).
In a single line, print the position after the end of the contest for each of n students in the same order as they appear in the input.
3 1 3 3
3 1 1
1 1
1
5 3 5 3 4 5
4 1 4 3 1
In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating.
In the second sample, first student is the only one on the contest.
In the third sample, students 2 and 5 share the first position with highest rating, student 4 is next with third position, and students 1 and 3are the last sharing fourth position.
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<list>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
using namespace std;
int buf[10];
//整型变量快速输入输出函数
inline int readint()
{
char c = getchar();
while(!isdigit(c)) c = getchar();
int x = 0;
while(isdigit(c))
{
x = x * 10 + c - '0';
c = getchar();
}
return x;
}
inline void writeint(int i)
{
int p = 0;
if(i == 0) p++;
else while(i)
{
buf[p++] = i % 10;
i /= 10;
}
for(int j = p - 1 ; j >= 0 ; --j) putchar('0' + buf[j]);
}
//
#define MAX_N 2005
const int INF = 0x3f3f3f3f;
int ans[MAX_N];
struct node
{
int d, id;
};
bool cmp(node a, node b)
{
return a.d > b.d;
}
node t[MAX_N];
int main()
{
int n;
n = readint();
for(int i = 1 ; i <= n ; i++)
{
t[i].d = readint();
t[i].id = i;
}
sort(t + 1, t + n + 1, cmp);
int tmp = 1;
ans[t[1].id] = tmp;
for(int i = 2 ; i <= n ; i++)
{
if(t[i].d == t[i - 1].d)
{
ans[t[i].id] = tmp;
}
else
{
ans[t[i].id] = i;
tmp = i;
}
}
for(int i = 1 ; i <= n ; i++)
{
cout<<ans[i]<<" ";
}
return 0;
}