标签:poj2785
Time Limit: 15000MS | Memory Limit: 228000K | |
Total Submissions: 16000 | Accepted: 4625 | |
Case Time Limit: 5000MS |
Description
Input
Output
Sample Input
6 -45 22 42 -16 -41 -27 56 30 -36 53 -37 77 -36 30 -75 -46 26 -38 -10 62 -32 -54 -6 45
Sample Output
5
Hint
Source
/* ** Problem: POJ2785 ** Status: Accepted ** Running Time: 6766ms ** Author: Changmu ** ** 题解:将解空间分成两部分分别枚举。 */ #include <cstdio> #include <cstring> #include <algorithm> #define maxn 4010 typedef __int64 LL; using namespace std; int A[4][maxn], CD[maxn * maxn]; int main() { LL ret = 0; int i, j, n, id = 0, tmp; scanf("%d", &n); for(i = 0; i < n; ++i) { for(j = 0; j < 4; ++j) scanf("%d", &A[j][i]); } for(i = 0; i < n; ++i) for(j = 0; j < n; ++j) CD[id++] = A[2][i] + A[3][j]; sort(CD, CD + id); for(i = 0; i < n; ++i) for(j = 0; j < n; ++j) { tmp = A[0][i] + A[1][j]; ret += upper_bound(CD, CD + id, -tmp) - lower_bound(CD, CD + id, -tmp); } printf("%I64d\n", ret); }
POJ2785 4 Values whose Sum is 0 【枚举】
标签:poj2785
原文地址:http://blog.csdn.net/chang_mu/article/details/40948903