一二三四五 上山打老虎

CCF-CSP-2020-12-2 期末预测之最佳阈值

链接:http://118.190.20.162/view.page?gpid=T122

思路:发现计算规律,得到选每个y值的准确率计算公式,按照y值从小到大进行排序,依次计算选最大y。

坑点:对于两个y值相同的情况要特判考虑。

代码:

#include<bits/stdc++.h>

using namespace std;
struct node {
    int l,r;
    node(int _l,int _r):l(_l),r(_r){}
};
vector<node> a;
bool cmp(node s,node t){
    if(s.l==t.l)return s.r<t.r;
    return s.l<t.l;
}
int main (){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int num=0;
    int l,r;
    for(int i=0;i<n;i++){
        cin>>l>>r;
        a.push_back(node(l,r));
        num+=r;
    }
    sort(a.begin(),a.end(),cmp);
    int ans=0;
    int atm=0,no=0,s;
    for(int i=0;i<n;i++){
        if(i!=0&&a[i].l==a[i-1].l){
                ans+=a[i].r;
                continue;
        }
        s=i+num-2*ans;
        if(s>=atm){
            atm=s;
            no=a[i].l;
        }
        //cout<<a[i].l<<" "<<s<<endl;
        ans+=a[i].r;

    }
    cout<<no;
    return 0;
}

posted @ 2021-03-14 20:18  黒川川  阅读(202)  评论(0)    收藏  举报