题目链接: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. AppiumLibrary库倒入后显示红色,日志报错:ImportError: cannot import name 'InvalidArgumentException'

    AppiumLibrary安装后,robotframe worke 倒入后一直显示红色,查看日志报错:ImportError: cannot import name 'InvalidArgumentE ...

  2. SqlSession 内部运行

    <深入浅出MyBatis技术原理与实战>p150页 SqlSession内部运行图 四大对象在流程中的操作. 1.准备sql.StatementHandler 的prepare方法进行sq ...

  3. EntityFramework经典数据访问层基类——增删改查

    namespace StudentSys.DAL { public class BaseService<T>:IDisposable where T:BaseEntity,new() { ...

  4. 远控CVE整理

    Windows: CVE-2017-8464(通过快捷方式,可U盘/共享等途径传播)

  5. response.getWriter()和jsp中的out对象的区别

    (1) out和response.getWriter属于的类不同,前者是JspWriter,后者是java.io.PrintWriter.而JspWriter是一个抽象类, PrintWriter是一 ...

  6. Map2

    map增加和更新: map["key"] = value //如果key还没有,就是增加,如果key存在就是修改 案例演示: func main() { cities := mak ...

  7. maven配置本地仓库、maven配置阿里中央仓库、eclipse配置maven

    一.maven配置本地仓库路径 1.打开下载好的maven目录 (若没安装,可以看我写的安装步骤https://www.cnblogs.com/xjd-6/p/11344719.html) 2.进入c ...

  8. ApplicationContextAware 快速获取bean

    在Web应用中,Spring容器通常采用声明式方式配置产生:开发者只要在web.xml中配置一个Listener,该Listener将会负责初始化Spring容器,MVC框架可以直接调用Spring容 ...

  9. 解决Ubuntu12.04下rpcbind: cannot open '/var/run/rpcbind/rpcbind.xdr' file for reading

    不知道怎么回事,实验室的电脑在同学搞过之后,每次启动都报错 rpcbind: cannot open '/run/rpcbind/rpcbind.xdr' file for reading, errn ...

  10. [ARC083]Collecting Balls

    Description 有一个 \(n\times n\) 的矩阵,矩阵内有 \(2n\) 个球.对于 \(i \in [1,n]\) ,\((0,i) (i,0)\) 的位置各有一个启动后往右走/往 ...