zoukankan      html  css  js  c++  java
  • 水题 Codeforces Round #307 (Div. 2) A. GukiZ and Contest

    题目传送门

     1 /*
     2     水题:开个结构体,rk记录排名,相同的值有相同的排名
     3 */
     4 #include <cstdio>
     5 #include <cstring>
     6 #include <algorithm>
     7 #include <cmath>
     8 #include <string>
     9 #include <iostream>
    10 #include <queue>
    11 #include <map>
    12 #include <vector>
    13 using namespace std;
    14 
    15 const int MAXN = 2e3 + 10;
    16 const int INF = 0x3f3f3f3f;
    17 struct A
    18 {
    19     int v, id, rk;
    20 }a[MAXN];
    21 
    22 bool cmp_v(A x, A y)    {return x.v > y.v;}
    23 
    24 bool cmp_id(A x, A y)    {return x.id < y.id;}
    25 
    26 int main(void)        //Codeforces Round #307 (Div. 2) A. GukiZ and Contest
    27 {
    28 //    freopen ("A.in", "r", stdin);
    29 
    30     int n;
    31     while (scanf ("%d", &n) == 1)
    32     {
    33         for (int i=1; i<=n; ++i)
    34         {
    35             scanf ("%d", &a[i].v);    a[i].id = i;
    36         }
    37         sort (a+1, a+1+n, cmp_v);
    38 
    39         int cnt = 1;    a[0].v = a[1].v;    a[0].rk = 1;
    40         for (int i=1; i<=n; ++i)
    41         {
    42             if (a[i].v < a[i-1].v)
    43             {
    44                 a[i].rk = cnt++;
    45             }
    46             else
    47             {
    48                 a[i].rk = a[i-1].rk;    cnt++;
    49             }
    50         }
    51         sort (a+1, a+1+n, cmp_id);
    52         for (int i=1; i<=n; ++i)
    53         {
    54             printf ("%d%c", a[i].rk, (i==n) ? '
    ' : ' ');
    55         }
    56     }
    57 
    58     return 0;
    59 }
    编译人生,运行世界!
  • 相关阅读:
    testlink安装全攻略
    软件测试过程管理脑图
    VBS: FSO对象及文件读写
    最简单的NT驱动
    过DNF TP驱动保护(二)(转载)
    DebugPrint格式输出
    ObReferenceObjectByName
    最简单的WDM驱动
    设备对象(DEVICE_OBJECT)设备名称
    ObReferenceObjectByHandle内核函数
  • 原文地址:https://www.cnblogs.com/Running-Time/p/4573467.html
Copyright © 2011-2022 走看看