CSU-ACM2017暑期训练1-Debug与STL Jury Marks-set判重
2017-07-24 20:14
477 查看
题目:
Polycarp watched TV-show wherek jury
members one by one rated aparticipant 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 thei-th
jury member gave ai points.
Polycarp does not remember how many points the participant hadbefore this k marks
were given, but he remembers that among the scoresannounced after each of thek judges
rated the participant there were n (n ≤ k)
values b1, b2, ..., bn (it
is guaranteed that allvalues bj are
distinct). It ispossible 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 scorethe participant could have before the judges rated the participant.
Input
The first line contains two integersk and n (1 ≤ n ≤ k ≤ 2 000)
—the number of jury members and the number of scores Polycarp remembers.
The second line containsk integers a1, a2, ..., ak ( - 2 000 ≤ ai ≤ 2 000)
— jury's marks in chronological order.
The third line containsndistinct integers b1, b2, ..., bn ( - 4 000 000 ≤ bj ≤ 4 000 000)
— the values of points Polycarp remembers. Note that thesevalues are not necessarily given in chronological order.
Output
Print the number of options for the score the participant could have before thejudges rated the participant. If Polycarp
messes something up and there is nooptions, print "0"(without
quotes).
Examples
Input
4 1
-5 5 0 20
10
Output
3
Input
2 2
-2000 -2000
3998000 4000000
Output
1
Note
The answer for the first example is3 because
initially the participantcould have - 10,10 or 15 points.
In the second example there is only one correct initial score equaling to4 002 000.
C. Jury Marks
time limit per test 2
seconds
memory limit per test 256
megabytes
members one by one rated aparticipant 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 thei-th
jury member gave ai points.
Polycarp does not remember how many points the participant hadbefore this k marks
were given, but he remembers that among the scoresannounced after each of thek judges
rated the participant there were n (n ≤ k)
values b1, b2, ..., bn (it
is guaranteed that allvalues bj are
distinct). It ispossible 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 scorethe participant could have before the judges rated the participant.
Input
The first line contains two integersk and n (1 ≤ n ≤ k ≤ 2 000)
—the number of jury members and the number of scores Polycarp remembers.
The second line containsk integers a1, a2, ..., ak ( - 2 000 ≤ ai ≤ 2 000)
— jury's marks in chronological order.
The third line containsndistinct integers b1, b2, ..., bn ( - 4 000 000 ≤ bj ≤ 4 000 000)
— the values of points Polycarp remembers. Note that thesevalues are not necessarily given in chronological order.
Output
Print the number of options for the score the participant could have before thejudges rated the participant. If Polycarp
messes something up and there is nooptions, print "0"(without
quotes).
Examples
Input
4 1
-5 5 0 20
10
Output
3
Input
2 2
-2000 -2000
3998000 4000000
Output
1
Note
The answer for the first example is3 because
initially the participantcould have - 10,10 or 15 points.
In the second example there is only one correct initial score equaling to4 002 000.
题目大意:
给你一串评委给打的分,再给你一串中间分值(由初始分值加上某前一段评委打的分算得),问你初始分值有多少种可能?
思路:
随便取一个中间分值,与所有的评委打分的时间点枚举算初始分,再用set判重法来判断这个初始分数能不能满足其他的中间分值,注意判断所得初始分结果有没有重复。因为由一个中间分值和各个节点枚举出来的初始分可能重复。
代码:
#include <iostream> #include <cstdio> #include <cstring> #include <set> using namespace std; int n,k,sco,ans; int a[2222],b[2222]; set<int>s; set<int>score; int judge(int t) { s.erase(s.begin(),s.end()); for(int i=0;i<k;i++) { s.insert(sco+a[i]); } for(int i=0;i<n;i++) { if(s.find(b[i])==s.end()) return 0; } return 1; } int main() { while(scanf("%d%d",&k,&n)!=EOF) { score.erase(score.begin(),score.end()); ans=0; for(int i=0;i<k;i++) { scanf("%d",&a[i]); if(i) a[i]+=a[i-1]; } for(int i=0;i<n;i++) { scanf("%d",&b[i]); } for(int i=0;i<k;i++) { sco=b[0]-a[i]; if(score.find(sco)==score.end()&&judge(i)) { score.insert(sco); ans++; } } printf("%d\n",ans); } return 0; }
相关文章推荐
- CSU-ACM2017暑期训练1-Debug与STL E - Train Problem I
- CSU-ACM2017暑期训练1-Debug与STL C - Languages
- Train Problem I CSU-ACM2017暑期训练1-Debug与STL
- CSU-ACM2017暑期训练1-Debug与STL hdu2736 - Surprising Strings
- CSU-ACM2017暑期训练1-Debug与STL C-Languages-map判重
- CSU-ACM2017暑期训练1-Debug与STL hdu1896-Stones
- CSU-ACM2017暑期训练1-Debug与STL hdu1022-Train Problem I
- CSU-ACM2017暑期训练1-Debug与STL -圆桌问题
- Languages--CSU-ACM2017暑期训练1-Debug与STL
- CSU-ACM2017暑期训练1-Debug与STL B - Jury Marks
- CSU-ACM2017暑期训练1-Debug与STL A - Surprising Strings
- CSU-ACM2017暑期训练3 J - Non-boring sequences UVA - 1608
- CSU-ACM2017暑期训练12-KMP D - 匹配
- CSU-ACM2017暑期训练16-树状数组 F - Matrix Sum HihoCoder - 1336
- CSU-ACM2017暑期训练3-递推与递归I - Erratic Expansion UVA - 12627
- CSU-ACM2017暑期训练4-dfs H- Square HDU - 1518
- CSU-ACM2017暑期训练5-三分 E - Line belt
- CSU-ACM2017暑期训练6-bfs H - ACM小组的古怪象棋 CSU - 1224
- CSU-ACM2017暑期训练7-模拟&&贪心A - Radar Installation
- CSU-ACM2017暑期训练7-模拟&&贪心 E - 荷马史诗 HYSBZ - 4198