07: and for a given number of (half)

description

It gives the number of integers, asking whether there is a pair of numbers and equal to a given number.

The input common three lines:
the first line is an integer of n (0 <n <= 100,000 ), there are n represents an integer.
The second line is the n integers. It is an integer ranging between 0 and 10 ^ 8.
The third line is an integer m (0 <= m <= 2 ^ 30), and expressed the need. If there is output and p, an output two integers, small front, after a large, separated by a single space for the number of m. If the number of the plurality of conditions are satisfied, the number of the smaller number of selected smaller. If not found to meet the requirements of the logarithm of the output line No. Sample input

4
2 5 1 4
6

Sample Output

15 

ideas: can-half may map, set off WA words, if a given 5,678,910, and 10 to find, will wrong
#include <bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
#define ll long long
ll a[100000+5],n,k;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    sort(a+1,a+1+n);
    cin>>k;
    for(int i=1;i<=(n+1)>>1;i++)
    {
        if( a[ lower_bound( a+1,a+1+n,k-a[i]) -a] == k-a[i] )
            {cout<<a[i]<<" "<<k-a[i]<<endl;return 0;}
    }
    cout<<"No"<<endl;
}

 



Guess you like

Origin www.cnblogs.com/Shallow-dream/p/11706109.html