noip2014-Universal group Rematch-first question-Abacus mental arithmetic test

Source: Internet
Author: User

Title DescriptionDescription Bead Heart is a kind of computing technique that can accomplish fast computation by simulating the change of abacus in the brain. Abacus Mental Arithmetic training, not only can develop intelligence, but also can bring many conveniences for daily life, so in many schools get popularity.

A school's abacus mental arithmetic teacher uses a kind of test method to study the ability of abacus arithmetic addition quickly. He randomly generates a set of positive integers in which the number varies, and then asks the student to answer: how many are there, exactly equal to the sum of the other two (different) numbers in the set?

Recently the teacher has made some quiz questions, ask you to help to find out the answer.

(This topic is 2014NOIP popularization T1) input/output format input/output Input Format:
Enter a total of two lines, the first line containing an integer n, representing the number of positive integers given in the test question.
The second line has n positive integers, separated by a space between each of the two positive integers, representing the positive integers given in the test question.
output Format:
Outputs a common line that contains an integer that represents the answer to the quiz question. input and Output sample sample Input/output sample Test point # # Input Sample:

4
1 2 3 4

Sample output:

2

"Sample description"

By 1+2=3,1+3=4, the answer to meet the test requirements is 2. Note that Addend and Summand must be two different numbers in a collection.

"Data description"

For 100% of the data, 3≤n≤100, the number of positive integers given by the quiz is not more than 10,000.

Idea: This problem can be divided into two arrays, one of the sorting, then judge, output can be.

The code is as follows:

1#include <stdio.h>2 intMain ()3 {4     inti,j,k,m,n,ans=0;5     inta[101],p[101];//two identical arrays, a array is sorted out and stored in the P array.6scanf"%d",&n);7      for(i=1; i<=n;i++)//enter a number into the a array inside8     {9scanf"%d",&a[i]);Ten     } One      for(i=1; i<n;i++)//sorts each number in the a array A           for(j=i+1; j<=n;j++) -               if(a[i]>A[j]) -               { thek=A[i]; -a[i]=A[j]; -a[j]=K; -               } +      for(i=1; i<n-1; i++)//sweep backwards from the first one -          for(j=i+1; j<n;j++)//from the second one to the first +              for(k=j+1; k<=n;k++) A                 if(A[i]+a[j]==a[k])//If a test instructions is found, the number inside the P array becomes 1 . at                 { -p[k]=1; -                 } -      for(i=1; i<=n;i++)//sweep back from the front, each element is added -     { -ans+=P[i]; in     }     -printf"%d\n", ans); to     return 0; +}

noip2014-Universal group Rematch-first question-Abacus mental arithmetic test

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.