B. Dreamoon and WiFi(Codeforces Round 272)
1 second
256 megabytes
standard input
standard output
Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them.
Each command is one of the following two types:
- Go 1 unit towards the positive direction, denoted as '+'
- Go 1 unit towards the negative direction, denoted as '-'
But the Wi-Fi condition is so poor that Dreamoon's smartphone reports some of the commands can't be recognized and Dreamoon knows that some of them might even be wrong though successfully recognized. Dreamoon decides to follow every recognized command and toss
a fair coin to decide those unrecognized ones (that means, he moves to the 1 unit to the negative or positive direction with the same probability 0.5).
You are given an original list of commands sent by Drazil and list received by Dreamoon. What is the probability that Dreamoon ends in the position originally supposed to be final by Drazil's commands?
The first line contains a string s1 —
the commands Drazil sends to Dreamoon, this string consists of only the characters in the set {'+', '-'}.
The second line contains a string s2 —
the commands Dreamoon's smartphone recognizes, this string consists of only the characters in the set {'+', '-', '?'}. '?' denotes
an unrecognized command.
Lengths of two strings are equal and do not exceed 10.
Output a single real number corresponding to the probability. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 9.
++-+-
+-+-+
1.000000000000
+-+-
+-??
0.500000000000
+++
??-
0.000000000000
For the first sample, both s1 and s2 will
lead Dreamoon to finish at the same position + 1.
For the second sample, s1 will
lead Dreamoon to finish at position 0, while there are four possibilites for s2:
{"+-++", "+-+-", "+--+","+---"}
with ending position {+2, 0, 0, -2} respectively. So there are 2 correct cases out of 4,
so the probability of finishing at the correct position is 0.5.
For the third sample, s2 could
only lead us to finish at positions {+1, -1, -3}, so the probability to finish at the correct position + 3 is 0.
将全部可能的路径dfs推断一遍即可了。
代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
char s1[20],s2[20];
int acou=0,dao=0,sum=0;
int n1,n2;
void solve(int n,int at)
{
if(n==n2)
{
if(at==acou)
dao++;
sum++;
return;
}
if(s2[n]=='+')
solve(n+1,at+1);
else if(s2[n]=='-')
solve(n+1,at-1);
else
{
solve(n+1,at+1);
solve(n+1,at-1);
}
} int main()
{
scanf("%s",s1);
scanf("%s",s2);
n1=strlen(s1);
n2=strlen(s2);
for(int i=0;i<n1;i++)
if(s1[i]=='+')
acou++;
else
acou--;
solve(0,0);
printf("%.12f\n",(double)(dao)/(sum));
return 0;
}
B. Dreamoon and WiFi(Codeforces Round 272)的更多相关文章
- A. Dreamoon and Stairs(Codeforces Round #272)
A. Dreamoon and Stairs time limit per test 1 second memory limit per test 256 megabytes input standa ...
- E. Dreamoon and Strings(Codeforces Round #272)
E. Dreamoon and Strings time limit per test 1 second memory limit per test 256 megabytes input stand ...
- D. Dreamoon and Sets(Codeforces Round #272)
D. Dreamoon and Sets time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #272 (Div. 2) 题解
Codeforces Round #272 (Div. 2) A. Dreamoon and Stairs time limit per test 1 second memory limit per ...
- Codeforces Round #272 (Div. 2)-B. Dreamoon and WiFi
http://codeforces.com/contest/476/problem/B B. Dreamoon and WiFi time limit per test 1 second memory ...
- Codeforces Round #272 (Div. 2) B. Dreamoon and WiFi dp
B. Dreamoon and WiFi 题目连接: http://www.codeforces.com/contest/476/problem/B Description Dreamoon is s ...
- Codeforces Round #272 (Div. 2) Dreamoon and WiFi 暴力
B. Dreamoon and WiFi Dreamoon is standing at the position 0 on a number line. Drazil is sending a li ...
- Codeforces Round #272 (Div. 2)
A. Dreamoon and Stairs 题意:给出n层楼梯,m,一次能够上1层或者2层楼梯,问在所有的上楼需要的步数中是否存在m的倍数 找出范围,即为最大步数为n(一次上一级),最小步数为n/2 ...
- Codeforces Round #272 (Div. 2)AK报告
A. Dreamoon and Stairs time limit per test 1 second memory limit per test 256 megabytes input standa ...
随机推荐
- C#使用Redis集群缓存
C#使用Redis集群缓存 本文介绍系统缓存组件,采用NOSQL之Redis作为系统缓存层. 一.背景 系统考虑到高并发的使用场景.对于并发提交场景,通过上一章节介绍的RabbitMQ组件解决.对于系 ...
- 基于HTTP和TFTP的PXE批量自动化安装Linux系统
CentOS 6.5 PXE自动化部署系统 拓扑图如下: 步骤: 1. 安装http服务,上传ISO文件 [root@UCS-1 ~]# yum install httpd –y [root@UCS ...
- wwwtyro/cellophane
wwwtyro/cellophane A dead simple web terminal that gets all of the boilerplate out of the way and le ...
- Boost中timer的简易用法
boost::asio::deadline_timer timer_; timer_(io_service), timer_.expires_from_now(boost::posix_time::s ...
- android动画-动画分类及代码演示样例
原来一直对动画一知半解,仅仅知道依照网上的方法会用即可了,可是自己写起来感觉确实有点费劲,今天最终研究了代码实现,一下子感觉清晰多了.先把总结例如以下,代码中有具体的凝视. 动画分类 1.Peoper ...
- 在Laravel中一步一步创建Packages
首先要看一下Laravel官方文档,这是最新4.2的文档,假设想看中文的话点击此处,基本一样.这个github上的库setup-laravel4-package,也是一步一步介绍怎样创建一个包.并关联 ...
- SVN更改登录用户(转)
一) 原地址:http://www.ixna.net/articles/2606 //证书缓存 $ svn list https://host.example.com/repos/project Er ...
- java7 API详解
Java™ Platform, Standard Edition 7API Specification This document is the API specification for the J ...
- GDAL切割重采样遥感图像
一个小测试程序开发全过程实录,完全新手入门级的实例,如果你还在为处理大影像而发愁,来试试这个称手的工具吧. Imagec 开发日记 2013-6-25 需求: 影像数据切割,重采样 数据切割的要求是简 ...
- iText操作word文档总结
操作word文档的工具有很多,除了iText之外还有POI,但是POI擅长的功能是操作excel,虽然也可以操作word,但是能力有限,而且还有很多的bug,技术并不成熟,下面就重点介绍一种操作wor ...