codeforces 476B.Dreamoon and WiFi 解题报告
题目链接: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 解题报告的更多相关文章
- codeforces 476C.Dreamoon and Sums 解题报告
题目链接:http://codeforces.com/problemset/problem/476/C 题目意思:给出两个数:a 和 b,要求算出 (x/b) / (x%b) == k,其中 k 的取 ...
- 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 ...
- Codeforces Educational Round 92 赛后解题报告(A-G)
Codeforces Educational Round 92 赛后解题报告 惨 huayucaiji 惨 A. LCM Problem 赛前:A题嘛,总归简单的咯 赛后:A题这种**题居然想了20m ...
- Codeforces Round #382 (Div. 2) 解题报告
CF一如既往在深夜举行,我也一如既往在周三上午的C++课上进行了virtual participation.这次div2的题目除了E题都水的一塌糊涂,参赛时的E题最后也没有几个参赛者AC,排名又成为了 ...
- codeforces 507B. Amr and Pins 解题报告
题目链接:http://codeforces.com/problemset/problem/507/B 题目意思:给出圆的半径,以及圆心坐标和最终圆心要到达的坐标位置.问最少步数是多少.移动见下图.( ...
- codeforces 500B.New Year Permutation 解题报告
题目链接:http://codeforces.com/problemset/problem/500/B 题目意思:给出一个含有 n 个数的排列:p1, p2, ..., pn-1, pn.紧接着是一个 ...
- codeforces B. Xenia and Ringroad 解题报告
题目链接:http://codeforces.com/problemset/problem/339/B 题目理解不难,这句是解题的关键 In order to complete the i-th ta ...
- codeforces 462C Appleman and Toastman 解题报告
题目链接:http://codeforces.com/problemset/problem/461/A 题目意思:给出一群由 n 个数组成的集合你,依次循环执行两种操作: (1)每次Toastman得 ...
- codeforces 460A Vasya and Socks 解题报告
题目链接:http://codeforces.com/problemset/problem/460/A 题目意思:有一个人有 n 对袜子,每天早上会穿一对,然后当天的晚上就会扔掉,不过他会在 m 的倍 ...
随机推荐
- 【CodeForces 622A】Infinite Sequence
题意 一个序列是, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5....这样排的,求第n个是什么数字. 分析 第n个位置属于1到k,求出k,然后n-i*(i-1)/ ...
- Spring JdbcTemplate 的使用与学习(转)
紧接上一篇 (JdbcTemplate是线程安全的,因此可以配置一个简单的JdbcTemplate实例,将这个共享的实例注入到多个DAO类中.辅助的文档) Spring DAO支持 http://ww ...
- 洛谷P1508 Likecloud-吃、吃、吃
题目背景 问世间,青春期为何物? 答曰:“甲亢,甲亢,再甲亢:挨饿,挨饿,再挨饿!” 题目描述 正处在某一特定时期之中的李大水牛由于消化系统比较发达,最近一直处在饥饿的状态中.某日上课,正当他饿得头昏 ...
- make_pair
Utilities <utility> 由短小精干的类和函数构成,执行最一般性的工作. 这些工具包括: general types 一些重要的C函数 numeric limits Pair ...
- centos 配置固定ip
centos下网络配置方法(网关.dns.ip地址配置) 来源:互联网 作者:佚名 时间:07-13 00:32:07 [大 中 小] 本文介绍了centos网络配置的方法,centos网络配置主要包 ...
- xcrun: error: active developer path ("/Volumes/Xcode/Xcode-beta.app/Contents/Developer") does not exist, use `xcode-select --swi
xcrun: error: active developer path ("/Volumes/Xcode/Xcode-beta.app/Contents/Developer") d ...
- Java读取word文档,转换为网页
public class Test3 { /** * * @param path * @param paths * @param savepaths */ public static void cha ...
- SQL 两种表复制语句
1.INSERT INTO SELECT语句 语句形式为:Insert into Table2(field1,field2,...) select value1,value2,... from Tab ...
- gnl总结(#,%,$)
Ognl表达式struts标签“%,#,$” 1.什么是Ognl? OGNL(Object-Graphic Navigation Language),对象图道行语言.是一种可以方便操作对象属性的开源表 ...
- jQuery基础细节
使用CDN版的jQuery 用托管在公共CDN(Content Delivery Network,内容分发网络)上的jQuery库,CDN是一种内容分发网络,当用户请求其数据时,CDN ...