AcWing 3298. 期末预测之最佳阈值
原题链接
中等
作者:
ちょっとジョーンソース
,
2021-03-15 16:59:14
,
所有人可见
,
阅读 1362
此题解来源于y总tql
C++ 代码
#include <iostream>
#include <cstring>
#include <algorithm>
#define x first
#define y second
using namespace std;
typedef pair<int, int> PII;
const int N = 100010;
int n;
PII q[N];
int s[2][N];
int main()
{
scanf("%d", &n);
for (int i = 1; i <= n; i ++ ) scanf("%d%d", &q[i].x, &q[i].y);
sort(q + 1, q + n + 1);
for (int i = 1; i <= n; i ++ )
for (int j = 0; j < 2; j ++ )
s[j][i] = s[j][i - 1] + (j == q[i].y);
int cnt = -1, res;
for (int i = 1; i <= n; i ++ )
{
int j = i;
while (j + 1 <= n && q[j + 1].x == q[i].x) j ++ ;
int t = s[0][i - 1] + s[1][n] - s[1][i - 1];
if (t >= cnt) cnt = t, res = q[i].x;
i = j;
}
printf("%d\n", res);
return 0;
}
作者:yxc
链接:https://www.acwing.com/file_system/file/content/whole/index/content/1955821/
来源:AcWing
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。