AtCoder Regular Contest 095 D - Binomial Coefficients

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

  • 2n105
  • 0ai109
  • 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);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值