F-Kobolds and Catacombs
题意:对于\(n(n<=10^6)\)个数的序列,划分区间,每个区间内部从小到大排序,要求最后整个序列单调不下降,求最多可以划分为多少个区间。
分析:分别计算原始序列的前缀和,原始序列sort从小到大排序之后的前缀和,每两个前缀和相等的下标之间可以划分为一个区间,即答案就是前缀和相等的下标个数。
#include<bits/stdc++.h>
#define ll long long
using namespace std;
inline int read() {
char ch = getchar(); int x = 0, f = 1;
while (ch < '0' || ch>'9') { if (ch == '-') f = -1; ch = getchar(); }
while ('0' <= ch && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
return x * f;
}
const int N=1e6+5;
const int M=8e3+5;
const int mod=998244353;
ll sum1[N],sum2[N];
int a[N];
int main(){
int n=read();
for(int i=1;i<=n;++i){
a[i]=read();
sum1[i]=sum1[i-1]+a[i];
}
sort(a+1,a+n+1);
for(int i=1;i<=n;++i)sum2[i]=sum2[i-1]+a[i];
int ans=0;
for(int i=1;i<=n;++i){
if(sum1[i]==sum2[i])++ans;
}
cout<<ans<<endl;
return 0;
}
G-The Witchwood
题意:给定n个数,求最大的k个数之和。
分析:签到题,应该要开long long。
K-Scholomance Academy
题意:直接看这篇博客了解混淆矩阵、ROC曲线、AUC指标,就能看懂题目了,而且看懂题意,这道题就十分简单。
分析:我们要求的就是ROC曲线下方的面积。对于每个样本,题目中的'+'就是阳性,'-'就是阴性,当前阈值大于等于某样本的数值时,该样本判定为阳性,否则判定为阴性,因此会出现真阳TP、假阴FN、真阴TN、假阳FP四种情况。把两个样本分开并分别从小到大排序,根据阳性样本的值,让阈值递增,在每两个阳性样本之间阈值变化,TP不变,因此TPR也不变,即ROC曲线的纵坐标不变,而且很好求;现在只要考虑每两个阳性样本之间,FPR的变化范围,也就是ROC曲线横坐标的区间。阴性样本中数值越大的越容易假阳,因此随着阈值增大假阳样本数量递减,设置一个指针指向阴性样本的数组,阈值变化时,更新指针右移。
#include<bits/stdc++.h>
#define ll long long
using namespace std;
inline int read() {
char ch = getchar(); int x = 0, f = 1;
while (ch < '0' || ch>'9') { if (ch == '-') f = -1; ch = getchar(); }
while ('0' <= ch && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
return x * f;
}
const int N = 1e6 + 5;
const int M = 8e3 + 5;
const int mod = 998244353;
int n, pos[N], neg[N];
int main() {
cin>>n;
for (int i = 1; i <= n; ++i) {
char ch; cin >> ch;
int val;cin>>val;
if (ch == '+')pos[++pos[0]] = val;
else neg[++neg[0]] = val;
}
sort(pos + 1, pos + pos[0] + 1);
sort(neg + 1, neg + neg[0] + 1);
int now_tp = pos[0], now_fp = neg[0];
long double ans = 0.0, now_tpr = 1.0, now_fpr = 1.0;
int j = 1;
for (int i = 1; i <= pos[0]; ++i) {
while (j <= neg[0] && neg[j] < pos[i])++j;
long double r = now_fpr;
now_fp = neg[0] - j + 1; now_fpr = (long double)1.0 * now_fp / neg[0];
ans += (long double)(r - now_fpr) * now_tpr;
now_tp--; now_tpr = (long double)1.0 * now_tp / pos[0];
}
printf("%.12Lf\n", ans);
return 0;
}