Bet(The 2016 ACM-ICPC Asia China-Final Contest 思路题)
题目:
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 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 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 思路题)的更多相关文章
- 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) ...
- 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 ...
- 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 ...
- 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 ...
- 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 ( ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- ppp点对点协议
直接链接两个信令点的一组链路称作什么? PPP点到点连接: 点对点协议(PPP)为在点对点连接上传输多协议数据包提供了一个标准方法.PPP 最初设计是为两个对等节点之间的 IP 流量传输提供一种封装协 ...
- Glide 图片形状裁剪 ,滤镜等
Glide . Picasso . Fresco 已逐渐成为Android主流的图片加载工具(个人见解,使用Volley.ImageLoader.xUtils的大佬们请勿喷~),在多数Android程 ...
- svchost.exe 占用内存过多
http://www.tomshardware.com/forum/20583-63-svchost-netsvcs-speed By Lokesh Chandra: Just Go to Contr ...
- oracle给用户授权
1.在PLSQL里,用sys(oracle系统用户)登陆,登陆的时候一定要选择SYSDBA.普通用户登陆选择normal就可以了 2.创建用户 *也可以给普通用户授权为dba即数据库管理员.在导入导出 ...
- [App Store Connect帮助]六、测试 Beta 版本(1)TestFlight Beta 版测试概述(iOS、Apple TVOS、watchOS)
TestFlight Beta 版测试让您可以分发您 App 的 Beta 版构建版本给测试员并收集反馈.您可以在您的 App Store Connect 帐户中一次为至多 100 个 App 启用 ...
- 我的周记2——“天道酬勤"
Get 什么是JAVA https://zhuanlan.zhihu.com/p/62717204 了解下HTTP 缓存机制 https://juejin.im/post/5a1d4e546fb9a ...
- 第三章 K近邻法(k-nearest neighbor)
书中存在的一些疑问 kd树的实现过程中,为何选择的切分坐标轴要不断变换?公式如:x(l)=j(modk)+1.有什么好处呢?优点在哪?还有的实现是通过选取方差最大的维度作为划分坐标轴,有何区别? 第一 ...
- java io 文件下载
/** * 文件下载 * @param response * @param downloadPath * @param docName */ public void downLoadFile( Htt ...
- [NOI2004]cashier 郁闷的出纳员
Description OIER公司是一家大型专业化软件公司,有着数以万计的员工.作为一名出纳员,我的任务之一便是统计每位员工的工资.这本来是一份不错的工作,但是令人郁闷的是,我们的老板反复无常,经常 ...
- 状态压缩+枚举 UVA 11464 Even Parity
题目传送门 /* 题意:求最少改变多少个0成1,使得每一个元素四周的和为偶数 状态压缩+枚举:枚举第一行的所有可能(1<<n),下一行完全能够由上一行递推出来,b数组保存该位置需要填什么 ...