题目大意:

从5个集合中个选取一个数出来,使5个数相加之和为0 , 判断是否存在这种可能

因为集合数目最多200,那么200^3 = 8000000 , 那么这里很明显要把5个数拆成2个和3个计算,因为3个的话有8000000种可能,不好保存

所以只先算前两个数40000种相加的可能性保存到hash表中,然后再后面800000次找hash表中是否存在对应的值

 #include <cstdio>
#include <cstring>
#include <iostream>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std; #define N 205
#define MOD 1000007
typedef long long ll;
int n;
ll v[][N] ;
int head[MOD+] , k; struct HashNode{
ll val;
int next;
}_hash[MOD]; void insert(ll key)
{
int pos = abs(key)%MOD;
_hash[k].val = key , _hash[k].next = head[pos];
head[pos] = k++;
} bool search(ll key)
{
int pos = abs(key)%MOD;
for(int i=head[pos] ; ~i ; i=_hash[i].next)
if(key == _hash[i].val) return true;
return false;
} int main()
{
#ifndef ONLINE_JUDGE
freopen("a.in" , "r" , stdin);
#endif // ONLINE_JUDGE
int T;
scanf("%d" , &T);
while(T--)
{
memset(head , - , sizeof(head));
k = ;
scanf("%d" , &n);
for(int i= ; i< ; i++){
for(int j= ; j<n ; j++) scanf("%I64d" , &v[i][j]);
} for(int i= ; i<n ; i++)
for(int j= ; j<n ; j++)
insert(v[][i]+v[][j]);
bool flag = false;
for(int i= ; i<n ; i++)
{
for(int j= ; j<n ; j++)
{
for(int k= ; k<n ; k++)
{
if(search(-v[][i]-v[][j]-v[][k])) flag=true; }
if(flag) break;
}
if(flag) break;
}
printf("%s\n" , (flag?"Yes":"No"));
}
return ;
}

最新文章

  1. smarty使用
  2. 1310. ACM Diagnostics
  3. DOM杂记
  4. VS2010 密钥问题
  5. 1920.154s 0.309s 30817
  6. C语言strchr()函数:查找某字符在字符串中首次出现的位置
  7. [Django_1_1]第一个app
  8. 上海二手房8月排名:链家、悟空找房、中原、太平洋、我爱我家、易居、房天下、iwjw、房多多、房好多、q房网、、、
  9. Service Oriented Architecture
  10. python ctypes小例子
  11. OS X快捷键最最齐全版(官方版)
  12. MFC 透明内存DC
  13. DSAPI 菜单渲染
  14. 二、docker的安装和基本命令
  15. sql选择
  16. Again Prime? No Time.(uva10870+数论)
  17. JS --- 本地保存localStorage、sessionStorage用法总结
  18. 1022. Sum of Root To Leaf Binary Numbers从根到叶的二进制数之和
  19. nowcoder172A 中位数 (二分答案)
  20. Codeforces 862B (二分图染色)

热门文章

  1. MongoDB学习笔记~监控Http请求的消息链
  2. ASP.NET Core Action 读取流
  3. P2614 计算器弹琴
  4. C# 部分命名规则
  5. hihocoder1736 最大的K-偏差排列
  6. [BZOJ1053][SDOI2005]反素数ant 数学
  7. 26款优秀的Android逆向工程工具
  8. 如何配置TomCat
  9. 关于ie的内存泄漏与javascript内存释放
  10. PHP环境搭建Zend Studio 10.6.2+WampServer2.4