【74.89%】【codeforces 551A】GukiZ and Contest
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
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.
Input
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).
Output
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.
Examples
input
3
1 3 3
output
3 1 1
input
1
1
output
1
input
5
3 5 3 4 5
output
4 1 4 3 1
Note
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.
【题目链接】:http://codeforces.com/contest/551/problem/A
【题解】
模拟
模拟它的要求排序就好了.
用结构体比较方便。
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%I64d",&x)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int MAXN = 2000+100;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
struct abc
{
int x,pos;
};
int n;
abc a[MAXN];
int ans[MAXN];
bool cmp(abc a,abc b)
{
return a.x < b.x;
}
int main()
{
//freopen("F:\\rush.txt","r",stdin);
scanf("%d",&n);
rep1(i,1,n)
rei(a[i].x),a[i].pos = i;
sort(a+1,a+1+n,cmp);
rep1(i,1,n)
{
int l = i,r = i;
while (r+1<=n && a[r+1].x == a[l].x)
r++;
int temp = n-r+1;
rep1(j,l,r)
ans[a[j].pos] = temp;
}
rep1(i,1,n)
{
printf("%d",ans[i]);
if (i==n)
puts("");
else
putchar(' ');
}
return 0;
}
最新文章
- JavaScript中事件处理
- 【原】iOS学习之tableView的常见BUG
- python读取文件的方法
- 【HOW】如何对Reporting Services表格中数据按字段排序
- (转)一个JavaWeb项目开发总结
- Hadoop.2.x_时间服务器搭建(CentOs6.6)
- JMeter中3种参数值的传递
- 什么是ADB
- Hadoop 2.4.0全然分布式平台搭建、配置、安装
- 软件测试 -- 软件缺陷记录的5C原则
- Delphi- ini文件的读写操作
- Run-Time Check Failure #2 - Stack around the variable &#39;ucPriKey&#39; was corrupt
- js基础例子购物车升级版(未优化版)
- 《Head First Java》读书笔记(2) - Java面向对象思想
- Tensorflow模型加载与保存、Tensorboard简单使用
- gitlab 建立本地仓库
- Java反序列化漏洞实现
- 1T硬盘获3T体验 彻底解决NVR存储时间短的问题
- Mobile first! Wijmo 5 + Ionic Framework之:费用跟踪 App
- Java使用google开源工具Thumbnailator实现图片压缩