题解 P2777 【[AHOI2016初中组]自行车比赛】

· · 题解

首先我的AC之路不(超级)太(不)顺利 刚开始不长眼开了个10005的数组,错的一塌糊涂T_T

sublime text3有[delete]可恨可耻可烦的[/delete]bug!

sublime text3有[delete]可恨可耻可烦的[/delete]bug!

sublime text3有[delete]可恨可耻可烦的[/delete]bug!

重要的事情说三遍!!

刚开始我有一个变量定义为count,结果用命令行一编译,蹦出几十个错误,全指向这个count变量。后来调成_count就没有问题了。

把数组和count变量改完了之后一编译,发现虽然没有RE了,但全是WA,没办法了,WA一般意味着你的程序出错了,改吧,最后发现自己的一个小变量设错了,改完之后AC。

思路是这样的:

1.读入

2.排序(STL,手打均可)

3.写一个get函数,用于查找下一个比当前选手比分高的人,若没有,返回-1,否则返回比分高的人的下标。

4.如果返回值为-1,计数器直接+1。

否则如果当前选手的最高得分(+n)比当前最高分的选手的最低得分(+1)高的话,计数器+1,又找到一个。

5.循环N次(确定了,就是N次!)之后程序结束。

这是一道水题,但绝不能掉以轻心。

附代码(我好像忘了贴代码的格式了):

···cpp

#include <cstdio>
#include <algorithm>
using namespace std;
const int size = 3000005;
int n,A[size],_count = 0;
int get(int id){
    for(int i = id+1; i < n; i++) if(A[i] > A[id]) return i;
    return -1;
}
int main(int argc, char const *argv[]){
    scanf("%d",&n);
    for(int i = 0; i < n; i++) scanf("%d",&A[i]);
    //solve
    sort(A,A+n);
    for(int i = 0; i < n; i++){
        int key = get(i);
        if(key == -1){ _count++; continue; }
        if(A[i]+n >= A[n-1]+1) _count++;
    }
    printf("%d\n",_count);
    return 0;
}
···