4 Values whose Sum is 0, valueswhose

Source: Internet
Author: User

4 Values whose Sum is 0, valueswhose
 Time Limit:15000 MSMemory Limit:228000KB64bit IO Format:% I64d & % I64uSubmit Status

Description

The SUM problem can be formulated as follows: given four lists A, B, C, D of integer values, compute how many quadruplet (a, B, c, d) ε A x B x C x D are such that a + B + c + d = 0. in the following, we assume that all lists have 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 have n lines containing four integer values (with absolute value as large as 2 28) that belong respectively to A, B, C and D.

Output

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

Sample Input

6-45 22 42 -16-41 -27 56 30-36 53 -37 77
 1 #include<cstdio> 2 #include<string.h> 3 #include<algorithm> 4 #define MAXN 4400 5 using namespace std; 6 int A[MAXN],B[MAXN],C[MAXN],D[MAXN]; 7 int S[MAXN*MAXN]; 8 int lower_bound1(int low,int high,int num,int a[]) 9  {10      int mid;11      while(low

 

-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 ), (-32, 22, 56,-46), (-32, 30,-75, 77), (-32,-54, 56, 30 ).
English literature expected by mathematics

En.wikipedia.org/wiki/Expected_value
Zh.wikipedia.org/..20.8020.bc

Mathematical expectation
Mathematical Expectation

In probability theory the expected value (or mathematical expectation, or mean) of a discrete random variable is the sum of the probability of each possible outcome of the experiment multiplied by the outcome value (or payoff ). thus, it represents the average amount one "expects" as the outcome of the random trial when identical odds are repeated several times. note that the value itself may not be expected in the general sense-the "expected value" itself may be unlikely or even impossible.

Examples
The expected value from the roll of an ordinary six-sided die is 3.5, which is not among the possible outcomes:

A common application of expected value is to gambling. for example, an American roulette wheel has 38 places where the ball may land, all equally likely. A winning bet on a single number pays 35-to-1, meaning that the original stake is not lost, and 35 times that amount is won, so you receive 36 times what you 've bet. considering all 38 possible outcomes, the expected value of the profit resulting from a dollar bet on a single number is the sum of what you may lose times the odds of losing and what you w ...... remaining full text>

How to add infinite numbers in C Language

Adding 20 Floating Point numbers, here is a program in ANSI Standard C:
Double sum, a [20];
Int I;
/*
* Some code to initialize array a with legitimate
* Floating point values whose sum is less than "maximum double ".
*/
Sums = 0.0;
For (I = 0; I <20; I ++)
Sum + = a [I];
Printf ("% e \ n", sum );

Sums = 0.0;
I = 20;
While (I --)
Sum + = a [I];
Printf ("% e \ n", sum );

Question:
Will the 2 "printed" values:
1) always be the same? If so, explain why.
2) always be different? If so, explain why.
3) sometimes be the same and sometimes different? If so, give an example. Please be as complete as possible.

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.