传送门

解题思路

  四个数组一起做有点炸。先把他们合并成两个数组,然后让一个数组有序,枚举另一个数组的元素,二分即可。时间复杂度\(O(n^2logn^2)\)

代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm> using namespace std;
const int MAXN = 4005; inline int rd(){
int x=0,f=1;char ch=getchar();
while(!isdigit(ch)) {f=ch=='-'?0:1;ch=getchar();}
while(isdigit(ch)) {x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
return f?x:-x;
} int A[MAXN*MAXN],B[MAXN*MAXN],n,a[MAXN],b[MAXN],c[MAXN],d[MAXN];
int num[MAXN*MAXN],cnt,cnt2,cpy[MAXN*MAXN];
long long ans; int main(){
n=rd();int x,y,w,z;
for(int i=1;i<=n;i++)
a[i]=rd(),b[i]=rd(),c[i]=rd(),d[i]=rd();
for(register int i=1;i<=n;i++)
for(register int j=1;j<=n;j++) A[++cnt]=a[i]+b[j],B[cnt]=c[i]+d[j];
sort(A+1,A+1+cnt);A[0]=(1<<28)+1;
for(register int i=1;i<=cnt;i++){
if(A[i]==A[i-1]) num[cnt2]++;
else cpy[++cnt2]=A[i],num[cnt2]=1;
}
// for(int i=1;i<=cnt2;i++) cout<<cpy[i]<<" ";
// A[++cnt2]=1;A[++cnt2]=2;A[++cnt2]=8;B[++cnt]=1;B[++cnt]=-2;B[++cnt]=-8;
for(register int i=1;i<=cnt;i++) {
x=lower_bound(cpy+1,cpy+1+cnt2,-B[i])-cpy;
// cout<<x<<endl;
if(cpy[x]==-B[i]) ans+=num[x];
}
printf("%lld\n",ans);
return 0;
}

SP1296 SUMFOUR - 4 values whose sum is 0的更多相关文章

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

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

  2. POJ 2785 4 Values whose Sum is 0

    4 Values whose Sum is 0 Time Limit: 15000MS   Memory Limit: 228000K Total Submissions: 13069   Accep ...

  3. 哈希-4 Values whose Sum is 0 分类: POJ 哈希 2015-08-07 09:51 3人阅读 评论(0) 收藏

    4 Values whose Sum is 0 Time Limit: 15000MS Memory Limit: 228000K Total Submissions: 17875 Accepted: ...

  4. [poj2785]4 Values whose Sum is 0(hash或二分)

    4 Values whose Sum is 0 Time Limit: 15000MS Memory Limit: 228000K Total Submissions: 19322 Accepted: ...

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

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

  6. 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< ...

  7. UVA1152-4 Values whose Sum is 0(分块)

    Problem UVA1152-4 Values whose Sum is 0 Accept: 794  Submit: 10087Time Limit: 9000 mSec Problem Desc ...

  8. POJ - 2785 4 Values whose Sum is 0 二分

    4 Values whose Sum is 0 Time Limit: 15000MS   Memory Limit: 228000K Total Submissions: 25615   Accep ...

  9. POJ 2785 4 Values whose Sum is 0(折半枚举+二分)

    4 Values whose Sum is 0 Time Limit: 15000MS   Memory Limit: 228000K Total Submissions: 25675   Accep ...

随机推荐

  1. Level DB 小调研

    一. 概况: 1. 背景: 随着信息技术的高速发展,数据存储量和流量呈现爆炸式增长.目前百度统计日 PV(日点击量)已超过 75 亿次,中国网民在百度上进行50 亿次的搜索请求,百度贴吧日 PV 十亿 ...

  2. 前端 JavaScript BOM & DOM

    内容目录: 1. BOM 2. DOM BOM(Browser Object Model)是指浏览器对象模型,它使 JavaScript 有能力与浏览器进行"对话". DOM (D ...

  3. uniq - 删除排序文件中的重复行

    总览 (SYNOPSIS) ../src/uniq [OPTION]... [INPUT [OUTPUT]] 描述 (DESCRIPTION) 从 INPUT (或 标准输入) 数据 中 忽略 (但是 ...

  4. Java调用Linux下的shell命令并将结果以流的形式返回

    import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader; public cl ...

  5. visual studio 2013下搭建 安卓,ios,wp app开发平台

    1.安装 visual studio 2013 + Microsoft Visual Studio 2013 Update 4+Microsoft Build Tools 2015 2.安装java ...

  6. day03 mysql外键 表的三种关系 单表查询 navicat

    day03 mysql navicat   一.完整性约束之     外键 foreign key     一个表(关联表: 是从表)设置了外键字段的值, 对应的是另一个表的一条记录(被关联表: 是主 ...

  7. Batch - call, start, goto 区别

    参考(待整理): 批处理命令——call 和 start

  8. C/Python/Java环境变量配置

    链接 全图预览: Java: 只需添加下面三个环境变量即可使用Java.对照这我的添加就行. CLASSPATH的内容: .;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\li ...

  9. 编译器报错: error LNK2001: unresolved external symbol "struct _ServiceDescriptorTable * KeServiceDescript

    转自VC错误:http://www.vcerror.com/?p=10 问题描述: 编译器报错: error LNK2001: unresolved external symbol "str ...

  10. C++之内存分区