Codeforce Gym 100819L : 2015-2016 ACM-ICPC Pacific Northwest Regional Contest - L 这是一道阅读理解(微笑)
2016-08-13 16:47
567 查看
题目(VJ) Gym - 100819L Codeforces-Gym Dashboard - 2015-2016 ACM-ICPC Pacific Northwest Regional Contest (Div. 2) PDF 20152016-acmicpc-pacific-northwest-regional-contest-div-2-en.pdf
讲道理第一题都应该是水题的。。。然而这是一道阅读理解... 读了三个多小时也没弄明白Sample2的那个数怎么算出来的,后来实在无聊从后往前算发现happiness正好算出来了...日啊... 官方的解释是这样的:
One should start by converting all the dollar values to happiness units and working with those; converting the final answer back to dollars is straightforward algebra.
To play Millionaire optimally, you want to determine how far you can go before you should take your winnings so far and quit, refusing to answer any further questions. The key observation is, once you've made it to a particular question, there's no additional history you need to worry about. So you can solve it backwards: assuming you make it to the final question, should you try to answer it or quit? If you quit, you receive the penultimate prize. If you try, the possible outcomes are success and failure, and your expected happiness is a weighted average of the two. Having determined whether to try or quit at the final question, now work backwards to the penultimate question and so on all the way back to the first question.
While a recursive solution risks overflowing the program stack, the same idea can be implemented by scanning over the questions backwards.
沃日...真是阅读理解啊...
AC代码 View Source On GitHub
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define MAXROUND 100005
double safemoney[MAXROUND];
double roundmoney[MAXROUND];
double p[MAXROUND];
char str[256];
inline double ln(double inc)
{
return log(inc);
}
int main()
{
int n,W;
scanf("%d %d",&n,&W);
for(int i=0;i<n;i++)
{
scanf("%s %lf %lf",str,&p[i],&roundmoney[i+1]);
roundmoney[i+1]=ln(1+roundmoney[i+1]/W);
if(strcmp(str,"safe")==0)
{
safemoney[i+1]=roundmoney[i+1];
}
else
{
safemoney[i+1]=safemoney[i];
}
}
for(int i=n-1;i>=0;i--)
{
double tmp=p[i]*roundmoney[i+1]+(1-p[i])*safemoney[i];
roundmoney[i]=max(tmp,roundmoney[i]);
}
double ans=(exp(roundmoney[0])-1)*W;
printf("$%.2f\n",ans);
}
讲道理第一题都应该是水题的。。。然而这是一道阅读理解... 读了三个多小时也没弄明白Sample2的那个数怎么算出来的,后来实在无聊从后往前算发现happiness正好算出来了...日啊... 官方的解释是这样的:
One should start by converting all the dollar values to happiness units and working with those; converting the final answer back to dollars is straightforward algebra.
To play Millionaire optimally, you want to determine how far you can go before you should take your winnings so far and quit, refusing to answer any further questions. The key observation is, once you've made it to a particular question, there's no additional history you need to worry about. So you can solve it backwards: assuming you make it to the final question, should you try to answer it or quit? If you quit, you receive the penultimate prize. If you try, the possible outcomes are success and failure, and your expected happiness is a weighted average of the two. Having determined whether to try or quit at the final question, now work backwards to the penultimate question and so on all the way back to the first question.
While a recursive solution risks overflowing the program stack, the same idea can be implemented by scanning over the questions backwards.
沃日...真是阅读理解啊...
AC代码 View Source On GitHub
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define MAXROUND 100005
double safemoney[MAXROUND];
double roundmoney[MAXROUND];
double p[MAXROUND];
char str[256];
inline double ln(double inc)
{
return log(inc);
}
int main()
{
int n,W;
scanf("%d %d",&n,&W);
for(int i=0;i<n;i++)
{
scanf("%s %lf %lf",str,&p[i],&roundmoney[i+1]);
roundmoney[i+1]=ln(1+roundmoney[i+1]/W);
if(strcmp(str,"safe")==0)
{
safemoney[i+1]=roundmoney[i+1];
}
else
{
safemoney[i+1]=safemoney[i];
}
}
for(int i=n-1;i>=0;i--)
{
double tmp=p[i]*roundmoney[i+1]+(1-p[i])*safemoney[i];
roundmoney[i]=max(tmp,roundmoney[i]);
}
double ans=(exp(roundmoney[0])-1)*W;
printf("$%.2f\n",ans);
}
相关文章推荐
- Codeforce Gym 100819P : 2015-2016 ACM-ICPC Pacific Northwest Regional Contest - P 仔细看题啊!
- [CFgym]2015-2016 ACM-ICPC Pacific Northwest Regional Contest小结
- 2015-2016 ACM-ICPC Pacific Northwest Regional Contest (Div. 2) S Surf
- 【2015-2016 ACM-ICPC Pacific Northwest Regional Contest (Div 1)D】【水题】Triangle 两个三角形是否可以恰好拼成矩形
- 【2015-2016 ACM-ICPC Pacific Northwest Regional Contest (Div 1)A】【floyd 最小路径覆盖】最少飞机数满足所有航班要求
- [CF Gym 100827K] Towers [2014-2015 ACM-ICPC Pacific Northwest Regional Contest K]
- [CF Gym 100827C] Containment [2014-2015 ACM-ICPC Pacific Northwest Regional Contest C]
- 【2015-2016 ACM-ICPC Pacific Northwest Regional Contest (Div 1)G】【坐标轴变换 LIS】Racing Gems 开车吃宝石,横向速度不能超
- 【2015-2016 ACM-ICPC Pacific Northwest Regional Contest (Div 1)H】【迭代 排序 模拟】Hilbert Sort 图形拐拐划分,经过所有点的
- 2015-2016 ACM-ICPC Pacific Northwest Regional Contest (Div. 2)V - Gears
- 【2015-2016 ACM-ICPC Pacific Northwest Regional Contest (Div 1)E】【水题 贪心】Excellence n个数两两组合使得最小和尽可能大
- 【2015-2016 ACM-ICPC Pacific Northwest Regional Contest (Div 1)C】【排序 模拟】Classy 课程难度排序超多关键字
- [CF Gym 100827E] Hill Number [2014-2015 ACM-ICPC Pacific Northwest Regional Contest E]
- [CF Gym 100827F] Knights [2014-2015 ACM-ICPC Pacific Northwest Regional Contest F]
- 2016-2017 ACM-ICPC Pacific Northwest Regional Contest (Div. 1) 【solved:9 / 12】
- 2016-2017 ACM-ICPC Pacific Northwest Regional Contest (Div. 1) K Tournament Wins
- Gym - 100792A Anagrams (2015-2016 ACM-ICPC, NEERC, Moscow Subregional Contest)
- 2017/9/23周测(CF2016-2017 ACM-ICPC Pacific Northwest Regional Contest (Div. 2))
- 2016-2017 ACM-ICPC Pacific Northwest Regional Contest (Div. 2)【solved:12 / 13】
- Codeforces GYM 100548 F - Color 2014-2015 ACM-ICPC, Asia Xian Regional Contest