大丰收,dfs,bfs,还有我cf的第一次

今年是一个值得纪念的日子,哦应该是昨天和今天凌晨阶段,昨天我我终于攻克了搜索魔咒,在前天迎来了第二周的周赛,在赛题中,我碰到了“初恋”,关于暴搜的。很多时候,我一直想用暴力搜索,我才不管时间,空间,只要我能得出结果就行,可是以前只知道怎么弄,不知道怎么写,好痛苦,但是今天,不知道是不是心诚则灵(自我陶醉中)尽然一起弄懂了,还敲了几道题,想想还是有点小激动,回想起自己第一次听说有acm这回事到现在,已经过去了一年,想着以后自己终于可以理直气壮地说自己在弄acm了(以前一直没敢说,毕竟连dfs和bfs都不会敲,汗颜中,真不知以前是怎么呆下来的),现在展示下成品题

B - Dreamoon and WiFi
Crawling in process... Crawling failed Time Limit:1000MS    Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

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 exceed10 - 9.

Sample Input

Input
++-+-
+-+-+
Output
1.000000000000
Input
+-+-
+-??
Output
0.500000000000
Input
+++
??-
Output
0.000000000000

Sample Output

Hint

For the first sample, both s1 ands2 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 fors2: {"+-++","+-+-", "+--+","+---"} with ending position {+2, 0, 0, -2} respectively. So there are2 correct cases out of 4, so the probability of finishing at the correct position is0.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的暴搜,结果整出的代码惨不忍睹,权当纪念贴下:

以下是自己第一次敲出的dfs,每每看到这个,我就觉得心情爽快,啊哈哈

有了dfs的小试身手,立马向bfs进军,

B

题意:从一个四位素数到另一个四位素数,每次变换一个数字,变换之后仍为素数,最少的步骤。

比如:1033  8179

变换过程:

1033
1733
3733
3739
3779
8779
8179

最少步骤一共是6步。

•SampleInput

      3

    1033 8179

    1373 8017

    1033 1033

•SampleOutput

    6

    7

    0

粗粗看来,我也不知道怎么入手,不过对着bfs的ppt模版,想了想还是可以做的,



值得一说的是,今天我终于突破了cf的0记录,开启了我的cf之路,熬夜打cf的感觉果然很好,不过略有点小伤心,因为少考虑一种情况,结果就跪了(本来如果仔细点根本可以来个开门红的),不过即便是这样,自己心里还是挺开心的,嗯 今天就先这样了,困了,睡了 世界



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值