题目链接: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. python 类型之 set

    python的set和其他语言类似, 是一个无序不重复元素集, 基本功能包括关系测试和消除重复元素. 集合对象还支持union(联合), intersection(交), difference(差)和 ...

  2. 从svn服务器自动同步到另一台服务器

    需求场景 A commit B post-commit C (workstation) --------------> (svn server) ---------------------> ...

  3. 【BZOJ-1452】Count 树状数组 套 树状数组

    1452: [JSOI2009]Count Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 1769  Solved: 1059[Submit][Stat ...

  4. PowerDesigner更改数据库类型

    如图,直入:

  5. UvaLive 5026 Building Roads

    传送门 Time Limit: 3000MS Description There is a magic planet in the space. There is a magical country ...

  6. Struts2拦截器的应用

    拦截器类 public class AdminInterceptor extends AbstractInterceptor { private static final long serialVer ...

  7. Java调用动态库方法说明-最详细

    Java不能直接调用由c或者c++写得dll(TF_ID.dll),所以只能采用jni得方法,一步一步生成符合规范得dll文件(假设叫FANGJIAN.dll),在FANGJIAN.dll这个文件里来 ...

  8. svn命令在linux下的使用

    svn命令在linux下的使用 SVN软件版本管理 三 12th, 2008 转载本站文章请注明,转载自:扶凯[[url]http://www.php-oa.com[/url]] 本文链接: [url ...

  9. C++ 中宏的使用 --来自:http://blog.csdn.net/hgl868/article/details/7058906

    宏在代码中的使用实例: g_RunLog2("Middleware client for Linux, build:%s %s", __DATE__, __TIME__); 下面详 ...

  10. mysql 的设置

    网上的一些文章都已经比较老了,现在版本高了之后,其实配置是很省力的(不考虑什么负载的话) 分享全过程,出了文中提到的安装epel rpmfushion 源指令不同外,其他的过程也适用与Centos 5 ...