zoukankan      html  css  js  c++  java
  • Codeforces Round #424 Div. 2 C. Jury Marks

    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 20
    10
    
    output
    3
    
    input
    2 2
    -2000 -2000
    3998000 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.


    英语好烂啊。。

    读题目读了好久

    读完还不会写。。。。

    这道题的题解感觉思路好奇妙啊。。

    先把a数组求前缀和

    题意简化过来就是对于任意一个b[j],存在一个a[i]+初始值=b[j]

    等式变形得 初始值=b[j]-a[i]

    我们枚举a[i]

    假设b[1]等于a[i]+初始值

    然后再查找对于其余的b

    a中是否存在一个值+初始值=b

    因为要查找

    所以想到排序后二分(因为要二分所以去重)

    然后用两个STL

    binary_search:二分查找

    unique:去重

    #include<cstdio>
    #include<algorithm>
    int a[2005],b[2005];
    int main()
    {
    	int n,m;
    	scanf("%d %d",&n,&m);
    	int t;
    	for(int i=1;i<=n;i++)			scanf("%d",&t),		a[i]=a[i-1]+t;
    	std::sort(a+1,a+1+n);
    	 n=std::unique(a+1,a+1+n)-a-1;
    	for(int i=1;i<=m;i++)	scanf("%d",&b[i]);
    	int ans=n;
    	for(int i=1;i<=n;i++)
    	{
    		int chu=b[1]-a[i];
    		for(int j=2;j<=m;j++)
    		if(!std::binary_search(a+1,a+n+1,b[j]-chu))
    		{
    			ans--;
    			break;
    		}
    	}
    	printf("%d
    ",ans);
    	return 0;
    }

  • 相关阅读:
    原码、反码、补码,计算机中负数的表示
    [转]Vue 2.0——渐进式前端解决方案
    关于MySQL的tinyint(3)问题
    js对象的深拷贝及其的几种方法
    深入 js 深拷贝对象
    JS 数组克隆方法总结
    Undefined class constant 'MYSQL_ATTR_INIT_COMMAND'
    邮件措辞小计
    Forbidden You don't have permission to access / on this server PHP
    正则表达式
  • 原文地址:https://www.cnblogs.com/Brian551/p/7352995.html
Copyright © 2011-2022 走看看