1001 number pairs in array and equal to K
Base time limit: 1 seconds space limit: 131072 KB score: 5 difficulty: 1-level algorithm problem
Given an integer k and an unordered array, the elements of A,a are n distinct integers, finding the pairs of all and equal k in array A. For example k = 8, array a:{-1,6,5,3,4,2,9,0,8}, All and equal to 8 pairs include ( -1,9), (0,8), (2,6), (3,5).
Input
Line 1th: 2 numbers separated by a space, K n,n is the length of a array. (2 <= N <= 50000,-10^9 <= K <= 10^9)
2-n + 1 Rows: N elements of a array. ( -10^9 <= a[i] <= 10^9)
Output
Line 1-m: 2 numbers per line, requires a smaller number in front, and the M number is in ascending order of smaller Numbers.
If there is no one set of solutions Output: no Solution.
Input example
8 9
-1
6
5
3
4
2
9
0
8
Output example
-1 9
0 8
2 6
3 5
Violence never thought it would.
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 using namespacestd;6 intn;7 Long Longa[50010],k;8 intMain ()9 {Tenscanf"%lld%d",&k,&n); one BOOLtemp=false; a for(intI=1; i<=n;i++) -scanf"%lld",&a[i]); -Sort (a +1, a+n+1); the for(intI=1; i<=n;i++){ - if((a[i]+a[n]) <k)Continue; - for(intj=i+1; j<=n&&a[i]+a[j]<=k;j++){ - if(a[i]+a[j]==k) { +temp=true; -printf"%lld%lld\n", a[i],a[j]); + } a } at } - if(!temp) printf ("No solution\n"); - return 0; -}
1001 The sum of the numbers in a group equals K the number of pairs
< Span style= "font-size:7.5pt; font-family: Microsoft Jacob black, sans-serif; > base time Limit: 1 , Second space limit: 131072 kb score : 5 difficulty: 1 class algorithm questions
Given an integer K and an unordered array a, the elements ofa are N distinct integers, and the pairs of all and equal K in array a are found. For example K = 8, array A:{ -1,6,5,3,4,2,9,0,8}, all and equal to 8 pairs including ( -1,9),(0,8) ,(2,6),(3,5).
Input
Line 1 : 2 number separated by a space,K n,n is the length of a array. (2 <= N <= 50000,-10^9 <= K <= 10^9)
2-n + 1 rows: N elements ofa array. (-10^9 <= a[i] <= 10^9)
Output
Line 1-m : 2 per line, requires a smaller number in front, and the M number is in ascending order of a smaller number.
If there is no one set of solutions output: nosolution.
Input Example
8 9
-1
6
5
3
4
2
9
0
8
Output Example
-1 9
0 8
2 6
3 5
51Nod 1001 pairs of numbers equal to K in arrays