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 ...
随机推荐
- 关于ios下录音
http://blog.csdn.net/silencetq/article/details/8447400 我是采用的AVAudioRecorder这个框架来进行录音 这个录音跟官方网站上的spea ...
- c# 数据库编程(利用DataSet 和 DataAdaper对象操作数据库--单表操作)
一.概述 前面2篇文章,介绍了使用SqlCommand对象利用sql命令来操作数据库. 这篇文章我们来介绍使用c#的DataSet 和 DataAdaper对象操作操作数据库. 先来介绍下这两个对象是 ...
- Spring连接MySQL、Oracle和SQL Server
其中applicationContext.xml的配置如下: <?xml version="1.0" encoding="UTF-8"?> < ...
- 【翻译自mos文章】当指定asm disk 为FRA时,11.2.0.3的dbua hang住
当指定asm disk 为FRA时.11.2.0.3的dbua hang住 来源于: 11.2.0.3 DBUA Hangs While Specifying ASM Disk To FRA (文档 ...
- Sqrt(x) 牛顿迭代法
为了实现sqrt(x),可以将问题看成是求解\(x^2-y=0\) ,即sqrt(y)=x: 牛顿法是求解方程的近似方法,给定初始点\((x0,f(x0))\),迭代公式为: #include < ...
- Surface,送我都不要
本文作于前几天,由于今天的突发新闻,已作了修订. Nokia的着火史 自从Elop那篇着火的平台备忘录出炉,Nokia的杯具就已经造成,唯一令人不解的就是:Elop为什么还没有被开除? 距离这个备忘录 ...
- EF 简单的 CRUD、分页 代码笔记
添加: static void Main(string[] args) { CCDBEntities ccdbContext = new CCDBEntities( ...
- QObject,有一个生存线程(慢慢体会)
moveToThread本来就是操作QObject的 比如把当前对象移到主线程里: myObject->moveToThread(QApplication::instance()-> ...
- ASP漏洞+SQL注入的入侵方法
本文就是想对装上了防火墙的主机,进行入侵攻击的大概思路小结一下. 首先当然是用扫描器对这台服务器(以下简称主机A)进行常规的扫描,得到初步的信息.再用nmap -sS IP -P0 -p 139 ,透 ...
- Eclipse中使用版本控制----Git
之前在做软件开发的过程中使用的版本控制软件大多是cvs,svn等等,这些都属于cvcs,及中央版本控制系统,其特点是存在一个中央库,开发者首先从中央库中下载代码,编辑,然后提交.很明显的一个特点就是使 ...