Gym 101190F Foreign Postcards
来源:互联网 发布:大数据主要来源于哪些 编辑:程序博客网 时间:2024/06/05 13:23
题意和转移就不讲了,讲讲比较 迷 的一点吧。
比赛结束之前,WA好多遍也没过,,
我开始还以为状态转移不对,或者写搓了,但是队友坚持查错,最终发现了这些有趣的地方。
目前只能怀疑和编译器有关系。
这样写是正确的,可以AC:
dp[0][0]=s[0]=='C'?1:0;
这样写是不行的,27组测试数据处会WA:
(s[0]=='C')?dp[0][0]=1:dp[0][0]=0;
还有,if{}else{}也不行,27组测试数据处会WA:
if (s[0]=='C') { dp[0][0]=1.0; } else { dp[0][0]=0.0; }先贴上AC代码:
#include<map>#include<set>#include<list>#include<stack>#include<deque>#include<queue>#include<vector>#include<sstream>#include<iomanip>#include<iostream>#include<math.h>#include<ctype.h>#include<stdio.h>#include<stdlib.h>#include<string.h>#include<algorithm>#include<functional>#define CPY(A,B)memcpy(A,B,sizeof(A))#define fin freopen("in.txt","r",stdin)#define fout freopen("out.txt","w",stdout)typedef long long LL;typedef unsigned long long uLL;const int MOD=1e9+7;const int INF=0x3f3f3f3f;const LL INFF=0x3f3f3f3f3f3f3f3fLL;const double OO=1e20;const double EPS=1e-9;const double PI=acos (-1.0);int dx[]= {0,1,0,-1};int dy[]= {1,0,-1,0};using namespace std;int gcd (const LL &a,const LL &b) { return b==0?a:gcd (b,a%b);}inline int dcmp (double a,double b) { if (fabs (a-b) <EPS) { return 0; } return a>b;}const int M=1e6+50;double dp[M][2];string s;int ss;bool judge (int n) { return s[n]=='C'?true:false;}void Init() { cin>>s; ss=s.size();// if (judge (0) ) {// dp[0][0]=1.0;// dp[0][1]=0.0;// } else {// dp[0][0]=0.0;// dp[0][1]=1.0;// }}int main() { freopen ("foreign.in","r",stdin); freopen ("foreign.out","w",stdout); Init(); dp[0][0]=s[0]=='C'?1:0; dp[0][1]=s[0]=='C'?0:1; double p,ans=0.0; for (int i=1; i<ss; ++i) { p=1.0/ (ss+1-i);// dp[i][0]= (1.0-p) *dp[i-1][0];// if (judge (i) ) {// dp[i][0]+=p;// } dp[i][0]=judge (i) ? (p+ (1-p) *dp[i-1][0]) : ( (1-p) * dp[i-1][0]); dp[i][1]=1.0-dp[i][0]; (judge (i) ) ?ans+=dp[i][1]:ans+=dp[i][0]; } printf ("%.10f\n",ans); return 0;}
WA在第27组的代码:
#include<map>#include<set>#include<list>#include<stack>#include<deque>#include<queue>#include<vector>#include<sstream>#include<iomanip>#include<iostream>#include<math.h>#include<ctype.h>#include<stdio.h>#include<stdlib.h>#include<string.h>#include<algorithm>#include<functional>#define CPY(A,B)memcpy(A,B,sizeof(A))#define fin freopen("in.txt","r",stdin)#define fout freopen("out.txt","w",stdout)typedef long long LL;typedef unsigned long long uLL;const int MOD=1e9+7;const int INF=0x3f3f3f3f;const LL INFF=0x3f3f3f3f3f3f3f3fLL;const double OO=1e20;const double EPS=1e-9;const double PI=acos (-1.0);int dx[]= {0,1,0,-1};int dy[]= {1,0,-1,0};using namespace std;int gcd (const LL &a,const LL &b) { return b==0?a:gcd (b,a%b);}inline int dcmp (double a,double b) { if (fabs (a-b) <EPS) { return 0; } return a>b;}const int M=1e6+50;double dp[M][2];string s;int ss;bool judge (int n) { return s[n]=='C'?true:false;}void Init() { cin>>s; ss=s.size(); if (judge (0) ) { dp[0][0]=1.0; dp[0][1]=0.0; } else { dp[0][0]=0.0; dp[0][1]=1.0; }//这样用if和else会WA}int main() { freopen ("foreign.in","r",stdin); freopen ("foreign.out","w",stdout); Init(); double p,ans=0.0; for (int i=1; i<ss; ++i) { p=1.0/ (ss+1-i); dp[i][0]= (1.0-p) *dp[i-1][0]; if (judge (i) ) { dp[i][0]+=p; }//这里用if也会WA //judge (i) ?dp[i][0]=(p+ (1-p) *dp[i-1][0]) :dp[i][0]=( (1-p) * dp[i-1][0]);//这样写,也会WA dp[i][1]=1.0-dp[i][0]; (judge (i) ) ?ans+=dp[i][1]:ans+=dp[i][0]; } printf ("%.10f\n",ans); return 0;}
阅读全文
0 0
- Gym 101190F Foreign Postcards
- Codeforces Gym 101190 (NEERC 2016) F. Foreign Postcards (dp + 期望)
- Foreign Postcards Gym
- Postcards
- [Gym-101350F] F
- Gym 100685 F Flood
- Gym 100989F STL
- codeforces Gym 101102F
- Codeforces-GYM-100726F
- Codeforces GYM 100803F
- Gym - 100947F
- [Gym-100520F]
- Gym 101142F Folding
- Gym 100553F-Filter
- Gym 101164.F
- Gym 101482.F
- Gym 101201.F
- Gym 100513F - Ilya Muromets
- C++11中的std::function,Lambda表达式
- Eclipse上red5插件安装
- 新域名访问方式从http改为https(为了支持微信小程序https用)
- lintcode刷题——搜索旋转排序数组
- 消息摘要、数字签名、数字证书
- Gym 101190F Foreign Postcards
- javaScript实现小球碰撞
- git学习3
- 合法IP地址的判断、关于给定字符串,求最大不重复子串 -- JAVA 算法题
- 【快搭】springboot+jsp
- (二)UI Automator测试项目的建立
- Java爬虫--页面跳转爬数据
- HDU5492 Find a path (动态规划)
- MySQL查询表格内容基本语句1