传送门

解题思路

  四个数组一起做有点炸。先把他们合并成两个数组,然后让一个数组有序,枚举另一个数组的元素,二分即可。时间复杂度\(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. (Struts2学习系列五)Struts2默认action

    当我们访问项目下一个不存在的Action的时候,页面就会报错,404找不到资源,这样对用户来说是非常不友好的,所以我们设置一个默认的Action,当找不到对应Action的时候,就会跳转到默认Acti ...

  2. json条件查询

    完整Demo <html> <head> <script type="text/javascript" src="http://www.w3 ...

  3. 2018-10-31-WPF-在触摸线程等待主线程窗口关闭会让主线程和触摸线程相互等待

    title author date CreateTime categories WPF 在触摸线程等待主线程窗口关闭会让主线程和触摸线程相互等待 lindexi 2018-10-31 9:30:9 + ...

  4. 基于用户的协同过滤(UserCF)

  5. linux常用命令-3文件与目录相关命令

    cd .. #返回上一级目录 cd ../.. #返回上两级目录 cd - #返回上次所在目录 cp file1 file2 #将file1复制为file2 cp -a dir1 dir2 #复制一个 ...

  6. 关于vsphere exsi安装时遇到的问题

    我在虚拟机上安装vsphere 6.0的时候,在安装的过程中报错,出现了如下的内容. Error loading /tools.t00 Compressed MD5: Decompressed MD5 ...

  7. Linux grep return code

    The exit code is 1 because nothing was matched by grep. EXIT STATUS The exit status is 0 if selected ...

  8. Mysql ibd恢复

    一,binlog恢复,这里就不说了. 二,ibd方式其实很简单, 生成数据结构(有的可以跳过) 1,创建一个新库 2,新库里新建一个表,名字和回复的表一样. 字段数量一样(字段类型和名字都无所谓) 3 ...

  9. git Web

    { …or create a new repository on the command line   echo "# Kotlin" >> README.md git ...

  10. 干货满满!解密阿里云RPA (机器人流程自动化)的产品架构和商业化发展

    阿里云RPA,作为阿里云自研8年的技术,在资本的热捧下,逐渐从幕后来到台前,成为企业服务市场的黑马.本文将从产品上全面剖析,阿里云RPA这款产品的现阶段情况,同时简单谈谈阿里云RPA的商业化进展. 阿 ...