题目地址:http://poj.org/problem?id=2785

 #include<cstdio>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<stdbool.h>
#include<time.h>
#include<stdlib.h>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<vector>
using namespace std;
#define clr(x,y) memset(x,y,sizeof(x))
#define sqr(x) ((x)*(x))
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define LL long long
#define INF 0x3f3f3f3f
#define A first
#define B second const int N=+;
int n,a[][N],b[N*N]; void solve()
{
scanf("%d",&n);
for(int i=;i<n;i++) {
for(int j=;j<;j++) {
scanf("%d",&a[j][i]);
}
} for(int i=;i<n;i++) {
for(int j=;j<n;j++) {
b[i*n+j]=a[][i]+a[][j];
}
}
sort(b,b+n*n);
LL res=;
for(int i=;i<n;i++) {
for(int j=;j<n;j++) {
int p=-(a[][i]+a[][j]);
res+=upper_bound(b,b+n*n,p)-lower_bound(b,b+n*n,p);
}
} printf("%lld\n",res); }
int main()
{
solve(); return ;
}

[POJ] 2785 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. POJ - 2785 4 Values whose Sum is 0 二分

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

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

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

  5. POJ:2785-4 Values whose Sum is 0(双向搜索)

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

  6. POJ 2785 4 Values whose Sum is 0(暴力枚举的优化策略)

    题目链接: https://cn.vjudge.net/problem/POJ-2785 The SUM problem can be formulated as follows: given fou ...

  7. POJ 2785 4 Values whose Sum is 0(哈希表)

    [题目链接] http://poj.org/problem?id=2785 [题目大意] 给出四个数组,从每个数组中选出一个数,使得四个数相加为0,求方案数 [题解] 将a+b存入哈希表,反查-c-d ...

  8. POJ 2785 4 Values whose Sum is 0 Hash!

    http://poj.org/problem?id=2785 题目大意: 给你四个数组a,b,c,d求满足a+b+c+d=0的个数 其中a,b,c,d可能高达2^28 思路: 嗯,没错,和上次的 HD ...

  9. poj 2785 4 Values whose Sum is 0(折半枚举(双向搜索))

    Description The SUM problem can be formulated . In the following, we assume that all lists have the ...

随机推荐

  1. 智能卡 APTU命令

    一条命令APDU含有一个头标和一个本体.本体可有不同长度,或者在相关数据字段为空时,整个可以不存 在. 头标由四个数据元组成,它们是类CLA(ClAss)字节,命令INS(INStructic,n)字 ...

  2. #if defined 的意思?

    在读s3c2440a的test程序,其中option.h文件中有段语句为: #define LCD_N35 //#define LCD_L80 //#define LCD_T35 //#define ...

  3. MVC4.0系统开发新手历程(四)数据列表查询

    任何系统都不可避免的就是数据的查询展示,我觉得这里最值得一说的就是分部视图以及数据分页了 首先添加控制器 在控制其上面的名字为Index的Action上面右击,添加视图即可添加对应的视图,分部视图呈现 ...

  4. c语言结构体3之结构体嵌套

    注意: 1结构体内部再次定义一个结构体 但是没有创建结构体的实例  也就是说再次定义的结构体内部的变量会被当做母结构体的成员变量 struct tianchao { int data; ]; stru ...

  5. animation之translate、scale、alpha、rotate动画效果呈现

    动画类型 Android的animation由四种类型组成 XML中 alpha 渐变透明度动画效果 scale 渐变尺寸伸缩动画效果 translate 画面转换位置移动动画效果 rotate 画面 ...

  6. HTML--控制小人自由移动

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  7. HLS直播和时移项目上线

    兄弟姐妹们: 天翼视讯的高清HLS直播和时移项目上线,测试观看地址为:http://118.85.192.228/live/,同时支持移动终端和pc终端.移动终端支持ios client和androi ...

  8. Servlet实现文件的下载

    (1)项目的主文件夹例如以下:(演示出image和servlet的位置所在) watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveGxnZW4xNTczODc= ...

  9. LG 2.2.1 P350安卓系统刷机,问题总结,希望对需要的朋友有助

    手机误删软件导致短信,键盘等无声音提醒 我的手机前几天被我误删了一个软件,导致电话接不了,别人打电话的时候,老提示我在通话中,但是我可以在通话中看到对方的打电话记录.短信,键盘,USB连接,等等都没有 ...

  10. OpenMp 基本

      OpenMp是由OpenMP Architecture Review Board牵头提出的,并已被广泛接受的,用于共享内存并行系统的多线程程序设计的一套指导性的编译处理方案(Compiler Di ...