Dreamoon and WiFi

【CodeForces 476B】 Dreamoon and WiFi(组合概率) B. Dreamoon and WiFi time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Dreamoon is standing at the position 阅读详情


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:

  1. Go 1 unit towards the positive direction, denoted as '+'
  2. 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?

Input

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

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.

Sample test(s)
input
++-+-
+-+-+
output
1.000000000000
input
+-+-
+-??
output
0.500000000000
input
+++
??-
output
0.000000000000
Note

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.

n个字符,然后接受到的样子也是n个,然后判断多少概率是保证结果没有错的。即字符个数相等就可以。其实就是一个数学题。首先看原来的+和-个数,再算后来的+-?个数,因为只有2种字符,所以一个确定时,另一个也就确定了。即m中取n的排列方式,然后写一个函数来表示一下。最后用符合的例子除以总例子,就是概率了。

#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int main()
{
	char a[12], b[12];
	int i, j, m, n, pre1, pre2, temp1, temp2, temp3, len1, len2, temp, c1, c2, pre;
	double ans;
	scanf("%s", a); getchar();
	scanf("%s", b);
	len1 = strlen(a); len2 = strlen(b);
	pre1 = pre2 = temp1 = temp2 = temp3 = 0;
	for (i = 0; i < len1; i++)
	{
		if (a[i] == '+')
			pre1++;
		else
			pre2++;
	}
	for (i = 0; i < len2; i++)
	{
		if (b[i] == '+')
			temp1++;
		else if (b[i] == '-')
			temp2++;
		else temp3++;
	}

	if (temp1 == pre1&&temp2 == pre2)
		cout << "1.000000000000\n";
	else if (temp3 == 0)
		cout << "0.000000000000\n";
	else if (temp1 + temp3 < pre1)
		cout << "0.000000000000\n";
	else if (temp2 + temp3 < pre2)
		cout << "0.000000000000\n";
	else
	{
		temp1 = pre1 - temp1;
		temp2 = pre2 - temp2;
		if (temp1 == 0 || temp2 == 0)
			temp = 1;
		else
		{
			c1 = 1; c2 = 1;
			for (i = temp3; i > temp3 - temp1; i--)
				c1 = c1*i;
			for (i = 1; i <= temp1; i++)
				c2 = c2*i;
			temp = c1 / c2;
		}
		pre = 1;
		for (i = 1; i <= temp3; i++)
			pre = pre * 2;
		ans = temp*1.0 / pre;
		printf("%.12lf\n", ans);
	}
	return 0;
}

C++网络编程 - Boost::asio异步网络编程 - 01- boost库源码编译安装 知识的学习在于点滴记录,坚持不懈;知识的学习要有深度和广度,不能只流于表面,坐井观天;知识要善于总结,不仅能够理解,更知道如何表达! 目录 如果需要录屏资料,请私信邮箱shitou3000@qq.com获取。 ... 阅读详情

相关推荐

我想自己组装一台服务器,微调大模型通义千问2.5 Omni 72B,但是我是个人购买,资金非常有限,最省的方案

阶段动作✅ 推理用 GGUF + llama.cpp + 4090 加载 14B INT4✅ 微调训练 Qwen2.5-7B-Chat,使用 LoRA / QLoRA❌ 放弃Qwen2.5-Omni-72B 全量微调(显存需求 >160G,不现实)

AngelCryToo的专栏 2822

Day 51 B. Dreamoon and WiFi

Problem 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

Jackey_tao的博客 221

如何用 Python 实现自动化测试?详细步骤和代码示例

Python自动化测试实战指南 本文系统介绍了使用Python构建自动化测试体系的完整方案。主要内容包括: 环境搭建:Python 3.8+虚拟环境配置,安装pytest、Selenium等核心测试库 分层测试实现: 单元测试:通过计算器示例演示pytest断言和异常测试 API测试:使用requests库进行RESTful接口验证 UI测试:Selenium WebDriver实现网页交互测试 高级特性: 使用fixture管理测试依赖 参数化实现数据驱动测试 生成HTML和Allure测试报告 GitH

m0_64424835的博客 448

Dreamoon and WiFi(组合数学)

题目链接 题目大意 就是给定两个字符串,第一个字符串由”+”,”-“组成,第二个字符串由”+”,”-“,”?”组成,“+”代表加1,”-“代表减一,“?”代表可取正也可取负,问第二个字符串的位置和第一个字符串相等的概率是多少。 我一开始的想法是把(+1,-1)^n 看成和二项式定理一样的展开始式,只不过把乘法改为加法,然后得到公式 c(n,0)(n+(-1)0)+c(n,1)(n-1+...

博採眾長 9328

Vue+ECharts-GL 3D地图实战:5层叠加打造炫酷中国地图(附完整代码)

本文详细介绍了如何利用Vue和ECharts-GL构建具有强烈立体感的3D中国地图。通过5层图层的巧妙叠加与样式调校,实现了从背景阴影到交互高光的完整视觉层次,并整合了动态飞线与散点标记。文章提供了完整的代码实现、核心配置解析以及性能优化与视觉调优的实战技巧,帮助开发者快速打造专业级的交互式地图可视化应用。

d6e7f8g9h的博客 649

视频动作识别、行为识别、时空动作检测数据集整理(持续更新)

动作、行为、事件 在计算机视觉的相关研究中,人体的动作、行为识别是一个基础研究问题。但目前识别、检测人类的动作/行为仍然是一个巨大的挑战。这里整理下当前相关的细分任务、数据集和开源代码(持续更新中)。

人工智能算法与工程实践 3万+

codeforces 普及--

Dreamoon站在位置0,他想知道Wifi在哪儿,于是Drazil给他发了条短信告诉他怎么走,‘+‘代表向前走一个,’-‘代表向后走一格。如果不可能,输出 −1 输入 两个正整数 n,m (n<=10000,m<=10) 输出 按要求输出。有五个人在玩游戏 每个人一开始有 b 个硬币 有一种操作是把一个硬币给另一个人 给你所有人经过若干次操作的硬币数 0≤c[i]≤100)求正整数 b,若无解输出 −1。求l<=a<b<c<=r,且gcd(a,b)=gcd(b,c)=1,gcd(a,c)!

weixin_46800709的博客 615

ClickHouse分布式表原理:大数据分片存储与查询

我是一名资深大数据工程师,专注于ClickHouse优化和分布式架构设计。拥有5年以上大数据开发经验,曾为多家电商、金融公司提供ClickHouse解决方案。欢迎关注我的博客(),一起探讨大数据技术!留言互动:你在使用ClickHouse分布式表时遇到过什么问题?欢迎在评论区分享,我会一一解答!

AI大模型应用之禅 959

B. Dreamoon and WiFi

http://codeforces.com/problemset/problem/476/B 题意:给两个‘+’‘-’字符串,第二次串有'?'可+,-;问第二个串到第一串概率; 思路:(1)dfs,记录可行个数;(2)排列组合;(3)dp[i][j],串的i位置在坐标j的概率 dfs: #include&lt;bits/stdc++.h&gt; #include&lt;algorit...

newhonor 312

optee技术简介

OP-TEE(Open Portable Trusted Execution Environment)是一种开源的可信执行环境(TEE),专为ARM TrustZone架构设计。TEE是一种独立的执行环境,运行在主操作系统之外,为敏感任务提供安全的计算空间,如加密、身份验证、密钥管理等。

baron-周贺贺-代码改变世界ctw 1279

MicroCap声学仿真介绍(六)-入耳式耳机仿真

从上图可以看出,后腔开了泄声孔后,振膜的最大位移从4.8um提升到了10um,振膜位移增加了一倍。在实际应用中,一般耳机的前腔和后腔都需要开泄声孔,开孔的大小和调音网布的阻尼需要根据客户的要求以及仿真的结果进行权衡选择。接着在主界面放置电阻、电感、电容,电阻值为Rms,电感值为Mms,电容值为Cms,如下图。假设后腔泄声孔的直径为1.2mm,宽度为0.3mm,对应调音网的阻抗为5.5e8欧姆。假设前腔泄声孔的直径为1.2mm,宽度为0.3mm,对应调音网的阻抗为5.5e8欧姆。

山无忧的博客 1800

Dreamoon and WiFi CodeForces - 476B

Dreamoon and WiFi CodeForces - 476B题目描述 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.E

退役的铜牌狗 684

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

F - Dreamoon and WiFi 组合数学

F - Dreamoon and WiFi Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 476B Description Dreamoon is standing at the p

Believe in the Future的专栏 749

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

CF 272B Dreamoon and WiFi

B. Dreamoon and WiFi time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Dreamoon is standing at the position 0 on a numbe

? 608

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

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 standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dr...

weixin_30762087的博客 151

Dreamoon and WiFi ???下同一位置的概率

B. Dreamoon and WiFi time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Dreamoon is standing at the position 0 

雷_u013188850的专栏 921

Codeforces Round #272 (Div. 2)-B. Dreamoon and WiFi

http://codeforces.com/contest/476/problem/BB. Dreamoon and WiFitime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputDreamoon is standing at the positio...

weixin_30436891的博客 139

Codeforces 476B Dreamoon and WiFi

说好的用dp呢!!!结果dfs一遍就过了 题意大致是,给你两个字符串,一个字符串只由‘+’和‘-’构成,另外一个字符由‘+’、‘-’和‘?’构成,‘?’可能是‘+’也可能是‘-’,题目要求的就是如何将问号改变使得该字符串与另一个字符串‘+’和‘-’数目完全一样的概率 两个字符串的长度都不超过10,所以O(2^N)的复杂度是可以承受的 #include #include #include

BacktoWin 565

B. Dreamoon and WiFi(Codeforces Round 272)

B. Dreamoon and WiFi time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Dreamoon is standing at the posit...

weixin_34249678的博客 106

B. Dreamoon and WiFi dfs 概率

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 tw...

loooooog的博客 316

codeforces 476B Dreamoon and WiFi

点击打开链接 B. Dreamoon and WiFi time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Dreamoon is standing at t

zhang__liuchen的博客 311

476B. Dreamoon and WiFi

B. Dreamoon and WiFi:题目链接 题意:给你一个正常的走向,在给你一个虚假和不确定的走向,问到达的可能性 #include <bits/stdc++.h> using namespace std; string str1, str2; double C(double A, double B) { double res = 1.0; for (int i = A - B + 1; i <= A; i++) { res *= 1.0

weixin_51771856的博客 197
上一篇: DZY Loves Chessboard
下一篇: Two Buttons
Techay
博客等级 码龄11年 11粉丝 174原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值