标签:output integer time i++ sed font input 技术分享 ide
Time Limit: 15000MS | Memory Limit: 228000K | |
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
#include<cstdio> #include<iostream> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std; // 0--n-1 1 n -- 2n-1 0 const int M = 4005, inf = 1e8; int ans, a[M], b[M], c[M], d[M], p[M*M], q[M*M]; bool cmp(int a, int b){return a > b;} int main(){ int n, cnt = 0; scanf("%d", &n); for(int j = 1; j <= n; j++)scanf("%d%d%d%d", &a[j], &b[j], &c[j], &d[j]); for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++)p[++cnt] = a[i] + b[j]; cnt = 0; for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++)q[++cnt] = c[i] + d[j]; sort(p+1, p+1+cnt); sort(q+1, q+1+cnt, cmp); p[cnt+1] = q[cnt+1] = inf; int st = 1, ed = 1; while(st <= cnt || ed <= cnt){ while(p[st] + q[ed] < 0)st++; while(p[st] + q[ed] > 0)ed++; while(p[st] + q[ed] == 0){ int cc = st, dd = ed; while(p[st] == p[cc])st++; while(q[ed] == q[dd])ed++; ans += (st - cc) * (ed - dd); } } printf("%d\n", ans); }
poj2785 4 Values whose Sum is 0
标签:output integer time i++ sed font input 技术分享 ide
原文地址:https://www.cnblogs.com/EdSheeran/p/9396188.html