首页 > 其他 > 详细

Parlay Wagering

时间:2014-03-25 01:15:12      阅读:376      评论:0      收藏:0      [点我收藏+]

http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2833

题意:讲述了一种投小钱赢大钱的赌博方式,初始投入钱m,如果本局赢了,将钱连本带利投入下一局继续赌博。如果本局输了,之前得到的钱全部清零,如果打平,本局不赢钱。每局投入的钱数不能大于一百万,计算连本带利赢得的钱数,如果大于一百万则按赢了一百万。输入t组,然后是初始投入的钱m与赌博的局数n。在n局中,给出每局的Money Line,用于作为比率计算本局赢得的钱数。如果Money Line 大于0,则比率为Money Line/100,结果截取3位小数;否则,比率为100/Money Line,结果截取3位小数。每局赢得的钱数(截取两位小数)=当前投入的赌注*比率。最后得到的钱整数部分按每3位输出一个“,”的形式。

bubuko.com,布布扣
 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <iostream>
 4 #include <algorithm>
 5 #include <stack>
 6 using namespace std;
 7 const int N=2000010;
 8 #define LL long long
 9 struct ndoe
10 {
11     LL x;
12     string s;
13 } a[N];
14 char ss[N];
15 int main()
16 {
17     int t;
18     scanf("%d",&t);
19     while(t--)
20     {
21         double m;
22         int n;
23         scanf("%lf%d",&m,&n);
24         for (int i = 0; i < n; i++)
25         {
26             cin>>a[i].x>>a[i].s;
27         }
28         LL sum = m*100;
29         for (int i = 0; i < n; i++)
30         {
31             if (a[i].s=="Tie")
32                 continue;
33             else if (a[i].s=="Loss")
34             {
35                 sum = 0;
36                 continue;
37             }
38             else
39             {
40                 LL t1,t2;
41                 if (a[i].x > 0)
42                 {
43                     t1 = a[i].x*10;
44                     t2 = sum*t1/1000;
45                     sum+=t2;
46                 }
47                 else
48                 {
49                     t1 = 100*1000/(-a[i].x);
50                     t2 = sum*t1/1000;
51                     sum+=t2;
52                 }
53             }
54             if (sum >= 100000000) sum=100000000;
55         }
56         if (sum >= 100000000) sum=100000000;
57         double ans = sum*0.1/10;
58         sprintf(ss,"%.2f",ans);
59         stack<char>p;
60         int i,cnt = 0;
61         printf("$");
62         for (i = strlen(ss)-1; i >= 0; --i)
63         {
64             p.push(ss[i]);
65             if (ss[i]==.)
66                 break;
67         }
68         for (int j = i-1; j >= 0; --j)
69         {
70             cnt++;
71             p.push(ss[j]);
72             if (cnt%3==0&&j!=0)
73                 p.push(,);
74         }
75         while(!p.empty())
76         {
77             char ch = p.top();
78             printf("%c",ch);
79             p.pop();
80         }
81         puts("");
82     }
83     return 0;
84 }
View Code

Parlay Wagering,布布扣,bubuko.com

Parlay Wagering

原文:http://www.cnblogs.com/lahblogs/p/3621912.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!