-
Total time limit:
-
1000ms
-
Memory Limit:
-
65536kB
-
Describe
-
Give a number of integers asking if there is a pair of numbers and equal to the given number.
-
Input
-
Total three lines:
The first line is an integer n (0 < n <= 100,000) that represents n integers.
The second line is n integers. The range of integers is between 0 and 10^8.
The third line is an integer m (0 <= M <= 2^30) that represents the and that needs to be obtained.
-
Output
-
If there are several pairs of m, output two integers, small in front, large in the middle, separated by a single space. If there is more than one number to satisfy the condition, select the smaller number of the number pair. If no matching number pairs are found, the output line is no.
-
Sample input
-
42 5 1 46
-
Sample output
-
1 5
1#include <stdio.h>2#include <stdlib.h>3 #defineMAXN 1000104 intA[MAXN];5 intcmpConst void*a,Const void*b)6 {7 return*(int*) a-* (int*) b;8 }9 intFoundintLintRintTG)Ten { One intMid= (L+R)/2; A while(l<r-1) - { - if(Tg==a[mid])return 1; the Else if(A[MID]>TG) r=mid; - ElseL=mid; -Mid= (L+R)/2; - } + return 0; - } + intMain () A { at intN; - intmin; - inti,j; - intflag=0; - intsum; - intn1,n2; in intTg,l,r; -scanf"%d",&n); toscanf"%d", &a[0]); +min=a[0]; - for(i=1; i<n;i++) the { *scanf"%d",&a[i]); $ if(a[i]<min) min=A[i];Panax Notoginseng } -Qsort (A,n,sizeof(int), CMP);//convenient two points thescanf"%d",&sum); + if(n==1) flag=0; A Else the { +j=0; - while(j<N) $ { $tg=sum-min; - if(Found (J,N,TG)) - { theflag=1; -N1=min;//A[j]==minWuyiN2=TG; the Break; - } Wu Else -min=a[++j]; About } $ } - if(flag==0) printf ("no\n"); - Elseprintf"%d%d\n", n1,n2); - return 0; A}
In fact, it is not difficult, it is the basic of the two points.
First of all to analyze the situation of n=1, at this time only No.
Then analyze the situation of n>=2. The method is very simple, the preparation is a fast line, and then starting from the first number, with a given number of M minus the currently selected number of A[j], two points from the current number to the maximum number of find.
Openjudge Noi question Bank ch0111/07 and for a given number