codeforces 551A GukiZ and Contest
来源:互联网 发布:java约瑟夫环问题 编辑:程序博客网 时间:2024/05/16 05:04
点击打开链接
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.
31 3 3
3 1 1
11
1
53 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<stdio.h>#include<algorithm>using namespace std;struct node{ int a,b,c;} s[2010];int compa(node a,node b){ return a.a>b.a;}int comp(node x,node y){ return x.b<y.b;}int main(){ int n; scanf("%d",&n); for(int i=0; i<n; i++) { scanf("%d",&s[i].a); s[i].b=i; } sort(s,s+n,compa); s[0].c=1; int w=1; for(int i=1; i<n; i++) { if(s[i].a==s[i-1].a) { s[i].c=s[i-1].c; w++; } else { w++; s[i].c=w; } } sort(s,s+n,comp); for(int i=0; i<n; i++) { if(i==0) printf("%d",s[i].c); else printf(" %d",s[i].c); } printf("\n"); return 0;}
- CodeForces-551A GukiZ and Contest
- 【74.89%】【codeforces 551A】GukiZ and Contest
- codeforces 551A GukiZ and Contest
- CodeForces 551A GukiZ and Contest(模拟)
- A. GukiZ and Contest
- coderforce 551A - GukiZ and Contest
- [水题]Codeforces Round #307 (Div. 2) A.GukiZ and Contest
- Codeforces Round #307 (Div. 2) A. GukiZ and Contest
- contest: Codeforces Round #307 (Div. 2), problem: (A) GukiZ and Contest
- Codeforces Round #307 (Div. 2) A. GukiZ and Contest (暴力)
- A. GukiZ and Contest-Codeforces Round #307 (Div. 2)-简单水题
- Codeforces551A:GukiZ and Contest
- GukiZ and Contest
- GukiZ and Contest
- Codeforces 551E GukiZ and GukiZiana (分块)
- codeforces 551E GukiZ and GukiZiana 分块
- Codeforces 551D GukiZ and Binary Operations
- Codeforces 551E GukiZ and GukiZiana 分块
- JavaScript的基础知识
- 在全景场景里添加平面视频
- 高中生就可学会编程--写在前面的话
- 算法笔记:二进制数有多少个1
- C语言模拟实现strncpy、strncpy、strncat、strstr和strrstr函数实现
- codeforces 551A GukiZ and Contest
- MultiByteToWideChar的用法
- 一些不错的网站
- ReactNative在安卓上遇到的问题
- ubuntu包管理命令apt
- Team 1——Add More Zero
- 随笔记:Mysql 对于换行符回车符 查询失效的处理
- 安装fastDFS遇到的问题总结
- A Serial Killer