202012-1 期末预测之安全指数
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
#ifdef debug
freopen("test.in", "r", stdin);
#endif
int n,w,s;
cin>>n;
ll sum=0;
for(int i=0;i<n;++i){
cin>>w>>s;
sum += w*s;
}
cout << ((sum > 0)?sum:0);
}
202012-2 期末预测之最佳阈值
![在这里插入图片描述](https://img-blog.csdnimg.cn/5b251a6b4d3b45cab849eacd480862bf.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAYW50UmFpbg==,size_20,color_FFFFFF,t_70,g_se,x_16)
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5+5 ;
struct Predict{
int y;
int r;
int n0;
int n1;
Predict(int y=0,int r=0,int n0=0,int n1=0):y(y),r(r),n0(n0),n1(n1){}
void setn(int n0,int n1){
this->n0 = n0;
this->n1 = n1;
}
};
bool cmp(const Predict& a, const Predict& b)
{
return a.y < b.y;
}
Predict pred[MAXN];
int main(){
#ifdef debug
freopen("test1.in", "r", stdin);
#endif
int m,tmp=1,result = 0,maxr=0;
cin>>m;
for(int i=1;i<=m;++i){
cin>>pred[i].y>>pred[i].r;
if(pred[i].r==1) {
pred[i].setn(0,1);
} else {
pred[i].setn(1,0);
}
}
sort(pred+1,pred+m+1,cmp);
for(int i=2;i<=m;++i) {
if(pred[i].y==pred[i-1].y){
pred[tmp].n1 += pred[i].n1;
pred[tmp].n0 += pred[i].n0;
} else {
pred[++tmp].y = pred[i].y;
pred[tmp].n1 = pred[i].n1;
pred[tmp].n0 = pred[i].n0;
}
}
m = tmp;
for(int i=1;i<=m;++i){
pred[i].n0 += pred[i-1].n0;
pred[i].n1 += pred[i-1].n1;
}
for (int i=1;i<=m;++i){
tmp = pred[i-1].n0 + pred[m].n1 - pred[i-1].n1;
if (tmp>=maxr) {
maxr = tmp;
result = pred[i].y;
}
}
cout<<result;
}