[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/ ...
随机推荐
- python框架之Django(14)-rest_framework模块
APIView django原生View post请求 from django.shortcuts import render, HttpResponse from django import vie ...
- Cartographer源码阅读(9):图优化的前端——闭环检测
约束计算 闭环检测的策略:搜索闭环,通过匹配检测是否是闭环,采用了分支定界法. 前已经述及PoseGraph的内容,此处继续.位姿图类定义了pose_graph::ConstraintBuilder ...
- django-ajax post与get请求
客户端 访问 服务器 方式: 地址栏 get a标签 get form表单 get/post ajax ...
- MongoDB 知识点
左边是mongodb查询语句,右边是sql语句.对照着用,挺方便. db.users.find() select * from users db.users.find({"age" ...
- bs4.FeatureNotFound: Couldn’t find a tree builder with the features you requested: lxml.
python3 bs4解析网页时报错: bs4.FeatureNotFound: Couldn’t find a tree builder with the features you requeste ...
- Jmeter对jar包的调用赋值
一.前言 在我们测试接口的过程中,可能有时需要用到第三方jar包来生成一些测试数据(如有时需要对参数的输入值使用第三方jar包进行加密操作),涉及到这种的情况,普遍做法是:手动调用jar包获得需要的值 ...
- java.lang.RuntimeException: wrong class format Caused by: org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException: null
Spring Boot 启动的时候报的错 使用Drools 5.6版本,Spring Boot1.5.8版本,JAVA8版本,Eclipse4.4.2版本. Google后在Stack上发现一个,中文 ...
- eclipse无法断点调试JDK源码的问题
最近换了新版的eclipse,在jdk源码里面,打断点发现无法进入源码调试,程序直接跳过,已查资料发现自己eclipse配置的是jre环境的. 此处要配成jdk目录才有效 打开preferences, ...
- dotnet core命令
dotnet run -----运行程序 dotnet publish -r centos-x64 -----发布程序 mkdri 文件名--->cd 文件名--->dotnet new ...
- Html from 标签
Html from 标签 <html> <body> <!-- form 提交表单设置 --> <form> <input type=" ...