2010-1070

从 Trac 迁移的文章

这是从旧校内 Wiki 迁移的文章,可能存在一些样式问题,您可以向 memset0 反馈。

原文章内容如下:

题目大意:已知赔率a,b,c和本金v,可以用v或v的一部分来下注,设下a,b,c分别为x,y,z,剩余r = v - x - y - z
则题目所求即max{r + min{ax, by, cz}} (r, x, y, z ∈ N)

要使最坏情况的最大值,那么就要尽可能使ax,by,cz平均一点

那么考虑所有情况for i := 0 -> v
对于每一个i,选择的下注对象为min{ax, by, cz}
从而不断更新,最后求得最大值

{{{
#!cpp
#include<stdio.h>
#include<memory.h>

int min(int *a)
{
    int res = a[0] < a[1] ? a[0] : a[1];
    return res < a[2] ? res : a[2];
}

int find_min(int *a)
{
    if (a[0] <= a[1] && a[0] <= a[2])
    {
        return 0;
    }
    if (a[1] <= a[2] && a[1] <= a[0])
    {
        return 1;
    }
    return 2;
}

int main(void)
{
    int i;
    int j;
    int k;
    int s;
    int tc;
    int temp;
    int odd[3];
    int get[3];
    int max;
    double fodd[3];

    scanf("%d", &tc);
    for (j=0; j<tc; ++j)
    {
        scanf("%d %lf %lf %lf", &s, fodd, fodd+1, fodd+2);
        for(i=0; i<3; ++i)
        {
            odd[i] = (int)(fodd[i] * 100 + 0.5);
        }
        memset(get, 0, sizeof(get));
        max = s;
        for (i=1; i<=s; ++i)
        {
            k = find_min(get);
            get[k] += odd[k];
            temp = min(get) / 100;
            max = max > s - i + temp ? max : s - i + temp;
        }
        printf("%d\n", max);
    }

    return 0;
}
}}}
[by delta_4d]

题目大意:已知赔率a,b,c和本金v,可以用v或v的一部分来下注,设下a,b,c分别为x,y,z,剩余r = v - x - y - z

则题目所求即max{r + min{ax, by, cz}} (r, x, y, z ∈ N)

要使最坏情况的最大值,那么就要尽可能使ax,by,cz平均一点

那么考虑所有情况for i := 0 -> v

对于每一个i,选择的下注对象为min{ax, by, cz}

从而不断更新,最后求得最大值

#include<stdio.h>
#include<memory.h>
int min(int *a)
{
    int res = a[0] < a[1] ? a[0] : a[1];
    return res < a[2] ? res : a[2];
}
int find_min(int *a)
{
    if (a[0] <= a[1] && a[0] <= a[2])
    {
        return 0;
    }
    if (a[1] <= a[2] && a[1] <= a[0])
    {
        return 1;
    }
    return 2;
}
int main(void)
{
    int i;
    int j;
    int k;
    int s;
    int tc;
    int temp;
    int odd[3];
    int get[3];
    int max;
    double fodd[3];
    scanf("%d", &tc);
    for (j=0; j<tc; ++j)
    {
        scanf("%d %lf %lf %lf", &s, fodd, fodd+1, fodd+2);
        for(i=0; i<3; ++i)
        {
            odd[i] = (int)(fodd[i] * 100 + 0.5);
        }
        memset(get, 0, sizeof(get));
        max = s;
        for (i=1; i<=s; ++i)
        {
            k = find_min(get);
            get[k] += odd[k];
            temp = min(get) / 100;
            max = max > s - i + temp ? max : s - i + temp;
        }
        printf("%d\n", max);
    }
    return 0;
}

[by delta_4d]