CodeForces 424 Div2 CBA题

来源:互联网 发布:大数据存储技术研究 编辑:程序博客网 时间:2024/05/17 05:05

代码中镶嵌了很多注释,E题我想用BIT,但不知道该保存写什么值

C. Jury Marks
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain number of points (may be negative, i. e. points were subtracted). Initially the participant had some score, and each the marks were one by one added to his score. It is known that the i-th jury member gave ai points.

Polycarp does not remember how many points the participant had before this k marks were given, but he remembers that among the scores announced after each of the k judges rated the participant there were n (n ≤ k) values b1, b2, ..., bn (it is guaranteed that all values bj are distinct). It is possible that Polycarp remembers not all of the scores announced, i. e. n < k. Note that the initial score wasn't announced.

Your task is to determine the number of options for the score the participant could have before the judges rated the participant.

Input

The first line contains two integers k and n (1 ≤ n ≤ k ≤ 2 000) — the number of jury members and the number of scores Polycarp remembers.

The second line contains k integers a1, a2, ..., ak ( - 2 000 ≤ ai ≤ 2 000) — jury's marks in chronological order.

The third line contains n distinct integers b1, b2, ..., bn ( - 4 000 000 ≤ bj ≤ 4 000 000) — the values of points Polycarp remembers. Note that these values are not necessarily given in chronological order.

Output

Print the number of options for the score the participant could have before the judges rated the participant. If Polycarp messes something up and there is no options, print "0" (without quotes).

Examples
input
4 1-5 5 0 2010
output
3
input
2 2-2000 -20003998000 4000000
output
1
Note

The answer for the first example is 3 because initially the participant could have  - 1010 or 15 points.

In the second example there is only one correct initial score equaling to 4 002 000.


#define _CRT_SECURE_NO_WARNINGS#include <iostream>#include <set>using namespace std;const int N = 2017;int a[N], b[N], n, k;set<int> vis, tmp, res;void solve(int x) {tmp.clear();int begin = b[1] - a[x];//一个中间得分减去前x个陪审团的打分,得到一个可能的初始分//这个中间分不建议选择b[2:n],因为约束,n可能为1。Nmaely, b[2]可能就不存在,不如样例1for (int i = 1; i <= k; ++i) {tmp.insert(begin + a[i]); //tmp保存这个可能的初始分加上陪审团打分产生的中间临时分}bool flag = true;for (int it : vis) { //增强的for循环,遍历数组,若编译器不支持,改if (tmp.find(it) == tmp.end()) { //在可能的中间得分中查找不到真实的中间得分,证明这个begin初始分impossibleflag = false;break;}}if (flag)res.insert(begin);}int main(){ios::sync_with_stdio(false);while (cin >> k >> n) {vis.clear();res.clear();for (int i = 1; i <= k; ++i) {cin >> a[i];a[i] += a[i - 1]; //原始数组变为了前缀和数组}for (int i = 1; i <= n; ++i) {cin >> b[i];vis.insert(b[i]);}for (int i = 1; i <= k; ++i)solve(i);cout << res.size() << endl;}return 0;}


虽然AB水,还是会记录一下的

A

//比赛时第26行ary[cur - 1] < ary[cur] 大于号写成了小于号,555 //what a pity! #include <cstdio>#include <algorithm>#include <cstring>const int N = 107;int ary[N];int main(){int n;while(~scanf("%d", &n)) {for(int i = 0; i < n; ++i)scanf("%d", ary + i);int st = 0;for (int cur = 1; cur < n; ++cur) {switch(st) {case 0:if (ary[cur] == ary[cur - 1])st = 1;else if (ary[cur- 1] > ary[cur]) st = 2;break;case 1:if (ary[cur - 1] < ary[cur])st = -1;else if (ary[cur - 1] > ary[cur]) st = 2;break;case 2:if (ary[cur - 1] <= ary[cur])st = -1;break;}}if (st == -1) puts("NO");else puts("YES");}return 0;}


B

#define _CRT_SECURE_NO_WARNINGS #include <cstdio>#include <algorithm>#include <cstring>#include <iostream>#include <string>using namespace std;const int N = 1007;int main(){char a[30], b[30], c[N], d[N];int pos[128];while (~scanf("%s%s%s", a, b, c)) {memset(d, 0, sizeof d);int len = strlen(c);for (int i = 0; i < 26; ++i)pos[a[i]] = i;for (int i = 0; i < len; ++i) {if ('a' <= c[i] && c[i] <= 'z')d[i] = b[pos[c[i]]];else {if ('A' <= c[i] && c[i] <= 'Z')d[i] = b[pos[c[i] + 32]] - 32;else d[i] = c[i];}}puts(d);}return 0;}





原创粉丝点击