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

【题意】

在这里输入题意

【题解】

显然中间相遇。
自己写了个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. github关联域名,创建个人站点教程终结篇

    1.背景 近期心血来潮,买了一个域名,本来要买fuckgfw的,没想到被抢注了.就拿自己的英文名买了一个.叫做www.garvinli.com.由于知道会有非常多朋友不太清楚整个站点搭建的过程,所以在 ...

  2. _DataStructure_C_Impl:LinkListBasedSort

    #include<stdio.h> #include<stdlib.h> #include"LinkList.h" //创建单链表 void CreateL ...

  3. Linux常用的安全工具

    Linux常用的安全工具 "工欲善其事,必先利其器".作为一个合格的系统管理员,要应对可能发生的安全事件,掌握Linux下各种必须的安全工具是首要大事.本文主要介绍Linux上常用 ...

  4. vue 指令的用法

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. 机器学习实践:《Python机器学习实践指南》中文PDF+英文PDF+代码

    机器学习是近年来渐趋热门的一个领域,同时Python 语言经过一段时间的发展也已逐渐成为主流的编程语言之一.<Python机器学习实践指南>结合了机器学习和Python 语言两个热门的领域 ...

  6. Python excel 功能扩展库 ——> openpyxl 的基本使用

    说明:本文档内容参考自 https://www.cnblogs.com/zeke-python-road/p/8986318.html (作者:关关雎鸠`)的文档 from openpyxl impo ...

  7. iOS Scheme 跳转主流实现方案

    iOS Scheme跳转主流实现方案主要是路由跳转,目前iOS常用路由框架是JLRouter.HHRouter.MGJRouter. 但是这些路由库都各有不足,首先是JLRouter,用不到的功能繁多 ...

  8. 紫书 例题 9-6 UVa 11400 (线性结构上的动态规划)

    这道题的下标从1开始比较方便,一方面前缀和算的方便一些,一方面涉及到前j 个灯泡,那么如果从0开始,前3个灯泡就是第0, 1, 2, 3个,非常奇怪. 所以灵活换下标. 然后这道题的动规有点暴力枚举的 ...

  9. 【Henu ACM Round #13 B】Spider Man

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 会发现每个环可以操作的次数是固定的. (环的大小-1 也就是说一旦环确定了.其实结果就已经确定了. 则直接看操作总数的奇偶性就可以了 ...

  10. nio实现文件读取写入数据库或文件

    1.nio实现读取大文件,之后分批读取写入数据库 2.nio实现读取大文件,之后分批写入指定文件 package com.ally; import java.io.File; import java. ...