Gym - 101194E Bet [2016-2017 ACM-ICPC CHINA-Final E][贪心]

本文介绍了一个赌球策略的算法实现,通过数学分析确定了在确保最终获利的情况下,最多可以投注多少个队伍。利用概率和比较策略,实现了投注的最大化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

点击打开题目

题意: n个球队比赛,你可以赌哪个队获胜.如果你下注的队赢了,你将获得c + ai / bi * ci的钱,如果输了,那么你将输ci (ci为你下注的钱数)., 在确保你一定能得到比原来钱数多的前提下,你最多可以赌多少个队获胜(你下注的队伍至少有一支会赢得比赛).

分析: 假设原来总共有1元钱,在第i个足球队下注ci元钱,那么如果要最后获得的钱数大于1,则必有ci + ai / bi * ci  > 1  =>  ci > ai / (ai + bi) ,显然在下注第i个足球队后,你剩余的钱数为 1 - ci.问题就转变成了在满足 ∑(ai / (ai + bi)) < 1 , 赌最多的队获胜. 将ai / (ai + bi)排序后按从小到大取即可.

import java.math.BigInteger;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int t = cin.nextInt();
		int v = 1;
		BigInteger[] a = new BigInteger[120];
		BigInteger[] b = new BigInteger[120];
		while(t-- > 0) {
			int n = cin.nextInt();
			for(int i = 0; i < n; i++) {
				String str = cin.next();
				String[] st = str.split(":");
				double x = Double.parseDouble(st[0]) * 1000;
				double y = Double.parseDouble(st[1]) * 1000;
				a[i] = new BigInteger((long)x + "");
				b[i] = new BigInteger((long)y + "");
			}
			BigInteger tmp = new BigInteger("0");
			BigInteger tem = new BigInteger("0");
			for(int i = 0; i < n; i++) {
				for(int j = i + 1; j < n; j++) {
					if(a[i].multiply(b[j].add(a[j])).compareTo(a[j].multiply(a[i].add(b[i]))) > 0) {
						tmp = b[i];
						tem = a[i];
						a[i] = a[j];
						b[i] = b[j];
						a[j] = tem;
						b[j] = tmp;
					}
				}
			}
			int ans  = 1;
			BigInteger sum = a[0].add(b[0]), rr = a[0];
			for(int i = 1; i < n; i++) {
				 BigInteger sum1 = sum.multiply(a[i].add(b[i]));
				 rr = rr.multiply(a[i].add(b[i]));
				 rr = rr.add(sum.multiply(a[i]));
				 sum = sum1;
				 //System.out.println(sum + " " + rr);
				 if(sum.compareTo(rr) <= 0) break;
				 ans++;
			}
			System.out.println("Case #" + v++ + ": " + ans);
		}
		cin.close();
	}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值