2018 CodeM 资格赛 B.可乐

可乐

题目描述

小美和小团最近沉迷可乐。可供TA们选择的可乐共有k种,比如可口可乐、零度可乐等等,每种可乐会带给小美和小团不同的快乐程度。
TA们一共要买n瓶可乐,每种可乐可以买无限多瓶,小美会随机挑选其中的m瓶喝,剩下的n-m瓶小团喝。
请问应该如何购买可乐,使得小美和小团得到的快乐程度的和的期望值最大?
现在请求出购买可乐的方案。

输入

第一行三个整数n,m,k分别表示要买的可乐数、小美喝的可乐数以及可供选择的可乐种数。
接下来k行,每行两个整数a,b分别表示某种可乐分别给予小美和小团的快乐程度。
对于所有数据,1 <= n <= 10,000, 0 <= m <= n, 1 <= k <= 10,000, -10,000 <= a, b <= 10,000

输出

一行k个整数,第i个整数表示购买第i种可乐的数目。
如果有多解,请输出字典序最小的那个。
对于两个序列 a1, a2, …, ak, b1, b2, …, bk,a的字典序小于b,当且仅当存在一个位置i <= k满足:
ai < bi且对于所有的位置 j < i,aj = bj;

样例

输入
2 1 2
1 2
3 1
输出
0 2
说明
一共有三种购买方案:
1. 买2瓶第一类可乐,小美和小团各喝一瓶,期望得到的快乐程度和为1+2=3;
2. 买1瓶第一类可乐和1瓶第二类可乐,小美和小团各有二分之一的概率喝到第一类可乐,另有二分之一的概率喝到第二类可乐,期望得到的快乐程度和为1*0.5+3*0.5+2*0.5+1*0.5=3.5;
3. 买2瓶第二类可乐,小美和小团各喝一瓶,期望得到的快乐程度和为3+1=4。

题意

期望最大的话 以为两个的概率是固定的 为 m / n , 1 m / n 所以 只要相乘最大的那种方案就行了,
大水题。。。。

AC代码

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <string>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <ctime>
#include <vector>
#include <fstream>
#include <list>
#include <iomanip>
#include <numeric>
using namespace std;

#define ls              st<<1
#define rs              st<<1|1
#define fst             first
#define snd             second
#define MP              make_pair
#define PB              push_back
#define LL              long long
#define PII             pair<int,int>
#define VI              vector<int>
#define CLR(a,b)        memset(a, (b), sizeof(a))
#define ALL(x)          x.begin(),x.end()
#define rep(i,s,e) for(int i=(s); i<=(e); i++)
#define tep(i,s,e) for(int i=(s); i>=(e); i--)

const int INF = 0x3f3f3f3f;
const int MAXN = 2e5+10;
const int mod = 1e9+7;
const double eps = 1e-8;

void fe() {
  #ifndef ONLINE_JUDGE
      freopen("in.txt", "r", stdin);
      freopen("out.txt","w",stdout);
  #endif
}
LL read()
{
   LL x=0,f=1;char ch=getchar();
   while (ch<'0'||ch>'9') {if (ch=='-') f=-1;ch=getchar();}
   while (ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
   return x*f;
}
struct  node {
    int a, v;
}p[MAXN];
double arr[MAXN],brr[MAXN], crr[MAXN];

int main(int argc, char const *argv[])
{
    int n, m, k, x;
    cin >> n >> m >> k;
    for(int i = 0; i < k; i++) 
        cin >> arr[i] >> brr[i];
    double xx = m*1.0/n;
    double res = -INF;
    int pos;
    for(int i = 0; i < k; i++) {
        double yy = xx*arr[i]+(1.0-xx)*brr[i];
        if(res <= yy) {
            res = yy;
            pos = i;
        }
    }
    for(int i = 0; i < k; i++) {
        if(i == 0) {
            if(i == pos) 
                cout << n;
            else 
                cout << 0;
        }
        else {
            if(i == pos) 
                cout << " " << n;
            else
                cout << " " << 0;
        }
    }
    cout << "\n";
    return 0;
}

猜你喜欢

转载自blog.csdn.net/wang2332/article/details/80566953