http://codeforces.com/contest/831/problem/C

做的时候想不到,来了个暴力。

对于每个b[i],枚举每一个a[i],就有1个可能的情况。

然后用vector存起来,再判断。理论复杂度爆咋,过了综测717ms

正确的思路就是排一个序。

预处理前缀和suma_i,然后就相当于每一个数字只能选一次。从小到大排序。

从大到小排序b_i,枚举每一个suma_i,用b[1]确定一个初始值,然后跑完所有b_i,看看suma_i那里有没有就行了。

#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;
int a[], b[];
const int maxn = 8e6 + ;
map<int, bool> vis;
vector<int>vc;
int sum[];
bool cmp(int a, int b) {
return a > b;
}
void work() {
int n, k;
scanf("%d%d", &k, &n);
for (int i = ; i <= k; ++i) {
scanf("%d", a + i);
sum[i] = sum[i - ] + a[i];
vis[sum[i]] = true;
}
for (int i = ; i <= n; ++i) {
scanf("%d", b + i);
}
sort(sum + , sum + + k);
sort(b + , b + + n, cmp);
int ans = ;
for (int i = ; i <= k; ++i) {
if (i > && sum[i] == sum[i - ]) continue;
int val = b[] - sum[i];
bool flag = true;
for (int j = ; j <= n; ++j) {
if (!vis[b[j] - val]) {
flag = false;
break;
}
}
ans += flag;
}
cout << ans << endl;
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
work();
return ;
}

C. 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

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

  3. 【交互 细节题 思维题】cf1064E. Dwarves, Hats and Extrasensory Abilities

    第一次做交互真有趣……:挺好的细节思维题 This is an interactive problem. In good old times dwarves tried to develop extr ...

  4. zoj 3778 Talented Chef(思维题)

    题目 题意:一个人可以在一分钟同时进行m道菜的一个步骤,共有n道菜,每道菜各有xi个步骤,求做完的最短时间. 思路:一道很水的思维题, 根本不需要去 考虑模拟过程 以及先做那道菜(比赛的时候就是这么考 ...

  5. cf A. Inna and Pink Pony(思维题)

    题目:http://codeforces.com/contest/374/problem/A 题意:求到达边界的最小步数.. 刚开始以为是 bfs,不过数据10^6太大了,肯定不是... 一个思维题, ...

  6. ZOJ 3829 贪心 思维题

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3829 现场做这道题的时候,感觉是思维题.自己智商不够.不敢搞,想着队友智商 ...

  7. 洛谷P4643 [国家集训队]阿狸和桃子的游戏(思维题+贪心)

    思维题,好题 把每条边的边权平分到这条边的两个顶点上,之后就是个sb贪心了 正确性证明: 如果一条边的两个顶点被一个人选了,一整条边的贡献就凑齐了 如果分别被两个人选了,一作差就抵消了,相当于谁都没有 ...

  8. Codeforces831C Jury Marks

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

  9. C. Nice Garland Codeforces Round #535 (Div. 3) 思维题

    C. Nice Garland time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

随机推荐

  1. Java中String和byte[]间的 转换

    数据库的字段中使用了blob类型时,在entity中此字段可以对应为byte[] 类型,保存到数据库中时需要把传入的参数转为byte[]类型,读取的时候再通过将byte[]类型转换为String类型. ...

  2. 照片Urls

    http://img.my.csdn.net/uploads/201402/16/1392530364_7835.jpg http://img.my.csdn.net/uploads/201402/1 ...

  3. logback 相关

    %logger{36} 表示logger名字最长36个字符,否则按照句点分割. %X{key} to get the value that are stored in the MDC map ${lo ...

  4. Spring Boot 专栏

    http://blog.csdn.net/column/details/spring-boot.html?&page=2

  5. 超牛 猴子补丁,修改python内置的print

    猴子补丁一般是用于修改三方包或官方包,也可以用来修改自己或者他人的代码. 但也可以用来修改python 语言内置的关键字. 本篇博客修改python最常用的内置print,使你使用print时候,自动 ...

  6. strstr strchr strrchr strrstr

    通过函数的定义来区分: 1.strstr: 返回子串出现的第一次位置 char *strstr(const char *haystack, const char *needle) 可见,strstr函 ...

  7. cygwin运行git submodule init出错error while loading shared libraries的解决

    installing the Devel\gettext package should solve your problem. git-submodule requires that. Unfortu ...

  8. 301ReidrectPages中重复记录导致的500 server error

    在Umbraco平台开发一个系统时,遇到一个问题,报错500 server error, system is currently unable to handle this request. 按下F1 ...

  9. vue+element-ui 实现分页

    <el-table ref="multipleTable" :data="tableData.slice((currentPage-1)*pagesize,curr ...

  10. 【MYSQL】删除数据后自动增长列归0的问题

    在清空数据表后发现自动增长id列在新增数据后仍然会按照之前的顺序生成 强迫症,就是想清空数据后让id从0开始,于是百度 执行以下sql语句可以让自动增长列归0 truncate table 表名 这是 ...