题目链接:http://codeforces.com/problemset/problem/831/C

题意:有一位参赛选手,我们不知道他初始或最后的成绩,但是知道k次评审所加(减)的分数,以及n个在这过程中的他的分数。问这名选手初始分有几种情况。

思路:一开始考虑先求出评审分的前缀和,对过程分减去前缀和就能得到的初始分数,求出所有的初始分数情况,用map记录每个初始分重复的次数,重复次数==n 的即为正确的初始分。

然而这么做是WA了的。

分析第一个样例:

4 1
-5 5 0 20
10 如果按照上面的思路,输出答案是2。由于前缀和为0存在重复,使得10这个初始分重复了2次。
那么我们就需要去除重复的前缀和。
再来思考一下这种做法的正确性:由于前缀和都是不相等的,也就能说明对一个过程分,会产生不同的初始分数,那么对于一个初始分数,其中一个过程分是唯一的(一一对应),当这个初始分存在k个不同的初始分数时它必定是正确的

AC代码:

#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#include<algorithm>
using namespace std;
typedef long long LL;
const int MAXN=;
int sum[MAXN],a,b;
bool vis[MAXN];
int main()
{
int k,n;
sum[]=;
cin>>k>>n;
memset(vis, , sizeof(vis));
map<int,int> mp;
map<int,int>::iterator it;
for(int i=;i<=k;i++){
scanf("%d", &a);
sum[i]=sum[i-]+a;
}
sort(sum+, sum+k+);
for(int i=;i<=k;i++){
if(sum[i]==sum[i-])
vis[i]=;
}
for(int i=;i<=n;i++){
scanf("%d", &b);
for(int j=;j<=k;j++){
if(vis[j])
continue;
mp[b-sum[j]]++;
//cout<<b-sum[j]<<endl;
}
}
int res=;
for(it=mp.begin();it!=mp.end();it++){
if(it->second==n)
res++;
}
printf("%d\n", res);
return ;
}

Codeforces 831C--Jury Marks (思维)的更多相关文章

  1. C. Jury Marks 思维

    C. Jury Marks 这个题目虽然是只有1600,但是还是挺思维的. 有点难想. 应该可以比较快的推出的是这个肯定和前缀和有关, x x+a1 x+a1+a2 x+a1+a2+a3... x+s ...

  2. C. Jury Marks 思维题

    http://codeforces.com/contest/831/problem/C 做的时候想不到,来了个暴力. 对于每个b[i],枚举每一个a[i],就有1个可能的情况. 然后用vector存起 ...

  3. C. Jury Marks

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

  4. Codeforces831C Jury Marks

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

  5. CodeForces 540B School Marks(思维)

    B. School Marks time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  6. 【Codeforces Round #424 (Div. 2) C】Jury Marks

    [Link]:http://codeforces.com/contest/831/problem/C [Description] 有一个人参加一个比赛; 他一开始有一个初始分数x; 有k个评委要依次对 ...

  7. #424 Div2 Problem C Jury Marks (二分 && 暴力 && std::unique && 思维)

    题目链接 :http://codeforces.com/contest/831/problem/C 题意 :选手有一个初始积分,接下来有k个裁判为他加分或减分(时间顺序给出),然后告诉你n(1< ...

  8. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem C (Codeforces 831C) - 暴力 - 二分法

    Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain ...

  9. Educational Codeforces Round 60 C 思维 + 二分

    https://codeforces.com/contest/1117/problem/C 题意 在一个二维坐标轴上给你一个起点一个终点(x,y<=1e9),然后给你一串字符串代表每一秒的风向, ...

  10. Educational Codeforces Round 61 F 思维 + 区间dp

    https://codeforces.com/contest/1132/problem/F 思维 + 区间dp 题意 给一个长度为n的字符串(<=500),每次选择消去字符,连续相同的字符可以同 ...

随机推荐

  1. python杂谈

    1.for循环过界保护 例如: a=len([1,2,3]) for i in range(a): for j in range(i+1:a) print(i,j) 不会报错 2.python集合和列 ...

  2. Web控件LinkButton

    <asp:LinkButton ID="" runat="server" ></asp:LinkButton> 编译后就变成了回发事件 ...

  3. 21.线程,全局解释器锁(GIL)

    import time from threading import Thread from multiprocessing import Process #计数的方式消耗系统资源 def two_hu ...

  4. .Net core 2.0 利用Attribute获取MVC Action来生成菜单

    最近在学习.net core的同时将老师的MVC5项目中的模块搬过来用,其中有一块就是利用Attribute来生成菜单. 一·首先定义Action实体 /// <summary> /// ...

  5. jsp(java server page)

    jsp的组成元素; 1, 指令 page指令 <%@ page ..........%> language---当前页面使用的语言:java import---当前页面引入的类库, 默认是 ...

  6. 基于vux的Vue路由切换动画

    const history = window.sessionStorage history.clear() let historyCount = history.getItem('count') * ...

  7. securecrt(CRT)导入会话

    securecrt是个非常流行的远程管理维护工具,支持fssh.ssh2.telnet等多种协议,也支持中文.设备管理多了,自行手工添加也是很累的活.偷下懒,从别人那复制下文件,倒入到自己的secur ...

  8. [Codeforces 316E3]Summer Homework(线段树+斐波那契数列)

    [Codeforces 316E3]Summer Homework(线段树+斐波那契数列) 顺便安利一下这个博客,给了我很大启发(https://gaisaiyuno.github.io/) 题面 有 ...

  9. 问题处理——"无法导航到插入符号下的符号"

    最近编码时经常发现"转到定义"功能没法用了,代码一片灰.刚开始时重新编译一下项目或重启一下VS就恢复了,但到后面这两种方法都不管用了. 偶然下发现解决方案中很多项目的引用都出现了黄 ...

  10. JS高级 —— 普通函数、构造函数、对象方法的调用

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...