CCF-CSP记录 202012-2

#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
bool cmp(pair<int, int> a, pair<int, int> b){
	return a.first < b.first;
}
int main(){
	int n;
	cin >> n;
	int a,b;
	//一定记得打空格 不然会编译不通过 
	vector<pair<int, int> > stu(n);
	for(int i = 0;i <n;i++){
		cin>>a>>b;
		stu[i] = make_pair(a,b);
	}
	sort(stu.begin(), stu.end(), cmp);
	//先计算最小的正确率并记录小于该阈值的最后一个下标
	int count = 0;
	int maxCount = -1;
	int index = 0;
	int maxTheta = stu[0].first;
	int nowTheta = maxTheta;
	for(int i = 0;i < n;i++){
		if(stu[i].first >= nowTheta && stu[i].second == 1){
			count++;
		}else if(stu[i].first < nowTheta && stu[i].second == 0){
			count++;
			index = i;
		}
	} 
	maxCount = count;
	//遍历vector,查找到下一个阈值,对index+1到阈值前的一部分进行判断,如果新阈值判断对了,说明旧阈值判断的是错的,+1,否则-1
	for(int i = 1;i < n;i++){
		if(nowTheta == stu[i].first){
			continue;
		}
		nowTheta = stu[i].first;
		while(stu[index].first < nowTheta){
			if(stu[index].second == 1){
				count--;
			}else{
				count++;
			}
			index++;
		}
		if(count >= maxCount){
			maxCount = count;
			maxTheta = nowTheta;
		}
	} 
	cout<<maxTheta<<endl;
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值