GukiZ and Contest
来源:互联网 发布:python sum axis 1 编辑:程序博客网 时间:2024/06/05 08:44
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 nstudents 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 3 are the last sharing fourth position.
尽管是超简单的水题,也要记录自己犯下的每一个错。
这题没有细心看题,导致数组开小了所以错了。
#include<stdio.h>#include<algorithm>using namespace std;struct code{ int p; int r;}s[2003];bool compare1(code A,code B){ return A.r>B.r;}bool compare2(code A,code B){ return A.p<B.p;}int main(){ int n; while(scanf("%d",&n)!=EOF) { for(int i=0;i<n;i++) { scanf("%d",&s[i].r); s[i].p = i+1; } sort(s,s+n,compare1); int j=1; int t = s[0].r; s[0].r = j; for(int i=1;i<n;i++) { if(s[i].r==t) { t = s[i].r; s[i].r=j; } else { t = s[i].r; s[i].r = i+1; j = i+1; } } sort(s,s+n,compare2); for(int i=0;i<n;i++) { printf("%d ",s[i].r); } printf("\n"); } return 0;}
- Codeforces551A:GukiZ and Contest
- A. GukiZ and Contest
- GukiZ and Contest
- GukiZ and Contest
- CodeForces-551A GukiZ and Contest
- coderforce 551A - GukiZ and Contest
- 【74.89%】【codeforces 551A】GukiZ and Contest
- codeforces 551A GukiZ and Contest
- [水题]Codeforces Round #307 (Div. 2) A.GukiZ and Contest
- Codeforces Round #307 (Div. 2) A. GukiZ and Contest
- CodeForces 551A 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)-简单水题
- Codeforces 551E GukiZ and GukiZiana (分块)
- 分块法 CF551E GukiZ and GukiZiana
- GukiZ and Binary Operations(矩阵+二进制)
- codeforces 551E GukiZ and GukiZiana 分块
- 线程和信号
- 电磁震荡实验
- 51nod 1085 背包问题
- mysql--1.概念及安装
- 究竟什么是可重入锁?
- GukiZ and Contest
- 数位dp不要62
- 机器学习元知识
- Linux系统虚拟机的安装原理
- 普通工厂模式and抽象工厂模式
- Java的安全组成
- Ⅴ vue2.0 项目实战
- 实验二——双向链表
- oracle数据库写入数据的过程