[hdu P4334] Trouble

Hassan is in trouble. His mathematics teacher has given him a very difficult problem called 5-sum. Please help him. 
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的更多相关文章

  1. HDU 4334 Trouble (暴力)

    Trouble Time Limit: 5000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u Submit Statu ...

  2. HDU 4334 Trouble

    Trouble Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  3. HDU 4334 Trouble (数组合并)

    Trouble Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  4. HDU 4334——Trouble——————【贪心&水题】

    Trouble Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  5. HDU 4334 Trouble(哈希|线性查找)

    给定五个集合.问是否能从五个集合各取一个元素,使得元素之和为0. 这道题有两种做法,一种是哈希,然而之前没写过哈希.....比赛后从大神那copy了一份. 这里说还有一种. 对于这五个集合分为三组.1 ...

  6. hdu 3591 The trouble of Xiaoqian

    hdu 3591  The trouble of Xiaoqian 题意:xiaoqi要买一个T元的东西,当前的货币有N种,xiaoqi对于每种货币有Ci个:题中定义了最小数量即xiaoqi拿去买东西 ...

  7. HDU 3591 The trouble of Xiaoqian(多重背包+全然背包)

    HDU 3591 The trouble of Xiaoqian(多重背包+全然背包) pid=3591">http://acm.hdu.edu.cn/showproblem.php? ...

  8. Trouble HDU - 4334

    Hassan is in trouble. His mathematics teacher has given him a very difficult problem called 5-sum. P ...

  9. HDU 3594 The trouble of Xiaoqian 混合背包问题

    The trouble of Xiaoqian Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/ ...

随机推荐

  1. Failed to load driver class com.mysql.jdbc.Driver from HikariConfig class classloader sun.misc.Launcher$AppClassLoader@18b4aac2

    1.错误日志 Failed to load driver class com.mysql.jdbc.Driver from HikariConfig class classloader sun.mis ...

  2. Py中查看数据类型【转载】

    转自:https://www.jianshu.com/p/bb5cc438e3b2 1.内置函数isinstance(object, (type1,type2...)) isinstance('con ...

  3. ignore_user_abort(true); set_time_limit(0);程序在本地测试可以一直运行,上传服务器只能运行10-15分钟

    当PHP运行在安全模式下时此函数无效.除了关闭安全模式或者在php.ini程序中修改最大运行时间没有其他办法让此函数运行. php.ini 中缺省的最长执行时间是 30 秒,这是由 php.ini 中 ...

  4. 从零开始一起学习SLAM | 给点云加个滤网

    对VSLAM和三维重建感兴趣的在计算机视觉life"公众号菜单栏回复"三维视觉"进交流群. 小白:师兄,上次你讲了点云拼接后,我回去费了不少时间研究,终于得到了和你给的参 ...

  5. 斐讯面试记录—TCP滑动窗口及拥塞控制

    TCP协议作为一个可靠的面向流的传输协议,其可靠性是由流量控制和滑动窗口协议保证,而拥塞控制则由控制窗口结合一系列的控制算法实现. 一.滑动窗口协议 1. “窗口”对应的是一段可以被发送者发送的字节序 ...

  6. linux tail命令及其它日志查看命令的用法

    当日志文件存储日志很大时,我们就不能用vi直接进去查看日志,需要Linux的命令去完成我们的查看任务. Log位置: /var/log/message 系统启动后的信息和错误日志,是Red Hat L ...

  7. maven ${path.separator}

    ${path.separator} 兼容 windows & linux: <compilerArguments> <verbose /> <bootclassp ...

  8. C++ Com控件调用

    1.假如我们创建的Com组件的工程名叫TestCom,在其中添加了一个接口叫MyCom,接口名会自动命名为IMyCom,在其中添加两个方法,分别为: HRESULT Add([in] long n1, ...

  9. jquery easyui datagrid 将值作为img显示图片时报404 undefined

    原因:datagrid 在请求到数据先进行头部数据和样式的渲染,之后数据 obj = {}  value = undefined  index = 0 进行一次渲染, 在没有formater情况将数据 ...

  10. [c/c++] programming之路(18)、动态分配内存malloc

    一.图解堆栈 #include<stdio.h> #include<stdlib.h> #include<Windows.h> void main0(){ **]; ...