POJ 2785 4 Values whose Sum is 0
来源:互联网 发布:安卓编程权威指南第3版 编辑:程序博客网 时间:2024/06/06 01:17
you can find the problem here
the question let us to find 4 number from each row which sum fo them is zero. what we should do is to take two rows of tem as one row,get
#include<iostream>#include <cstdio>#include<cstring>#include <algorithm>using namespace std;const int maxn = 4005;int a[maxn],b[maxn],c[maxn],d[maxn];int ab[maxn*maxn],cd[maxn*maxn];int main(){ int n = 0; while(~ scanf("%d",&n)) { for(int i=1; i<=n; i++) scanf("%d%d%d%d",&a[i],&b[i],&c[i],&d[i]); int cnt = 0; for(int i=1; i<=n; i++) { for(int j = 1; j<=n; j++) { ab[cnt] = a[i]+b[j]; cd[cnt++] = c[i]+d[j]; } } int ans = 0; //sort(ab,ab+cnt); sort(cd,cd+cnt); for(int i=0; i<cnt; i++) { int s = ab[i]; //cout<<ab[i]<<endl; if(binary_search(cd,cd+cnt,-s)) { ans+=upper_bound(cd,cd+cnt,-s)-lower_bound(cd,cd+cnt,-s); } } printf("%d\n",ans); } return 0;}
阅读全文
0 0
- POJ 2785 Values whose Sum is 0
- 4 Values whose Sum is 0 POJ
- 4 Values whose Sum is 0 POJ
- 4 Values whose Sum is 0 POJ
- 4 Values whose Sum is 0 POJ
- POJ 2785 4 Values whose Sum is 0
- POJ 2785 4 Values whose Sum is 0 二分
- POJ 2785:4 Values whose Sum is 0
- POJ 2785(4 Values whose Sum is 0)
- poj 2785 4 Values whose Sum is 0
- poj 2785 4 Values whose Sum is 0 (二分+枚举)
- poj 2785 4 Values whose Sum is 0(hash)
- POJ 2785: 4 Values Whose Sum is 0
- poj 2785 4 Values whose Sum is 0
- POJ 2785 4 Values whose Sum is 0 Hash!
- poj 2785 4 Values whose Sum is 0 哈希
- POJ 2785 4 Values whose Sum is 0(二分)
- POJ 2785 4 Values whose Sum is 0 二分
- hdoj6129 Just do it(三种方法加详解)
- cookie与session的区别
- TensorFlow Ubuntu 安装笔记
- Metropolis Light Transport学习与实现
- 剑指OFFER 算法练习
- POJ 2785 4 Values whose Sum is 0
- intent-filter的action,category,data匹配规则
- 使用tf.contrib.learn构建输入函数
- OPENQUERY使用
- 红黑树性质的理解
- 2017.8.16. 最长不下降序列
- JavaScript的数据类型、内置对象
- 页面间传数据的中文乱码问题(第七周啦)
- ECMA-Script5