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

【题意】

在这里输入题意

【题解】

显然中间相遇。
自己写了个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. [9]EC_屏蔽ecshop云提示no_license

    安装完后,打开后台就看到这个,特别烦,想立刻干掉它. watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdXB0b255dWFu/font/5a6L5L2T/f ...

  2. Android中ViewPager的使用

    我们在一个apk中第一次開始的时候,会有一个guide界面.一般使用ViewPager来完毕. 布局文件例如以下: <? xml version="1.0" encoding ...

  3. vue12 循环添加重复数据

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

  4. 数据库中的Convert

    https://docs.microsoft.com/en-us/sql/t-sql/functions/cast-and-convert-transact-sql Conversion failed ...

  5. 20.发送http请求服务 ($http)

    转自:https://www.cnblogs.com/best/tag/Angular/ 服务从代码直接与服务器进行交互,底层是通过实现,与中http服务从AngularJS代码直接与Web服务器进行 ...

  6. BZOJ 1066 Dinic

    思路: 网络流 建边比较麻烦 //By SiriusRen #include <queue> #include <cstdio> #include <cstring> ...

  7. Linux安全应用之防垃圾邮件服务器的构建

    Linux安全应用之防垃圾邮件服务器的构建 一.垃圾邮件产生的原因 垃圾邮件(SPAM) 也称作UCE(Unsoticited Commercial Email.未经许可的商业电子邮件)或UBE(Un ...

  8. Java经典算法案例

    笔试中的编程题3 JAVA经典算法40例[程序1] 题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第四个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少? ...

  9. vue踩坑- 报错npm ERR! cb() never called!

    在vue项目中引入饿了么elementUI组件的步骤之中,出现以下的错误: D:\my-project-first>npm i element-ui -S Unhandled rejection ...

  10. 洛谷 P2309 loidc,卖卖萌

    P2309 loidc,卖卖萌 题目背景 Loidc萌萌哒. 他最近一直在靠卖萌追求他的真爱——vivym,经过几轮攻势后vivym酱眼看就要被他所攻略.擅长数据结构的vivym决定利用强大的数据结构 ...