[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/ ...
随机推荐
- MySQL5.7 虚拟列实现表达式或函数索引
MySQL5.7 虚拟列实现表达式或函数索引 http://www.linuxidc.com/Linux/2015-11/125162.htm https://dev.mysql.com/doc/re ...
- 【UML】NO.50.EBook.5.UML.1.010-【UML 大战需求分析】- 考勤系统
1.0.0 Summary Tittle:[UML]NO.50.EBook.1.UML.1.010-[UML 大战需求分析]- 考勤系统 Style:DesignPattern Series:Desi ...
- java开发定时任务执行时间
定时任务执行时间配置详解 Seconds Minutes Hours Day-of-month Month Day-of-Week Year 秒 分 时 天 ...
- Docker:Docker打包Web API成镜像并上传到Docker Hub(2)
Docker官方镜像:https://hub.docker.com/: 本文将把一个webapi制作成docker镜像 一.Docker命令 打开Docker Quickstart,有以下常用的命令 ...
- python操作excel的读、计算、写----xlrd、copy
import xlrd from xlutils.copy import copy class ExcelUtil: def __init__(self,excel_path=None,index=N ...
- Treap仿set 模板
Treap仿set 模板 蓝书232 &代码: #include <cstdio> #include <bitset> #include <iostream> ...
- Olap学习笔记
数据仓库建设--OLAP和数据立方体概念 http://student-lp.iteye.com/blog/2263154 OLAP(On-LineAnalysis Processing)在线分析处理 ...
- linux以16进制查看文件
vim 先用vim -b data 以2进制打开文件,然后用xxd工具转化,在vim的命令行模式下: :%!xxd --将当前文本转化为16进制格式 :%!xxd -r --将16 ...
- centos7.5 修改网卡名称
1.修改网卡配置文件中名称信息 vim /etc/sysconfig/network-scripts/ifcfg-ens33 将其中的名称为ens33的改为eth0 ,并将uuid删除以便后面克隆 2 ...
- Node + Redis 实现分布式Session方案(转载)
Session是什么? Session 是面向连接的状态信息,是对 Http 无状态协议的补充. Session 怎么工作? Session 数据保留在服务端,而为了标识具体 Session 信息指向 ...