Football Gambling II(zoj3356,贪心)

来源:互联网 发布:网络上的jpg什么意思 编辑:程序博客网 时间:2024/04/29 00:03

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3861

ZOJ Problem Set - 3356

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 a, b, c 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 s, a, b and c (0 < coins < 1000000, 1 < a, b,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

Submit    Status

解析:

题意:一个人有n本钱,有三个注可以让他压,每个注的获利倍数不同。如何押注使得他稳赚不赔,且最终拥有

最多钱

思路:

贪心,压钱的情况从1枚举到的n.由于总的获利情况取决最少赢的钱,因此每次只更新最小获利。

解题要点:抓住关键因素进行更新

注:注意把数据全部转化为同一一种形式,否则容易出错,如果是浮点型则要注意精度问题

Submit Time Judge Status Language Run Time(ms) Run Memory(KB) U

2013-07-23 10:48:19  Accepted C++ 810 188

*/


#include<stdio.h>#include<string.h>#include<math.h>#include <iostream>using namespace std;int a[4];int num[4];int min_id(){int k;k=a[0]*num[0]<=a[1]*num[1] ? 0:1;k=a[k]*num[k]<=a[2]*num[2] ? k:2;return k;}int max(int a,int b){return a>b? a:b;}int main(){int n,i,T,k;int t,ans;scanf("%d",&T);   while(T--)   {scanf("%d",&n);   int x1,xx1,x2,xx2,x3,xx3;   scanf("%d.%d%d.%d%d.%d",&x1,&xx1,&x2,&xx2,&x3,&xx3);//由于数据都要化为整型,如果是浮点型的话,(int)(3.30*100)=329会产生误差错误      memset(num,0,sizeof(num));     // printf("x1==%lf,x2==%lf,x3==%lf\n",x1*100,x2*100,x3*100);      a[0]=x1*100+xx1;      a[1]=x2*100+xx2;      a[2]=x3*100+xx3;      //printf("a[0]=%d,a[1]==%d,a[2]==%d\n",a[0],a[1],a[2]);      t=0;      for(i=1;i<=n;i++)//1由于是否可以稳赚取决于最小获利的那一注。因此每次都是从      //最小获利情况下考虑和更新      {k=min_id();//k为前一次最小获利的那注编号      num[k]++;//此处再加钱,目的是使获利更大。理由同1      k=min_id(); ///printf("num[%d]==%d\n",k,num[k]);//更新后取最小获利的编号      t=max(t,(num[k]*a[k]/100-i));//更新当前值      //printf("t==%d\n",t);      }      ans=t+n;      printf("%d\n",ans);   }    return 0;}