Jury Marks <思维题>
来源:互联网 发布:如何评价太祖知乎 编辑:程序博客网 时间:2024/06/14 19:30
Jury Marks
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 thek judges rated the participant there weren (n ≤ k) valuesb1, 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.
The first line contains two integers k andn (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.
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).
4 1-5 5 0 2010
3
2 2-2000 -20003998000 4000000
1
The answer for the first example is 3 because initially the participant could have - 10,10 or 15 points.
In the second example there is only one correct initial score equaling to 4 002 000.
#include<cstdio>#include<cctype>#include<iostream>#include<stack>#include<map>#include<cstring>#include<string>#include<sstream>#include<queue>#include<set>using namespace std ;int main() { int k,n; while(~scanf("%d %d",&k,&n)){ int a[2005],b[2005]; set<int>num; for(int i=0;i<k;i++){ scanf("%d",&a[i]); if(i)a[i]+=a[i-1]; num.insert(a[i]);//因为法官是按顺序给分的,所以前缀和有重复的我们就可以去掉,简便方法就是丢进set集合里 } for(int i=0;i<n;i++) scanf("%d",&b[i]); int cou=0; set<int>::iterator i=num.begin(); for(;i!=num.end();i++){ int ans=0; int x=b[0]-*i;//设置任意一个值推出来的初始数 for(int j=0;j<n;j++) if(num.count(b[j]-x)){//如果在集合里能找到分数-初始数,就说明这个初始数x能够推出当前b[j] ans++; } if(ans==n){//如果当前的初始数x能够推出所有的b[j],结果cou++; cou++; // printf("%d\n",x); } } printf("%d\n",cou); } return 0 ;}
- Jury Marks <思维题>
- Codeforces Round #424 C Jury Marks 思维
- CF --- 831C Jury Marks 【思维】
- Jury Marks
- Codeforces Round #424 (Div. 2) C. Jury Marks (思维题)
- Codeforces Round #424 C. Jury Marks (思维?)
- CF831C-Jury Marks
- Codeforces831 C. Jury Marks
- C. Jury Marks
- C.Jury Marks
- CF Round #424( Div.2) C. Jury Marks 【思维+STL】
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals)-831C Jury Marks(思维)
- CodeForces 831C Jury Marks
- Codeforces 831 C Jury Marks
- codeforces 831C Jury Marks
- 【Codeforces】831C Jury Marks
- CF831C-Jury Marks(map+vector)
- Codeforces-831C Jury Marks
- 直播推流实现RTMP协议的一些注意事项
- 创建运动函数startMove(obj,attr,iTarget)
- 城市列表
- STL队列
- mysql远程访问错误:access denied for user xxxx@xxxx(using password:YES)
- Jury Marks <思维题>
- JFreeChart画图形插件的使用
- java初级开发面试题全集(下)
- 剑指Offer----二叉树的镜像
- IDEA配置github并上传项目
- 机器学习实战python版决策树以及Matplotlib注解绘制决策树
- JSP--第十三天
- Password Hacking CSU 1966
- tail