Problem Statement
Let comb(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a1,a2,…,an, select two numbers ai>aj so that comb(ai,aj) is maximized. If there are multiple pairs that maximize the value, any of them is accepted.
Constraints
- 2≤n≤105
- 0≤ai≤109
- a1,a2,…,an are pairwise distinct.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
n a1 a2 … an
Output
Print ai and aj that you selected, with a space in between.
Sample Input 1
Copy
5 6 9 4 2 11
Sample Output 1
Copy
11 6
comb(ai,aj) for each possible selection is as follows:
- comb(4,2)=6
- comb(6,2)=15
- comb(6,4)=15
- comb(9,2)=36
- comb(9,4)=126
- comb(9,6)=84
- comb(11,2)=55
- comb(11,4)=330
- comb(11,6)=462
- comb(11,9)=55
Thus, we should print 11 and 6.
Sample Input 2
Copy
2 100 0
Sample Output 2
Copy
100 0
题意:找最大的组合数
思路:由组合数的性质可得如果ak>ai,则comb(ak,aj)>comb(ai,aj).则可知ai应选最大值,aj则选距ai/2最近的值,即为解;
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
typedef long long ll;
int a[N];
double b[N];
int main()
{
int n,maxa=-1;
cin>>n;
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
sort(a+1,a+1+n);
double mid=1.0*a[n]/2,minb=1000000009.0;
int ans;
for(int i=1;i<n;i++){
// printf("%lf\n",mid-(1.0*a[n]-1.0*a[i]));
if(fabs(mid-(1.0*a[n]-1.0*a[i]))<minb)
{
ans=a[i];
minb=fabs(mid-(1.0*a[n]-1.0*a[i]));
}
}
printf("%d %d\n",a[n],ans);
}