POJ 2785 4 Values whose Sum is 0 [dichotomy]

Source: Internet
Author: User

Transmission Door

13773503 njczy2010 2785 Accepted 25248K 7079MS g++ 1423B 2015-01-11 10:26:48

4 Values whose Sum is 0
Time Limit: 15000MS Memory Limit: 228000K
Total Submissions: 16102 Accepted: 4659
Case Time Limit: 5000MS

Description

The SUM problem can formulated as Follows:given four lists A, B, C, D of an integer values, compute how many quadruplet ( A, B, C, D) ∈a x B x C x D is such that A + B + c + d = 0. In the following, we assume this all lists has the same size n.

Input

The first line of the input file contains the size of the lists n (this value can be as large as 4000). We then had n lines containing four integer values (with absolute value as large as 228) that belong respectively to A, B, C and D.

Output

For each of the input file, your program have to write the number quadruplets whose sum is zero.

Sample Input

6-45 22 42-16-41-27 56 30-36 53-37 77-36 30-75-4626-38-10 62-32-54-6 45

Sample Output

5

Hint

Sample Explanation:indeed, the sum of the five following quadruplets is zero: (-45,-27, 42, 30), (26, 30,-10,-46), (-3) 2, 22, 56,-46), (-32, 30,-75, 77), (-32,-54, 56, 30).

Source

Southwestern Europe 2005 sign, holding his head for a long time how to do with a hash, is not thinking about using two points,,,,,

1#include <iostream>2#include <cstring>3#include <cstdlib>4#include <cstdio>5#include <algorithm>6#include <cmath>7#include <queue>8#include <map>9#include <Set>Ten#include <stack> One#include <string> A  - #defineN 4002 - #defineM 10 the #defineMoD 1000000007 - //#define P 10000007 - #defineMOD2 1000000000 - #definell Long Long + #defineLL Long Long - #defineEPS 1e-9 + #defineINF 0X3FFFFFFF A #defineMaxi (a) (a) > (b)? (a): (b) at #defineMini (A) (a) < (b)? (a): (b) -  - using namespacestd; -  - intx[n*N]; - intA[n],b[n],c[n],d[n]; in ll ans; - intK; to intN; +  - voidINI () the { *     inti,j; $ans=0;Panax Notoginseng      for(i=1; i<=n;i++){ -scanf"%d%d%d%d",&a[i],&b[i],&c[i],&d[i]); the     } +k=0; A      for(i=1; i<=n;i++){ the          for(j=1; j<=n;j++){ +x[k]=a[i]+b[j];k++; -         } $     } $Sort (x,x+k); - } -  the voidSolve () - {Wuyi     inti,j; the     intte; -     intt1,t2; Wu      for(i=1; i<=n;i++){ -          for(j=1; j<=n;j++){ Aboutte=-c[i]-D[j]; $T1=lower_bound (X,x+k,te)-x; -T2=upper_bound (X,x+k,te)-x; -ans+= (LL) (t2-t1); -         } A     } + } the  - void  out() $ { theprintf"%i64d\n", ans); the } the  the intMain () - { in     //freopen ("data.in", "R", stdin); the    //freopen ("Data.out", "w", stdout); the     //scanf ("%d", &t); About     //for (int ccnt=1;ccnt<=t;ccnt++) the     //While (t--) the      while(SCANF ("%d", &n)! =EOF) the     { + ini (); - solve (); the          out();Bayi     } the  the     return 0; -}

POJ 2785 4 Values whose Sum is 0 [dichotomy]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.