CCF 202012-2 期末预测之最佳阈值
2024-10-21 19:06:51
#include <iostream>
#include <bits/stdc++.h>
#include <string> using namespace std; typedef struct {
int y;
int result;
}S;
int main()
{
vector<S> s;
int number;
cin>>number;
while(number--)
{
S temp;
cin>>temp.y>>temp.result;
s.push_back(temp);
}
int Maxseita=INT_MIN;int seita;int maxsamenumber=INT_MIN;
for(int i=0;i<s.size();i++)
{
seita=s[i].y;
int samenumber=0;
for(int j=0;j<s.size();j++)
{
if(s[j].y>=seita)
{
if(s[j].result==1)
samenumber++;
}
else
{
if(s[j].result==0)
samenumber++;
} }
if(samenumber>maxsamenumber)
{
maxsamenumber=samenumber;
Maxseita=seita;
}
else if(samenumber==maxsamenumber)
{
if(seita>Maxseita)
{
Maxseita=seita;
}
}
}
cout<<Maxseita;
}
70
100
#include<iostream>
#include<set>
#include<vector>
#include<algorithm>
#include<cstring>
#define mm(a,b) memset(a,b,sizeof(a))
using namespace std;
struct node{
int y;
int result;
};
bool cmp(node a,node b){
return a.y<b.y;
}
vector<node> v;
set<int> s;
node temp;
const int N=1e5+5;
int sum[N];
int best_y,best_num;
int main(){
mm(sum,0); //也可以直接用 int sum[N]={0} 代替
int m;
cin>>m;
for(int i=0;i<m;i++){
cin>>temp.y>>temp.result;
v.push_back(temp);
}
sort(v.begin(),v.end(),cmp);
// 关键来了,就是求挂科前缀和
for(int i=1;i<=m;i++){
sum[i]=sum[i-1]+v[i-1].result;
}
int one,zero;
for(int i=1;i<=m;i++){
temp.y=v[i-1].y;
if(s.count(temp.y)) continue;
s.insert(temp.y);
one=sum[m]-sum[i-1];
zero=i-1-sum[i-1];
temp.result=one+zero;
if(temp.result>=best_num){
best_y=temp.y;
best_num=temp.result;
}
}
cout<<best_y<<endl;
return 0;
}
最新文章
- AngularJs的UI组件ui-Bootstrap分享(十一)——Typeahead
- android activity改变另一个activity ui
- day04关于MySqL&mdash;Android小白的学习笔记
- Mac OS 文件、文件夹重命名的方法
- python 多线程 笔记(一)
- POJ 1466 Girls and Boys 黑白染色 + 二分匹配 (最大独立集) 好题
- poj -3262 Protecting the Flowers (贪心)
- No Hibernate Session bound to thread, and configuration does not allow creat
- Using Live555 to Stream Live Video from an IP camera connected to an H264 encoder
- android 47 service绑定
- nginx配置文件中的location详解
- spring事务不会进行回滚的情况
- [转载] Java NIO教程
- XMPP系列(六)---创建群组
- ExtJS:文件上传实例
- Windows Internals 笔记——线程
- 我是如何用redis做实时订阅推送的
- Logstash使用介绍
- Python框架学习之Flask中的常用扩展包
- Android补间动画、帧动画和属性动画使用知识介绍
热门文章
- Asp.net中web.config配置文件最全面详解 (转载至CSDN)
- didi-笔试
- clear
- sxt_(001_002)_web简介
- 前端之Vue day07 混入、插件、elementui、Router、Vuex
- java 之 UncaughtExceptionHandler异常处理机制
- HashMap问题
- zookeeper在关闭服务时报could not find file /opt/module/zookeeper-3.5.10/zkData/zookeeper_server.pid
- bsub opts
- js单线程工作