Question: http://acm.zju.edu.cn/onlinejudge/showProblem.do? Problemcode = 3356 http://acm.hust.edu.cn/vjudge/contest/view.action? Cid = 26732 # Problem/d
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 numbersA,B,CBefore the match between Team X and team Y. NumberAIs
The odds for Team X will win the game. NumberBIs the odds for they will get a draw. NumberCIs the odds for Team X will lose the game.
Odds means that if you betXGold coins, you will getFloor (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 hasSGold coins before each match and
Odds for this math, you shocould caluate the maximum number of coins asmn will have after the gambling in the worst situation.
Input
The input consistsNCases. The first line of the input contains a positive integerN(N<= 100). Each case contains an integer and three decimal numbersS,A,BAndC(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
43 3.30 3.30 3.3030 3.30 3.30 3.301 30.00 50.00 20.0042 2.00 3.00 7.00
Sample output
333143
Hint
In the third case, the odds are very high, but asmn has only one coin. If he joins the gambling, he may lost his last coin.
Author: Wang, yelei
Source: zoj monthly, July 2010
Question:
Test data in each group: s indicates the number of initial coins, and A, B, and C respectively indicate the odds described in the question.
Gambling has three results. Only one guess is possible, and only one guess can make a profit.
If you cast a coin, num [the coin cannot be split] and the result is a, then the profitable floor (A * num) [that is, remove the decimal part]
For s coins, you can choose either to vote or not, or to vote for which one.
The final profit for the output of the worst case [Definitely> = s]
Ideas:
After reading this blog, the blogger wrote this idea: Click to open the link.
Ax> X + Y + z
By> X + Y + x
CZ> X + Y + z
1/A + 1/B + 1/C <1 Note:
T group test data available
When I started the competition, I thought that a formula should be available based on each odds to determine the number of coins each kind of investment. [to ensure that the result will not be worse than the start, if I vote, there must be three options to be cast. Obviously, the formula orz is not written.
3355 determine whether the service is stable or not
At the same time, if the above formula is trueB * C,C *,A * BTo bet, you can make a steady profit without compensation, so it is also a sufficient condition.
At last, we still follow mmchen's enumeration. However, if double is used for enumeration, there will be many precision problems in the future, the previous blogger added a little precision of EPS = 1e-5 to the result each time. This problem has been solved, but the question also says that there will be only two digits after the decimal point, so I don't want to worry about it, or follow the mmchen statement.
First, all the data is increased by 100 times to avoid precision issues. The final result is divided by 100.
Mmchen blog: http://blog.acmore.net /? P = 821
In general, it is from 1 enumeration to S. Each time we choose one with the smallest profit, the coin is invested in it, and the profit is updated. This ensures that no matter whether the result is a, B, c, which can be at least Zero loss code: an increase of one hundred times
#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;}
Precision addition:
// Various precision problems orz // daccepted180 kb1950 MSC ++ (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", & 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; // Add 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 ;}