[hdu P4334] Trouble
[hdu P4334] Trouble
The 5-sum problem is defined as follows: Given 5 sets S_1,...,S_5 of n integer numbers each, is there a_1 in S_1,...,a_5 in S_5 such that a_1+...+a_5=0?
InputFirst line of input contains a single integer N (1≤N≤50). N test-cases follow. First line of each test-case contains a single integer n (1<=n<=200). 5 lines follow each containing n integer numbers in range [-10^15, 1 0^15]. I-th line denotes set S_i for 1<=i<=5.OutputFor each test-case output "Yes" (without quotes) if there are a_1 in S_1,...,a_5 in S_5 such that a_1+...+a_5=0, otherwise output "No".Sample Input
2 2 1 -1 1 -1 1 -1 1 -1 1 -1 3 1 2 3 -1 -2 -3 4 5 6 -1 3 2 -4 -10 -1
Sample Output
No Yes
第一次手写Hash表。。。只不过跑的有点慢。。。
发现hash最常用的还是用邻接表挂链。。其实还蛮好写的,只是以前没写过而已。
code:
(第一次写class)
%:pragma GCC optimize()
#include<bits/stdc++.h>
#define LL long long
#define r register
#define Ms(a,x) memset(a,x,sizeof a)
using namespace std;
;
][N],sum;
class Hashmap {
private:
#define p 2040803
LL lnk[p+],son[N*N]; int nxt[N*N],tot;
public:
),Ms(nxt,-),tot=;}
void insert(LL x) {
LL k=x%p; ) k+=p;
) {lnk[k]=++tot,son[tot]=x; return;}
for (r int j=lnk[k]; ; j=nxt[j])
) {nxt[j]=++tot,son[j]=x; return;}
}
bool find(LL x) {
LL k=x%p; ) k+=p;
;
;
}
}app;
inline LL read() {
LL x=,f=; char ch=getchar();
:,ch=getchar();
+ch-',ch=getchar();
return x*f;
}
int main() {
for (int T=read(); T; T--) {
n=read(),app.clear();
; i<=; i++)
; j<=n; j++) a[i][j]=read();
; i<=n; i++)
; j<=n; j++)
sum=-(a[][i]+a[][j]),app.insert(sum);
;
; i<=n&&!tag; i++)
; j<=n&&!tag; j++)
; k<=n&&!tag; k++) {
sum=a[][i]+a[][j]+a[][k];
;
}
printf("%s\n",tag?"Yes":"No");
}
;
}
[hdu P4334] Trouble的更多相关文章
- HDU 4334 Trouble (暴力)
Trouble Time Limit: 5000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u Submit Statu ...
- HDU 4334 Trouble
Trouble Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- HDU 4334 Trouble (数组合并)
Trouble Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- HDU 4334——Trouble——————【贪心&水题】
Trouble Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- HDU 4334 Trouble(哈希|线性查找)
给定五个集合.问是否能从五个集合各取一个元素,使得元素之和为0. 这道题有两种做法,一种是哈希,然而之前没写过哈希.....比赛后从大神那copy了一份. 这里说还有一种. 对于这五个集合分为三组.1 ...
- hdu 3591 The trouble of Xiaoqian
hdu 3591 The trouble of Xiaoqian 题意:xiaoqi要买一个T元的东西,当前的货币有N种,xiaoqi对于每种货币有Ci个:题中定义了最小数量即xiaoqi拿去买东西 ...
- HDU 3591 The trouble of Xiaoqian(多重背包+全然背包)
HDU 3591 The trouble of Xiaoqian(多重背包+全然背包) pid=3591">http://acm.hdu.edu.cn/showproblem.php? ...
- Trouble HDU - 4334
Hassan is in trouble. His mathematics teacher has given him a very difficult problem called 5-sum. P ...
- HDU 3594 The trouble of Xiaoqian 混合背包问题
The trouble of Xiaoqian Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...
随机推荐
- (转)spring中的拦截器(HandlerInterceptor+MethodInterceptor)
1. 过滤器跟拦截器的区别 在说拦截器之前,不得不说一下过滤器,有时候往往被这两个词搞的头大. 其实我们最先接触的就是过滤器,还记得web.xml中配置的<filter>吗~ 你应该知道 ...
- java框架之SpringBoot(7)-异常处理
前言 在 SpringBoot 项目中,默认情况下,使用浏览器访问一个不存在的地址会返回如下错误页面: 而当客户端未非浏览器时,错误信息则会以 json 数据返回,如下: 会出现如上效果的原因是 Sp ...
- 为什么mysql事务回滚后, 自增ID依然自增
事务回滚后,自增ID仍然增加,回滚后,自增ID仍然增加.比如当前ID是7,插入一条数据后,又回滚了.然后你再插入一条数据,此时插入成功,这时候你的ID不是8,而是9.因为虽然你之前插入回滚,但是ID还 ...
- 创建视图sql
create view 视图名称 as 查询sql语句create view test2 as select * from sc te ...
- jsp一些使用技巧
1.web.xml中配置error页面 一.<error-page> <error-code>500</error-code> <location>50 ...
- [macOS] error when brew updating
I want to update the brew, then run brew update but unluckly, i got these error /usr/local/Library/b ...
- PHP日历的算法
<?php if (function_exists('date_default_timezone_set')) { date_default_timezone_set('Asia/Chongqi ...
- C#中哈希表(HashTable)的用法详解以及和Dictionary比较
1. 哈希表(HashTable)简述 在.NET Framework中,Hashtable是System.Collections命名空间提供的一个容器,用于处理和表现类似keyvalue的键值对, ...
- spring 获取对象的注解
BeanDefinition definition = registry.getBeanDefinition(name); if (definition instanceof AnnotatedBea ...
- introduce myself
大家好啊,我是来自计算机一班的喻达龙,是2018届的萌新一个,很高兴与大家相约在这里.我想,大家都是怀抱相同的梦想带着一样的抱负走进涉外.我们从稚嫩蜕化为成熟,我相信我们在这里会从菜鸟变为大佬的,当然 ...