C. Jury Marks 思维题
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 思维题的更多相关文章
- C. Jury Marks 思维
C. Jury Marks 这个题目虽然是只有1600,但是还是挺思维的. 有点难想. 应该可以比较快的推出的是这个肯定和前缀和有关, x x+a1 x+a1+a2 x+a1+a2+a3... x+s ...
- C. Jury Marks
C. Jury Marks time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- 【交互 细节题 思维题】cf1064E. Dwarves, Hats and Extrasensory Abilities
第一次做交互真有趣……:挺好的细节思维题 This is an interactive problem. In good old times dwarves tried to develop extr ...
- zoj 3778 Talented Chef(思维题)
题目 题意:一个人可以在一分钟同时进行m道菜的一个步骤,共有n道菜,每道菜各有xi个步骤,求做完的最短时间. 思路:一道很水的思维题, 根本不需要去 考虑模拟过程 以及先做那道菜(比赛的时候就是这么考 ...
- cf A. Inna and Pink Pony(思维题)
题目:http://codeforces.com/contest/374/problem/A 题意:求到达边界的最小步数.. 刚开始以为是 bfs,不过数据10^6太大了,肯定不是... 一个思维题, ...
- ZOJ 3829 贪心 思维题
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3829 现场做这道题的时候,感觉是思维题.自己智商不够.不敢搞,想着队友智商 ...
- 洛谷P4643 [国家集训队]阿狸和桃子的游戏(思维题+贪心)
思维题,好题 把每条边的边权平分到这条边的两个顶点上,之后就是个sb贪心了 正确性证明: 如果一条边的两个顶点被一个人选了,一整条边的贡献就凑齐了 如果分别被两个人选了,一作差就抵消了,相当于谁都没有 ...
- Codeforces831C Jury Marks
C. Jury Marks time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- 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 ...
随机推荐
- 洛谷【P1480】A/B Problem
题目传送门:https://www.luogu.org/problemnew/show/P1480 高精除低精板子题,灵性地回忆一下小学时期列竖式的草稿纸即可. 时间复杂度:\(O(len)\) 空间 ...
- Excel对重复数据分组,求出不同的数据(office 2013)
第一步: 第二步: 第三步:
- js基础之变量类型
1.NAN(Not a number) 不是一个数字 自身:console.log(NaN==NaN)和console.log(NaN===NaN)返回值都是false; 其他函数,isNaN()可用 ...
- rails常用命令示例
数据迁移命令 1.一下命令执行后会在db\migrate下产生同名数据迁移文件(文件内容可自行修改,基本语法见“数据迁移文件”部分) 创建model:rails generate model user ...
- oracle--事物---
一.什么是事务 事务用于保证数据的一致性,它由一组相关的dml语句组成,该组的dml(数据操作语言,增删改,没有查询)语句要么全部成功,要么全部失败. 如:网上转账就是典型的要用事务来处理,用于保证数 ...
- SpringBoot02 Controller的使用、数据库操作、事物管理、修改banner
1 Controller的使用 特点:编程技巧和SpringMVC几乎完全一样 注意:@RestController = @Controller + @ResponseBody 注意:读取路径参数和请 ...
- 9、linux的特殊符
在shell中常用的特殊符号罗列如下: # ; ;; . , / \ 'string'| ! $ ${} $? ...
- JAVA之J2EE学习路线
摘自:http://blog.csdn.net/hsc456/article/details/51970559 历经2,3个月,终于学完了J2EE的方方面面,虽然还是一知半解,好歹也算是整条路都走 ...
- php小块代码
//页面本身网址 "http://".$_SERVER["HTTP_HOST"].preg_replace("/[^\/]+$/",&quo ...
- Dreamweaver Flash Photoshop网页设计综合应用 (智云科技) [iso] 1.86G
全书共15章,主要包括网页制作基础.Dreamweaver CC网页制作.Photoshop CC网页图像设计.Flash CC网页动画设计以及综合案例实战5个部分.通过本书的学习,不仅能让读者学会三 ...