[置顶] Gym 101190F Foreign Postcards
2017-08-29 19:29
393 查看
题意和转移就不讲了,讲讲比较 迷 的一点吧。
比赛结束之前,WA好多遍也没过,,
我开始还以为状态转移不对,或者写搓了,但是队友坚持查错,最终发现了这些有趣的地方。
目前只能怀疑和编译器有关系。
这样写是正确的,可以AC:
这样写是不行的,27组测试数据处会WA:
还有,if{}else{}也不行,27组测试数据处会WA:
WA在第27组的代码:
比赛结束之前,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 =='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 =='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; }
相关文章推荐
- [置顶] 不用打开新的页面下载文件
- [置顶] 【算法 机器学习】R语言做朴素贝叶斯和决策树算法
- [置顶] multiple definition of(变量或者函数)
- android自定义View之自定义可置顶ScrollView,View滑动原理简析
- 文章标题 Gym 100971K : Palindromization
- [置顶] 图论500题
- [置顶] 浏览器缓存深入研究
- [置顶] iOS史上最全的UITextView实现placeHolder占位文字的N种方法
- [置顶] 类的封装性和信息隐蔽—类声明和成员函数定义的分离
- [置顶] 人月神话(一)
- [置顶] 大数 斐波那契 与阶乘
- [置顶] 【spark 词频统计】spark单词进行计数升级版
- [置顶] liunx常用命令
- 悬浮框,View置顶
- [置顶] 分享一些收集整理的一些常用Android万能工具类
- [置顶] 学习笔记之iptables(一)
- [置顶] 如何正确配置 Nginx+PHP
- [置顶] Python+Splinter实现简单12306自动刷新抢票
- [置顶] 二维码作激活码(密钥)功能开发
- [置顶] 恶意代码--样本分析学习资料整理网络地址