Codeforces Round #307 (Div. 二) A. GukiZ and Contest
Codeforces Round #307 (Div. 2) A. GukiZ and Contest
http://codeforces.com/problemset/problem/551/A
分析:
给你N个数的分数,让你进行排名,可以并列,但是要空出相应的人头数。对应原位置输出排名即可。
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <string>
#include <numeric>
#include <algorithm>
#include <functional>
#include <iterator>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <complex>
#include <ctime>
#define INF 0x3f3f3f3f
#define eps 1e-6
#define p(x) printf("%d\n", x)
#define k(x) printf("Case %d: ", ++x)
#define mes(x, d) memset(x, d, sizeof(x))
#define s(x) scanf("%d", &x)
/*
int gcd(int a,int b)
{
return ! b ? a : gcd(b,a % b);
}
*/
struct data
{
int val;
int pos;
int ranks;
}p[2005];
bool cmp1(const data &a,const data &b)
{
if(a.val == b.val)
return a.pos < b.pos;
return a.val < b.val;
}
bool cmp2(const data &a,const data &b)
{
return a.val > b.val;
}
bool cmp3(const data &a,const data &b)
{
return a.pos < b.pos;
}
typedef long long LL;
const double pi = acos(-1.0);
const long long mod = 1e9 + 7;
using namespace std;
int main()
{
//freopen("int.txt","r",stdin);
//freopen("out.txt","w",stdout);
int N;
scanf("%d",&N);
for(int i = 1;i <= N;i++)
{
scanf("%d",&p[i].val);
p[i].pos = i;
}
sort(p + 1,p + N + 1,cmp2);
//for(int i = 1;i <= N;i++)
//printf("%d %d\n",p[i].val,p[i].pos);
for(int i = 1;i <= N;i++)
p[i].ranks = lower_bound(p + 1,p + N + 1,p[i],cmp2) - p;
sort(p + 1,p + N + 1,cmp3);
for(int i = 1;i < N;i++)
printf("%d ",p[i].ranks);
printf("%d\n",p[N].ranks);
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。