题目:






Football Gambling II


Time Limit: 3 Seconds      Memory Limit: 65536 KB


The 2010 FIFA World Cup toke place between 11 June and 11 July 2010 in South Africa. Being a non-fans, asmn likes football gambling more than the football match itself. Of course, he
won't use real money, he just gamble on the renren.com for fun using the virtual gold coin.

The rule of football gambling is simple. The bookmaker display three decimal numbers abc before the match between team X and team Y. Number a is
the odds for team X will win the game. Number b is the odds for they will get a draw. Number c is the odds for team X will lose the game.

Odds means that if you bet x gold coins, you will get floor(odds * x) gold coins in total if you guess the right result, or you will get nothing.

The Odds of the online gambling is higher than that in the real gambling because the gold coins are virtual. After several gambling, asmn found that, sometimes the odds are too high that
it is possible to find a way to bet on three result at the same time, so that he can win money whatever the result is.

After several gambling, asmn lose a lot of money. So he decide not to take any risk in the following gambling. Now, given that asmn has s gold coins before each match and the
odds for this math, you should caluate the maximum number of coins asmn will have after the gambling in the worst situation.

Input

The input consists of N cases. The first line of the input contains a positive integer N(N <= 100). Each case contains an integer and three decimal numbers sab and c (0
coins < 1000000, 1 < ab,c < 100), the meaning of which is described above. Each decimal number will have exactly two digits after the decimal point.

Output

For each case, output the maximum number of coins that asmn will have after the match in the worst situation.

Sample Input

4
3 3.30 3.30 3.30
30 3.30 3.30 3.30
1 30.00 50.00 20.00
42 2.00 3.00 7.00

Sample Output

3
33
1
43

Hint

In the third case, the odds are very high, but asmn has only one coin. If he join the gambling, he may lost his last coin.


Author: WANG, Yelei

Source: ZOJ Monthly, July 2010

题意:

每组测试数据 S 表示初始硬币个数,a,b,c分别表示题中所述赔率

赌博有三种结果,只可能猜中一种情况,猜中的 才可获利。

如果投 a,num个硬币【硬币不可拆分】并且结果是 a 那么可获利 floor(a*num)【即去掉小数部分】

对于 S 个硬币你可随意选择投或不投,或者投给哪一个

最后输出最糟的情况的获利【肯定是 >= S的】

思路:

后来看了这篇博客的博主写了下这个的想法: 点击打开链接

ax>x+y+z

by>x+y+x

cz>x+y+z

推出  1/a+1/b+1/c<1  注意是必要条件

有T组测试数据

开始比赛的时候想的是,按照每一个的赔率应该可以推出一个公式,从而决定每一种投多少硬币【为了保证一定结果不会比开始更糟,那么如果投,肯定是三种都要投的】,很显然的没有写出公式Orz

3355 判断是否稳赚不赔

同时如果上式成立,那么按b*cc*aa*b的比率去押注,就可以做到稳赚不赔,所以也是充分条件。

最后还是按照 mmchen 的枚举了,但是枚举如果用double  表示赔率,后面会出现很多精度问题,前面那位博主是每次算一次加入一点精度eps = 1e-5 到结果中。解决了这个问题,但是题目中也说了,赔率小数点后只会有两位,所以不想纠结了,还是按照mmchen的写法
,先全部扩大 100 倍,避免了精度问题,最后的结果再除以100就好了

mmchen的博客:http://blog.acmore.net/?p=821

总的来说,就是从1枚举到 S,每次选一个盈利最小的,然后硬币就投入进去,同时更新盈利,这样就保证了无论结果是a,b,c哪一种,都能至少不输钱

code:

扩大一百倍
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std; int main()
{
int T;
int s,a,aa,b,bb,c,cc;
int ans;
int num[5]; scanf("%d", &T);
while(T--)
{
scanf("%d%d.%d%d.%d%d.%d", &s,&a,&aa,&b,&bb,&c,&cc);
memset(num, 0, sizeof(num)); a = a*100+aa;
b = b*100+bb;
c = c*100+cc; ans = s*100;
int sa,sb,sc;
for(int i = 1; i <= s; i++)
{
sa = a*num[1];
sb = b*num[2];
sc = c*num[3]; if(sa <= sb && sa <= sc)
{
num[1]++;
}
else if(sb <= sa && sb <= sc)
{
num[2]++;
}
else if(sc <= sa && sc <= sb)
{
num[3]++;
} sa = a*num[1];
sb = b*num[2];
sc = c*num[3]; if(sa <= sb && sa <= sc)
{
ans = max(ans, sa+(s-i)*100);
}
else if(sb <= sa && sb <= sc)
{
ans = max(ans, sb+(s-i)*100);
}
else if(sc <= sa && sc <= sb)
{
ans = max(ans, sc+(s-i)*100);
} }
printf("%d\n", ans/100);
}
return 0;
}

加精度:

//各种精度问题Orz
//D Accepted 180 KB 1950 ms C++ (g++ 4.4.5) 1298 B
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std; const double eps = 1e-5;
int main()
{
int T;
scanf("%d", &T);
while(T--)
{
int s;
double a, b, c;
int num[4];
scanf("%d%lf%lf%lf", &s,&a,&b,&c);
int ans = s;
memset(num, 0, sizeof(num)); int aa,bb,cc; for(int i = 1; i <= s; i++)
{
aa = a*num[1]+eps; //加一点精度
bb = b*num[2]+eps;
cc = c*num[3]+eps; if(aa <= bb && aa <= cc)
{
num[1]++;
}
else if(bb <= aa && bb <= cc)
{
num[2]++;
}
else if(cc <= aa && cc <= bb)
{
num[3]++;
} aa = a*num[1]+eps;
bb = b*num[2]+eps;
cc = c*num[3]+eps; if(aa <= bb && aa <= cc)
{
ans = max(ans,s+aa-i);
}
else if(bb <= aa && bb <= cc)
{
ans = max(ans,s+bb-i);
}
else if(cc <= aa && cc <= bb)
{
ans = max(ans,s+cc-i);
} }
printf("%d\n", ans);
}
return 0;
}

 

zoj 3356 Football Gambling II【枚举+精度问题】的更多相关文章

  1. zoj 3620 Escape Time II dfs

    题目链接: 题目 Escape Time II Time Limit: 20 Sec Memory Limit: 256 MB 问题描述 There is a fire in LTR ' s home ...

  2. 洛谷-P1414 又是毕业季II -枚举因子

    P1414 又是毕业季II:https://www.luogu.org/problemnew/show/P1414 题意: 给定一个长度为n的数列.要求输出n个数字,每个数字代表从给定数列中最合理地取 ...

  3. zoj 3627 Treasure Hunt II (贪心)

    本文出自   http://blog.csdn.net/shuangde800 题目链接:zoj-3627 题意 直线上有n个城市, 第i个城市和i+1个城市是相邻的.  每个城市都有vi的金币.   ...

  4. hdu5073 简单枚举+精度处理

    其实这题还是挺简单的,因为移动k个星球后,这k个星球的权值就可以变为0,所以只有剩下的本来就是连着的才是最优解,也就是说要动也是动两端的,那么就O(N)枚举一遍动哪些就好了. 我是在杭电oj题目重现的 ...

  5. zoj 1622 Switch 开关灯 简单枚举

    ZOJ Problem Set - 1622 Switch Time Limit: 2 Seconds      Memory Limit: 65536 KB There are N lights i ...

  6. zoj 3620 Escape Time II

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4744 Escape Time II Time Limit: 2 Seconds ...

  7. ZOJ 3987 Numbers(Java枚举)

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3987 题意:给出一个数n,现在要将它分为m个数,这m个数相加起来必须等于n ...

  8. zoj 3983 Crusaders Quest 思维+枚举

    题目链接 这道题意思是: 给你一个长度为9的字符串,且只有3个a.3个g.3个o 问,你可以选择删除一段连续的串或者单个的字符也可以不删,最多会出现几个三子相连的子串 比如:agoagoago只有将两 ...

  9. ZOJ 3332 Strange Country II

    Strange Country II Time Limit: 1 Second      Memory Limit: 32768 KB      Special Judge You want to v ...

随机推荐

  1. 大量数据更新导致fgc频繁引起jvm服务暂停。

    线上跑的几台server突然出现大量fgc,因为在fgc过程的stop the world太久.引起其他应用訪问该server上的接口大量超时.(发生超时的时间点和fgc时间点一致) 先进行初步的优化 ...

  2. ieda常用快捷键

    Ctrl+Shift + Enter,语句完成“!”,否定完成,输入表达式时按 “!”键Ctrl+E,最近的文件Ctrl+Shift+E,最近更改的文件Shift+Click,可以关闭文件Ctrl+[ ...

  3. 【Hadoop】Hadoop MR 自定义分组 Partition机制

    1.概念 2.Hadoop默认分组机制--所有的Key分到一个组,一个Reduce任务处理 3.代码示例 FlowBean package com.ares.hadoop.mr.flowgroup; ...

  4. k8s restful API 结构分析

    k8s的api-server组件负责提供restful api访问端点, 并且将数据持久化到etcd server中. 那么k8s是如何组织它的restful api的? 一, namespaced ...

  5. HTTP请求和响应2:方法(Method)

    方法表明了client希望server对资源运行的动作.经常使用的方法包含:GET.HEAD.POST.PUT.TRACE.OPTIONS和DELETE,每一个server能够实现这些方法中的部分或者 ...

  6. P6 EPPM 16 R1安装和配置文档

    白桃花心木P6企业项目组合管理文档库  描述 链接 下载 零件号  16 R1用户和集成文档 查看库 下载 E68199-01 16 R1安装和配置文档 查看库 下载 E68198-01 描述 链接 ...

  7. EffectiveJava(18)接口优先于抽象类

    ***接口和抽象类同样可以用来定义多个实现的类型,然而,接口通常是最佳途径.*** 这条规则有个例外 – 当演变的容易性比灵活性和功能性更为重要的时候,应该用抽象来定义类型 ,但前提是必须理解并且可以 ...

  8. Windows无法删除文件 提示找不到该项目怎么办

    1 如图所示,我想要删除某个文件,提示如图所示,一般用360的强力删除也不管用.   2 在桌面新建一个文本文档,并输入以下内容.保存为bat格式(比如Delete.bat).然后把这个删不掉的文件拖 ...

  9. Activity返回数据给上一个活动

    1.在A这个Activity中以startActivityForResult(intent, requestCode)启动B这个Activity 2.在B这个Activity中setResult(re ...

  10. 关于Java性能的9个谬论

    http://www.infoq.com/cn/articles/9_Fallacies_Java_Performance Java的性能有某种黑魔法之称.部分原因在于Java平台非常复杂,很多情况下 ...