题目链接:http://codeforces.com/problemset/problem/476/B

题目意思:给出两个字符串str1, str2,其中,str1 只由 '+' 和 '-' 组成,而str2 由 '+','-'和'?'组成。初始点在原点0的位置,经过 str1 的变换最终会达到某一个位置,‘+'表示向右移动一个单位(+1),'-'即-1。str2 中 '?'的部分可以填入'+','-'其中一个符号。问能填充 '?' 的所有情况中,使得使用 str2 所有的操作,能到达   经过 str1 所有操作后到达的最终位置   的概率是多少。(额....比较拗口= =,俺的...表达能力果然不敢恭维- -!)

首先,算出经过 str1 所有的操作后最终到达的位置,这个明显是确定的啦,没有 '?' 嘛。接着算出 str2 除 '?' 外到达的位置,剩下用深搜来填入 '?',统计等于最终位置的种数。最后用  这个种数 / 问号能填入的所有情况,就是答案啦!!!

还有一些特判点,假如str2 没有问号,概率只有两种情况:1 或者 0。其他就要dfs算啦~~

粗心过头,wa了两次: 无用%.12lf(又到考眼力的时候了= =) 还有调试 cnt 不记得注释了= =......

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std; const int maxn = + ;
char str1[maxn], str2[maxn];
int unknown, origin;
double cnt, fenmu; void dfs(int c, int cur)
{
if (c == unknown)
{
if (cur == origin)
cnt++;
return;
}
dfs(c+, cur+);
dfs(c+, cur-);
} int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif while (scanf("%s%s", str1, str2) != EOF)
{
int len = strlen(str1);
origin = ; for (int i = ; i < len; i++)
{
if (str1[i] == '+')
origin += ;
else
origin -= ;
} int known = ;
unknown = ;
for (int i = ; i < len; i++)
{
if (str2[i] == '?')
unknown++;
else if (str2[i] == '+')
known += ;
else if (str2[i] == '-')
known -= ;
}
if (!unknown)
{
if (known != origin)
printf("0.000000000000\n");
else
printf("1.000000000000\n");
}
else
{
cnt = ;
dfs(, known);
fenmu = ;
for (int i = ; i <= unknown; i++)
fenmu *= ;
printf("%.12lf\n", (double)cnt/(double)fenmu);
}
}
return ;
}

codeforces 476B.Dreamoon and WiFi 解题报告的更多相关文章

  1. codeforces 476C.Dreamoon and Sums 解题报告

    题目链接:http://codeforces.com/problemset/problem/476/C 题目意思:给出两个数:a 和 b,要求算出 (x/b) / (x%b) == k,其中 k 的取 ...

  2. CodeForces - 476B -Dreamoon and WiFi(DFS+概率思维)

    Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands throug ...

  3. Codeforces Educational Round 92 赛后解题报告(A-G)

    Codeforces Educational Round 92 赛后解题报告 惨 huayucaiji 惨 A. LCM Problem 赛前:A题嘛,总归简单的咯 赛后:A题这种**题居然想了20m ...

  4. Codeforces Round #382 (Div. 2) 解题报告

    CF一如既往在深夜举行,我也一如既往在周三上午的C++课上进行了virtual participation.这次div2的题目除了E题都水的一塌糊涂,参赛时的E题最后也没有几个参赛者AC,排名又成为了 ...

  5. codeforces 507B. Amr and Pins 解题报告

    题目链接:http://codeforces.com/problemset/problem/507/B 题目意思:给出圆的半径,以及圆心坐标和最终圆心要到达的坐标位置.问最少步数是多少.移动见下图.( ...

  6. codeforces 500B.New Year Permutation 解题报告

    题目链接:http://codeforces.com/problemset/problem/500/B 题目意思:给出一个含有 n 个数的排列:p1, p2, ..., pn-1, pn.紧接着是一个 ...

  7. codeforces B. Xenia and Ringroad 解题报告

    题目链接:http://codeforces.com/problemset/problem/339/B 题目理解不难,这句是解题的关键 In order to complete the i-th ta ...

  8. codeforces 462C Appleman and Toastman 解题报告

    题目链接:http://codeforces.com/problemset/problem/461/A 题目意思:给出一群由 n 个数组成的集合你,依次循环执行两种操作: (1)每次Toastman得 ...

  9. codeforces 460A Vasya and Socks 解题报告

    题目链接:http://codeforces.com/problemset/problem/460/A 题目意思:有一个人有 n 对袜子,每天早上会穿一对,然后当天的晚上就会扔掉,不过他会在 m 的倍 ...

随机推荐

  1. asp.net 实现在线打印功能,jQuery打印插件PrintArea实现自动分页

    使用的组件:jQuery打印插件PrintArea,有兴趣的可以研究一下. 使用方法略过,这里将介绍如何实现打印多页是可以分页. 现在提供两种方法思路: 1.根据特定的打印机型号和使用的纸张类型,然后 ...

  2. UVa 1347 Tour

    Tour Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Description   Joh ...

  3. HD2255奔小康赚大钱(最大权匹配模板)

    奔小康赚大钱 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Subm ...

  4. log4j使用教程详解(怎么使用log4j2)

    1. 去官方下载log4j 2,导入jar包,基本上你只需要导入下面两个jar包就可以了(xx是乱七八糟的版本号): log4j-core-xx.jar log4j-api-xx.jar 2. 导入到 ...

  5. javaweb学习总结(二十九)——EL表达式

    一.EL表达式简介 EL 全名为Expression Language.EL主要作用: 1.获取数据 EL表达式主要用于替换JSP页面中的脚本表达式,以从各种类型的web域 中检索java对象.获取数 ...

  6. linux下使用 Tomcat 的几个坑

    总结:用sudo su - 后的身份启动tomcat,可选用 bin下的  ./catalina.sh run命令以显示启动过程中可能的报错信息 1.普通用户是无法使用0~1023的熟知端口的,需要 ...

  7. How to Write and Publish a Scientific Paper: 7th Edition(科技论文写作与发表教程)(11.04更新)

    How to Write and Publish a Scientific Paper: 7th Edition(科技论文写作与发表教程)(11.04更新) 重要通知: 最近开题报告已差不多告一段落, ...

  8. gdb命令与调试方法

    单线程 http://www.cnblogs.com/lidabo/p/5629830.html 编译程序一定要加-g选项 gcc -g test.c -o test 进入gdb调试:gdb 程序名 ...

  9. WebService中方法的相关注意事项

    2014-11-14 在WebService中定义方法,有一些注意的地方: (1) 方法上面需要增加 [WebMethod] 属性,标志该方法是一个WebService方法: (2)方法的返回值可以为 ...

  10. C语言计算任意数的任意次方

    #include "stdio.h" #include"stdlib.h" #define max 500 void yiwei(int *a,int n,in ...