Bet ( UVALive 7901 ) ( 思维 + long double )

欢迎访问https://blog.csdn.net/lxt_Lucia~~

宇宙第一小仙女\(^o^)/~萌量爆表求带飞=≡Σ((( つ^o^)つ~ dalao们点个关注呗~

 

--------------------------------我只是一条可爱哒分界线-------------------------------

 

一、问题:

Description

The Codejamon game is on fire! Fans across the world are predicting and betting on which team will win the game.

A gambling company is providing betting odds for all teams; the odds for the i-th team is Ai : Bi . For each team, you can bet any positive amount of money, and you do not have to bet the same amount on each team. If the i-th team wins, you get your bet on that team back, plus Bi Ai times your bet on that team.

For example, suppose that there are two teams, with odds of 5:3 and 2:7 and you bet $20 on the first team and $10 on the second team. If the first team wins, you will lose your $10 bet on the second team, but you will receive your $20 bet back, plus 3/5 × 20 = 12, so you will have a total of $32 at the end. If the second team wins, you will lose your $20 bet on the first team, but you will receive your $10 bet back, plus 7/2 × 10 = 35, so you will have a total of $45 at the end. Either way, you will have more money than you bet ($20+$10=$30).

As a greedy fan, you want to bet on as many teams as possible to make sure that as long as one of them wins, you will always end up with more money than you bet. Can you figure out how many teams you can bet on?

 

Input

The input starts with one line containing exactly one integer T, which is the number of test cases.

Each test case starts with one line containing an integer N: the number of teams in the game. Then, N more lines follow. Each line is a pair of numbers in the form ‘Ai:Bi ’ (that is, a number Ai , followed by a colon, then a number Bi , with no spaces in between), indicating the odds for the i-th team.

 

Output

For each test case, output one line containing ‘Case #x: y’, where x is the test case number (starting from 1) and y is the maximum number of teams that you can bet on, under the conditions specified in the problem statement.

Limits:

• 1 ≤ T ≤ 100.

• 1 ≤ N ≤ 100.

• 0 < Ai , Bi < 100.

• Both Ai and Bi have at most 3 digits after the decimal point.

Note:

In sample case #1, one optimal strategy is to bet 1.5 dollars on the first team and 1.5 dollars on the third team. If the first team wins, you will get 1.5 + 1.5 × (1.1/1) = 3.15 dollars back, and if the third team wins, you will get 1.5 + (1.7/1.5) × 1.5 = 3.2 dollars back. Both of these are higher than the total money that you bet (1.5 + 1.5 = 3 dollars).

However, there is no way to bet on all three teams and be guaranteed a profit.

 

Sample Input

1

3

1:1.1

1:0.2

1.5:1.7

 

Sample Output

Case #1: 2

 

二、题意:

现给出每个队伍一个赔率 Ai : Bi ,假设你对某个队下了 x 元的注,若该队获胜你可对应获得    元,否则得到 0 元。

求:在只要有一个队伍获胜就能保证赚钱的条件下,最多能给几个队下注。

 

三、思路:

注意:这个题 double 的精度不够,需要用 long double。

 

四、代码:

#include <cstdio>
#include <algorithm>
#define fori(a,b) for(int i=a; i<=b; ++i)
#define forj(a,b) for(int j=a; j<=b; ++j)
using namespace std;

int main()
{
    int T, n;
    long double a[1000], x, y;
    scanf("%d", &T);
    forj(1, T)
    {
        scanf("%d", &n);
        fori(1, n)
        {
            scanf("%Lf:%Lf", &x, &y);
            a[i] = x/(x+y);
        }
        sort(a+1, a+1+n);
        long double k = 0;
        int  ans = 0;
        fori(1, n)
        {
            k += a[i];
            if(k >= 1.00)
                break;
            ans++;
        }
        printf("Case #%d: %d\n", j, ans);
    }
    return 0;
}

 

--------------------------------我也是有底线的---------------------------------

宇宙第一小仙女\(^o^)/~萌量爆表求带飞=≡Σ((( つ^o^)つ~ dalao们点个关注呗~

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值