和为0的四个值
来源:互联网 发布:曹云金 知乎 编辑:程序博客网 时间:2024/05/17 09:45
// by BNU_LZM#include<cstdio>#include<algorithm>using namespace std;const int maxn = 4010;int a[maxn], b[maxn], c[maxn], d[maxn], w[maxn*maxn];int erfenl(int x, int y, int v){int m;while(x < y){m = x+(y-x)/2;if(w[m] >= v) y = m;else x = m+1;}return x;}int erfenr(int x, int y, int v){int m;while(x < y){m = x+(y-x)/2;if(w[m] <= v) x = m+1;else y = m;}return x;}int main(){freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);int n;scanf("%d", &n);for(int i = 1; i <= n; i++) scanf("%d", &a[i]);for(int i = 1; i <= n; i++) scanf("%d", &b[i]);for(int i = 1; i <= n; i++) scanf("%d", &c[i]);for(int i = 1; i <= n; i++) scanf("%d", &d[i]);int cnt = 1;for(int i = 1; i <= n; i++)for(int j = 1; j <= n; j++)w[cnt++] = a[i]+b[j];sort(w+1, w+cnt);int ans = 0;for(int i = 1; i <= n; i++)for(int j = 1; j <= n; j++){int x = c[i]+d[j];int l = erfenl(1, cnt, -x);int r = erfenr(1, cnt, -x);ans += (r-l);}printf("%d\n", ans);return 0;}
0 0
- 和为0的四个值
- 和为0的四个值UVa1152
- [UVa 1152] 和为0的四个值(4 Values whose Sum is 0)
- 二分贪心练习题--D(四个数和为0的组合数)
- Leetcode012--四个数字的和为指定数
- OnFling的四个参数意思分别为
- OnFling的四个参数意思分别为
- 为知识付费买的四个教训
- C#以中心点经纬度和范围半径为基准计算矩形四个顶点的经纬度
- 给定四个正整数,求出四个数的最大值和最小值
- 于IaaS的四个误解和四个猜想
- 工作中任务管理的四个原则和四个技能
- 事物的四个特性和四个隔离级别
- 51Nod 1267 四个数字和为零
- 找出数组中和为指定值的四个数 4sum
- LeetCode18--4Sum--数组中某四个元素之和为某个输入的数值,输出这四个元素的值,并且这个四元组唯一
- position的四个属性值
- position的四个属性值
- 初谈Java集合
- XML序列化与反序列化
- HTML5五子棋游戏 画面超酷 可设置难度
- 剑指Offer_4Extra_合并两个有序数组
- Java三大特性之多态
- 和为0的四个值
- shell学习笔记3.14
- JavaWeb与Asp.net工作原理比较分析
- 20170313_从Asset文件夹导入一个已经存在的数据库
- C++命令模式
- Leetcode刷题(5)
- Lotus and Characters
- echarts3 柱状图
- QT之QCUSTOMPLOT绘图(一)配置和第一个例子