【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

显然中间相遇。
自己写了个hash处理一下冲突就可以了。

【代码】

/*
1.Shoud it use long long ?
2.Have you ever test several sample(at least therr) yourself?
3.Can you promise that the solution is right? At least,the main ideal
4.use the puts("") or putchar() or printf and such things?
5.init the used array or any value?
6.use error MAX_VALUE?
7.use scanf instead of cin/cout?
8.whatch out the detail input require
*/
/*
一定在这里写完思路再敲代码!!!
*/
#include <bits/stdc++.h>
const int MOD = 2000007;
using namespace std; const int N = 4e3; struct node{
int x,num;
node *nex;
node(){
x = 0;num = 0;nex=NULL;
}
node(int xx){
x = xx;num = 1;nex=NULL;
}
}; int n,a[4][N+10];
node *Hash[MOD+10]; void inc(int temp){
int x = abs(temp)%MOD;
node *p = Hash[x];
while (p->nex!=NULL){
p = p->nex;
if(p->x==temp){
p->num++;
return;
}
}
p->nex = new node(temp);
} int getnum(int temp){
int x= abs(temp)%MOD;
node *p = Hash[x];
while (p->nex!=NULL){
p = p->nex;
if(p->x==temp) return p->num;
}
return 0;
} int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif int T,kase = 0;
scanf("%d",&T);
while (T--){
for (int i = 0;i < MOD;i++) Hash[i] = new node();
if (kase>0) puts("");
kase++;
scanf("%d",&n);
for (int i = 1;i <= n;i++)
for (int j = 0;j < 4;j++)
scanf("%d",&a[j][i]);
for (int i = 1;i <= n;i++)
for (int j = 1;j <= n;j++)
inc(-a[0][i]-a[1][j]); long long ans = 0;
for (int i = 1;i <= n;i++)
for (int j = 1;j <= n;j++)
ans += getnum(a[2][i]+a[3][j]);
printf("%lld\n",ans);
} return 0;
}

【例题 8-3 UVA - 1152】4 Values whose Sum is 0的更多相关文章

  1. UVA 1152 4 Values whose Sum is 0 (枚举+中途相遇法)(+Java版)(Java手撕快排+二分)

    4 Values whose Sum is 0 题目链接:https://cn.vjudge.net/problem/UVA-1152 ——每天在线,欢迎留言谈论. 题目大意: 给定4个n(1< ...

  2. UVa 1152 -4 Values whose Sum is 0—[哈希表实现]

    The SUM problem can be formulated as follows: given four lists A, B, C, D of integer values, compute ...

  3. UVa 1152 4 Values whose Sum is 0

    题意:给出n,四个集合a,b,c,d每个集合分别有n个数,分别从a,b,c,d中选取一个数相加,问使得a+b+c+d=0的选法有多少种 看的紫书,先试着用hash写了一下, 是用hash[]记录下来a ...

  4. UVA - 1152 4 Values whose Sum is 0问题分解,二分查找

    题目:点击打开题目链接 思路:暴力循环显然会超时,根据紫书提示,采取问题分解的方法,分成A+B与C+D,然后采取二分查找,复杂度降为O(n2logn) AC代码: #include <bits/ ...

  5. UVA - 1152 --- 4 Values whose Sum is 0(二分)

    问题分析 首先枚举a和b, 把所有a+b记录下来放在一个有序数组,然后枚举c和d, 在有序数组中查一查-c-d共有多少个.注意这里不可以直接用二分算法的那个模板,因为那个模板只能查找是否有某个数,一旦 ...

  6. UVA - 1152 4 Values whose Sum is 0(中途相遇法)

    题意:从四个集合各选一个数,使和等于0,问有多少种选法. 分析:求出来所有ai + bi,在里面找所有等于ci + di的个数. #pragma comment(linker, "/STAC ...

  7. uva 1152 4 values whose sum is zero ——yhx

    The SUM problem can be formulated as follows: given four lists A;B;C;D of integer values, computehow ...

  8. UVA 1152 4 Values Whose Sum is Zero 和为0的4个值 (中途相遇)

    摘要:中途相遇.对比map,快排+二分查找,Hash效率. n是4000的级别,直接O(n^4)肯定超,所以中途相遇法,O(n^2)的时间枚举其中两个的和,O(n^2)的时间枚举其他两个的和的相反数, ...

  9. K - 4 Values whose Sum is 0(中途相遇法)

    K - 4 Values whose Sum is 0 Crawling in process... Crawling failed Time Limit:9000MS     Memory Limi ...

  10. POJ 2785 4 Values whose Sum is 0(想法题)

    传送门 4 Values whose Sum is 0 Time Limit: 15000MS   Memory Limit: 228000K Total Submissions: 20334   A ...

随机推荐

  1. WebForms简介

    http://www.w3school.com.cn/aspnet/aspnet_intro.asp ASP.NET 是下一代 ASP,不是 ASP 的更新版本. https://docs.micro ...

  2. thinkphp里面使用原生php

    thinkphp里面使用原生php Php代码可以和标签在模板文件中混合使用,可以在模板文件里面书写任意的PHP语句代码 ,包括下面两种方式: 使用php标签 例如: {php}echo 'Hello ...

  3. hdoj--5053--the Sum of Cube(水)

    the Sum of Cube Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Tot ...

  4. 22.IntelliJ IDEA 切换 project

    转自:https://blog.csdn.net/qwdafedv/article/details/73838628?utm_source=blogxgwz0 1.file->open 2.选择 ...

  5. Python(四) 分支、循环、条件与枚举

    一.什么是表达式 表达式(Expression)是运算符(operator)和操作数(operand)所构成的序列 二.表达式的优先级 三.表达式优先级练习 优先级同级 从左往右计算 1 or 2 a ...

  6. java中replaceAll反斜杠\ or java中replaceAll 括号[

    java中replaceAll反斜杠\   String s=new String("this is a \\"); s.replaceAll("\\",&qu ...

  7. centos inotify-rsync配置

    安装 yum -y install inotify-tools yum install rsync innotify说明 inotify介绍-- 是一种强大的.细颗粒的.异步的文件系统监控机制,*&a ...

  8. NStimer 被堵塞

    我们在界面上滚动一个scrollview,那么我们会发如今停止滚动前,会发现NSTimer未被运行.就好像scrollView在滚动的时候将timer暂停了一样,在查看对应文档后发现,这事实上就是ru ...

  9. 【java】itoo项目实战之大数据查询之使用 new map 优化hibernate之级联查询

    在我的上一篇博客<[java]itoo项目实战之hibernate 懒载入优化性能>中,我曾提到过学生数据有2万条,查询数据十分的慢,这是让人非常受不了的事情.看着页面进度条一直转着圈圈, ...

  10. 一次失败的PHP扩展开发之旅

    一次失败的PHP扩展开发之旅 By warezhou 2014.11.19 缘起 经过不断的持续迭代.我们部门的协程版网络框架(CoSvrFrame)最终出炉了!这本来是件喜大普奔的事情.可是随着新业 ...