hdu 5138
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <stack>
#include <cctype>
#include <string>
#include <malloc.h>
#include <queue>
#include <map>
#include <set> using namespace std; const int INF = 0xffffff;
const double esp = 10e-;
const double Pi = * atan(1.0);
const int maxn = + ;
const long long mod = ;
const int dr[] = {,,-,,-,,-,};
const int dc[] = {,,,-,,-,-,};
typedef long long LL; LL gac(LL a,LL b){
return b?gac(b,a%b):a;
}
const int hashtable = ;
struct Hash{
int head[hashtable];
int _next[maxn];
long long state[maxn];
int cnt;
void init(){
cnt = ;
memset(head,,sizeof(head));
}
bool _find(LL s){
int h = (s % hashtable+hashtable)%hashtable;
int u = head[h];
while(u){
if(s == state[u])
return ;
u = _next[u];
}
return ;
}
bool try_to_insert(LL s){
int h = (s % hashtable+hashtable)%hashtable;
_next[cnt] = head[h];
state[cnt] = s;
head[h] = cnt;
cnt++;
return ;
} };
Hash H1,H2;
inline LL read()
{
char ch=getchar();LL x=,f=;
while(ch>''||ch<''){if(ch=='-')f=-;ch=getchar();}
while(ch<=''&&ch>=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
LL a[maxn];
int main()
{
#ifndef ONLINE_JUDGE
freopen("inpt.txt","r",stdin);
// freopen("output.txt","w",stdout);
#endif
int t;
scanf("%d",&t);
for(int cas = ;cas <= t;cas++){
int n,k;
scanf("%d%d",&n,&k);
H1.init();
H2.init();
LL sum = ;
bool ok = ;
H1.try_to_insert();
H2.try_to_insert();
for(int i = ;i < n;i++){
a[i] = read();
}
for(int i = n-;i > - && !ok;i--){
if(ok)
continue;
if(i % == ){
sum -= a[i];
if(H2._find(-sum-k)){
ok = ;
}
}
else{
sum += a[i];
if(H1._find(sum-k)){
ok = ;
}
}
H1.try_to_insert(sum);
H2.try_to_insert(-sum);
}
printf("Case #%d: %s.\n",cas,ok?"Yes":"No");
}
return ;
}
hdu 5138的更多相关文章
- hdu 5138(水题)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5138 反着来. #include<iostream> #include<cstdi ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
- hdu 4481 Time travel(高斯求期望)(转)
(转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...
- HDU 3791二叉搜索树解题(解题报告)
1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...
随机推荐
- (Problem 9)Special Pythagorean triplet
A Pythagorean triplet is a set of three natural numbers, a b c, for which, a2 + b2 = c2 For exampl ...
- cocos2dx进阶学习之CCApplication
继承关系 CCApplication-> CCApplicationProtocol 类主要成员变量 static CCApplication * sm_pSharedApplication; ...
- Linux下的在线播放神器
Linux下的在线播放神器:一个是Amarok缺点是,每个音乐源都要更新后才能播放. 在一个就是中国造的:linux deepin下的深度音乐,缺点就是连不上.反正我是连不上
- im 编辑命令总结
一. VIM高亮 进入vim后,在普通模式下输入如下命令,开启php代码高亮显示 :syntax enable :source $VIMRUNTIME/syntax/php.vim 二. ...
- BON取代半岛电视,美国人要“换口味”了吗?
记得很久以前唐骏在某高校演讲时,讲了这么一个笑话,他问一位美国最普通的大妈,“请你说出三个印象最深刻的中国城市”,在北京奥运会之前,这位大妈说了如下三个城市:北京.香港.新加坡.很显然,这位大 ...
- c: c代码书写规范
排版: 较长的语句或函数过程参数(>80字符)要分成多行书写, 长表达式要在低优先级操作符处划分新行,操作符放在新行之首, 划分出的新行要进行适当的缩进,使排版整齐,语句可读 参考: 1. 运算 ...
- 04-UIKit(UINavigationController、NSAttributeString、UIImageView)
目录: 一.UINavigationController导航视图控制器 二.NSAttributeString属性字符串 三.UIImageView图像处理 回到顶部 一.UINavigationCo ...
- Windows Service的官方描述,抄下来(不写obj就是LocalSystem)
How to create a Windows service by using Sc.exe Email Print Support for Windows XP has ended Micro ...
- IntelliJ IDEA 开发swing(一)
原文:idea开发swing(一) 最近项目组需要开发一个swing小工具,以下是开发过程. 一.创建工程: 输入工程名称,选择java module,点击next 接下来什么都不选点击finish, ...
- 重设mysql数据库root用户密码
原文:http://blog.sina.com.cn/s/blog_a3695da601010mrs.html 1, 启用任务管理器,结束mysql进程 2,进入命令行,进入mysql的bi ...