题目:

  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 ith 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 ith team wins, you get your bet on that team back, plus B/ 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 ith 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.

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.

题意:

  有n个队伍,你现在对某些队伍下注,要求下注的队伍的个数尽量多,而且只要下注的队伍中有一支队伍获胜就能赚回本来,问最多可以下注多少支队伍。

思路:

  要想一支队伍赢就能赚回本来,那每支队伍赢了至少要赚回本来。所以可以用本钱来求下注的钱数。设下注的钱数为x,则sum = x*(1+b/a);,之后对数组排序求和,当和大于等于本钱时退出。

PS:

  这个题卡long double,卡到怀疑思路错了,最后队友题意试一下long double,竟然过了!!!

  long double 要比double表示的范围大,表示的精度也更大。相应的计算的时候速度也就慢了点。

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
const int maxn = 1e5+;
long double a[]; int main()
{
ios::sync_with_stdio(false);
int T,n,cnt=;
char ch;
cin>>T;
while(T--)
{
memset(a,,sizeof(a));
long double sum = 1.0,aa,b;
cin>>n;
for(int i = ; i<n; i++)
{
cin>>aa>>ch>>b;
a[i] = sum/(1.0+b/aa);
}
sort(a,a+n);
int ans = ;
long double res = 0.0;
for(int i = ; i<n; i++)
{
res += a[i];
if(res<sum)
ans++;
else
break;
}
cout<<"Case #"<<cnt++<<": "<<ans<<endl;
}
return ;
} /*
样例输入:
1
3
1:1.1
1:0.2
1.5:1.7
样例输出:
Case #1: 2
*/

Bet(The 2016 ACM-ICPC Asia China-Final Contest 思路题)的更多相关文章

  1. 2016 ACM/ICPC Asia Regional Shenyang Online 1009/HDU 5900 区间dp

    QSC and Master Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

  2. 2016 ACM/ICPC Asia Regional Shenyang Online 1003/HDU 5894 数学/组合数/逆元

    hannnnah_j’s Biological Test Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K ...

  3. 2016 ACM/ICPC Asia Regional Qingdao Online 1001/HDU5878 打表二分

    I Count Two Three Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  4. 2016 ACM/ICPC Asia Regional Shenyang Online 1007/HDU 5898 数位dp

    odd-even number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  5. 2016 ACM/ICPC Asia Regional Dalian Online 1002/HDU 5869

    Different GCD Subarray Query Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K ( ...

  6. 2016 ACM/ICPC Asia Regional Dalian Online 1006 /HDU 5873

    Football Games Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

  7. HDU 5874 Friends and Enemies 【构造】 (2016 ACM/ICPC Asia Regional Dalian Online)

    Friends and Enemies Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

  8. HDU 5889 Barricade 【BFS+最小割 网络流】(2016 ACM/ICPC Asia Regional Qingdao Online)

    Barricade Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total S ...

  9. HDU 5875 Function 【倍增】 (2016 ACM/ICPC Asia Regional Dalian Online)

    Function Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total ...

  10. HDU 5873 Football Games 【模拟】 (2016 ACM/ICPC Asia Regional Dalian Online)

    Football Games Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

随机推荐

  1. Vijos 1451 圆环取数 【区间DP】

    背景 小K攒足了路费来到了教主所在的宫殿门前,但是当小K要进去的时候,却发现了要与教主守护者进行一个特殊的游戏,只有取到了最大值才能进去Orz教主…… 描述 守护者拿出被划分为n个格子的一个圆环,每个 ...

  2. python-----删除小于2k的文件

    删除小于2k的文件,代码如下: #!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2019/1/10 15:34 # @Author : ...

  3. LR(逻辑回归)

    逻辑回归(Logistic regression): 想要理解LR,只需要记住: Sigmoid 函数: y=1/(1+e-z) 线性回归模型: y=wTx+b 最后: y= 1/(1+e-(wTx+ ...

  4. Vsftpd软件包的获取与安装

    11.2  Vsftpd简介 Vsftpd是一种在GPL许可下开放源代码的FTP服务器,用于多种UNIX系统和Linux系统.Vsftpd也称为Very Secure FTP Daemon,它是一种安 ...

  5. springmvc 用fasterxml.jackson返回son数据

    一,引入fasterxm.jackson包 <dependency> <groupId>com.fasterxml.jackson.core</groupId> & ...

  6. C++中正确使用PRId64 (转载)

    转自:http://blog.csdn.net/win_lin/article/details/7912693 例子参考高性能流媒体服务器SRS:https://github.com/winlinvi ...

  7. MySQL5.7 windows二进制安装

    200 ? "200px" : this.width)!important;} --> 介绍 1.下载解压 下载地址:http://dev.mysql.com/get/Dow ...

  8. sublime text2 配置php本地环境时遇到的错误。

    首先,将PHP加到电脑的环境变量中如图(D:\PHPEnv\PHP5是我PHP的安装目录): 第二步:添加编译系统配置 第三步:配置详情: { "cmd": ["php. ...

  9. AutoCAD2013 以上利用AccoreConsole+ c# NetApi 批量处理图纸

    AccoreConsole听起来有点拗口,其中文名可以叫做AutoCAD控制台或者无头AutoCAD.一句话概括,它是快速启动AutoCAD运行微环境,高效的处理图纸.你可以如同DOS命令行一样操作命 ...

  10. 对路径 obj 文件夹访问被拒绝

    TFS 刚下载的项目,出现该问题. 解决方案: 将文件夹属性“只读”,取消