Codeforces
来源:互联网 发布:浙江省纺织品出口数据 编辑:程序博客网 时间:2024/05/29 12:30
C. Jury Marks
题目链接
分类:暴力、二分
1.题意概述
- 某人昨晚看一场比赛选手比完以后有
k 位评委依次(根据时间轴顺序)打分为a1,a2,...ak ,这个人还记得某些时刻这个选手的当前分数为b1,b2,...,bn (不是按时间轴顺序给出),现在问你这个选手初始积分有多少几种情况? - 数据范围:
1 ≤ n ≤ k ≤ 2 000 、2 000 ≤ ai ≤ 2 000 、4 000 000 ≤ bj ≤ 4 000 000
2.解题思路
- 因为
a[1...k] 是按时间顺序给的,我们无法改变,因此不妨先求一下前缀和sum[1...k] ,我们不关心具体初始积分是多少,就关心合法性,假设初始积分b[0] ,那么b[1]=b[0]+sum[i] 肯定成立,我们考虑枚举这个i。我们把sum[i] 去重以后,假设有cnt种前缀和,那么ans的最大值就是cnt,但是可能这cnt种有一些对于后续的b[2...n] 不合法。如何检验合法性呢?那就考虑后续每一个b是否能找到对于的sum,换句话说就是对每个b[j],2≤j≤n 是否有b[j]=b[0]+sum[l] 成立,我们考虑将sum排序,然后去二分[1] 地查找它,这样总的复杂度就是O(n2logk) !- STL的binary_search:在具有一定单调性的片段中查找某个值,如果存在则返回真,否则返回假。
3.AC代码
#include <bits/stdc++.h>#define INF 0x3f3f3f3f#define maxn 100010#define lson root << 1#define rson root << 1 | 1#define lent (t[root].r - t[root].l + 1)#define lenl (t[lson].r - t[lson].l + 1)#define lenr (t[rson].r - t[rson].l + 1)#define N 2020#define eps 1e-6#define pi acos(-1.0)#define e exp(1.0)#define Close() ios::sync_with_stdio(0),cin.tie(0)using namespace std;const int mod = 1e9 + 7;typedef long long ll;typedef unsigned long long ull;int a[N], b[N];ll sum[N];int main(){#ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); long _begin_time = clock();#endif int n, k; scanf("%d%d", &k, &n); sum[0] = 0; for (int i = 1; i <= k; i++) { scanf("%d", &a[i]); sum[i] = sum[i - 1] + a[i]; } for (int i = 1; i <= n; i++) scanf("%d", &b[i]); sort(sum + 1, sum + k + 1); int sz = unique(sum + 1, sum + k + 1) - sum - 1; int cnt = sz; for (int i = 1; i <= sz; i++) { int initial = b[1] - sum[i]; for (int j = 1; j <= n; j++) { if (!binary_search(sum + 1, sum + sz + 1, b[j] - initial)) { cnt--; break; } } } printf("%d\n", cnt);#ifndef ONLINE_JUDGE long _end_time = clock(); printf("time = %ld ms.", _end_time - _begin_time);#endif return 0;}
阅读全文
0 0
- codeforces~~~
- Codeforces
- codeforces
- Codeforces
- codeforces
- codeforces
- Codeforces
- Codeforces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Codeforces Round #423 (Div. 1, rated, based on VK Cup Finals) D. Best Edge Weight(最小生成树+LCA+树链剖分)
- Python-matplotlib基本操作
- 冒泡排序
- git clone出现fatal: unable to access 'https://': SSL certificate problem: self signed certificate in
- linux C 读二进制文件和文件读取
- Codeforces
- 学习笔记之思路整理
- 常见乱码的解决方式
- Jquery post 传递单个和多个数组方法 asp.net mvc
- rk3288 拨打电话,来电唤醒
- 如何去除ListView中Header View、Footer View中的分割线
- Android5.0中的水波纹效果
- spring介绍
- 如何理解并正确使用MySQL 索引