Codeforces Round #272 (Div. 2) B. Dreamoon and WiFi (暴力二进制枚举)
题意:给你一个只含\(+\)和\(-\)的字符串,统计它的加减和,然后再给你一个包含\(+,-,?\)的字符串,其中\(?\)可以表示为\(+\)或\(-\),问有多少种情况使得第二个字符串的加减和等于第一个.
题解:首先我们统计第一个字符串的和,然后统计第二个字符串的加减和以及\(?\)的个数,然后对于\(?\)我们进行二进制枚举,枚举它的所有可能情况的和,再加上第二个字符串的和每次判断一下是否和第一个相等即可.
代码:
char s[N],t[N]; int main() {
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
scanf("%s",s);
getchar();
scanf("%s",t);
double res=0;
for(int i=0;i<strlen(s);++i){
if(s[i]=='+') res++;
else res--;
}
double cnt=0;
double ans=0;
double sum=0;
for(int i=0;i<strlen(t);++i){
if(t[i]=='+') cnt++;
else if(t[i]=='-') cnt--;
else{
sum++;
}
}
if(sum==0){
if(cnt==res) printf("1.000000000\n");
else printf("0.000000000\n");
return 0;
}
for(int i=1;i<=(1<<(int)sum);++i){
int tmp=0;
for(int j=0;j<sum;++j){
if(i&(1<<j)) tmp++;
else tmp--;
}
if(cnt+tmp==res) ans++;
}
sum=pow(2,sum);
printf("%.9f\n",ans/sum); return 0;
}
Codeforces Round #272 (Div. 2) B. Dreamoon and WiFi (暴力二进制枚举)的更多相关文章
- 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)-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) E. Dreamoon and Strings 动态规划
E. Dreamoon and Strings 题目连接: http://www.codeforces.com/contest/476/problem/E Description Dreamoon h ...
- Codeforces Round #272 (Div. 2) D. Dreamoon and Sets 构造
D. Dreamoon and Sets 题目连接: http://www.codeforces.com/contest/476/problem/D Description Dreamoon like ...
- Codeforces Round #272 (Div. 2) A. Dreamoon and Stairs 水题
A. Dreamoon and Stairs 题目连接: http://www.codeforces.com/contest/476/problem/A Description Dreamoon wa ...
- Codeforces Round #272 (Div. 2) E. Dreamoon and Strings dp
题目链接: http://www.codeforces.com/contest/476/problem/E E. Dreamoon and Strings time limit per test 1 ...
- Codeforces Round #272 (Div. 1) A. Dreamoon and Sums(数论)
题目链接 Dreamoon loves summing up something for no reason. One day he obtains two integers a and b occa ...
- Codeforces Round #272 (Div. 2)-C. Dreamoon and Sums
http://codeforces.com/contest/476/problem/C C. Dreamoon and Sums time limit per test 1.5 seconds mem ...
- Codeforces Round #272 (Div. 2)-A. Dreamoon and Stairs
http://codeforces.com/contest/476/problem/A A. Dreamoon and Stairs time limit per test 1 second memo ...
随机推荐
- 天梯赛练习 L3-010 是否完全二叉搜索树 (30分) 数组建树模拟
题目分析: 本题的要求是将n个数依次插入一个空的二叉搜索树(左大右小,且没有重复数字),最后需要输出其层次遍历以及判断是否是完全二叉搜索树,通过观察我们发现, 如果这个树是用数组建立的,那么最后输出的 ...
- LeetCode617. 合并二叉树
题目 1 class Solution { 2 public: 3 TreeNode* mergeTrees(TreeNode* t1, TreeNode* t2) { 4 if(!t1 && ...
- Upload - Labs (下)
Pass - 11: 1.查看源代码,发现进行了一次对后缀名替换成空格,因此考虑双写绕过, 2.上传成功, 关键代码: $is_upload = false; $msg = null; if (iss ...
- ProBuilder快速原型开发技术 ---ProBuilder基础操作
在游戏开发.虚拟现实等三维仿真领域,Unity目前是国内外最为知名的开发引擎.随着版本的不断提升与完善,目前Unity2020等最新版本,又增加了很多令人惊奇的功能. Unity内置的ProBuild ...
- 【pytest】(十二)参数化测试用例中的setup和teardown要怎么写?
还是一篇关于pytest的fixture在实际使用场景的分享. fixture我用来最多的就是写setup跟teardown了,那么现在有一个用例是测试一个列表接口,参数化了不同的状态值传参,来进行测 ...
- java之 Request
0x01.Request 什么是request 在Servlet API中,定义了一个HttpServletRequest接口,它继承自ServletRequest接口,专门用来封装HTTP请求消息. ...
- 浅析Linux启动流程
Linux系统启动流程 Linux 系统的启动,从计算机开机通电自检开始,一直到登陆系统,需要经历多个过程.了解 Linux 的启动过程,有助于了解 Linux 系统的结构,也对系统的排错有很大的帮助 ...
- Go Concurrency Patterns: Context At Google, we require that Go programmers pass a Context parameter as the first argument to every function on the call path between incoming and outgoing requests.
小结: 1. Background is the root of any Context tree; it is never canceled: 2. https://blog.golang. ...
- SpringBoot+Spring常用注解总结
为什么要写这篇文章? 最近看到网上有一篇关于 SpringBoot 常用注解的文章被转载的比较多,我看了文章内容之后属实觉得质量有点低,并且有点会误导没有太多实际使用经验的人(这些人又占据了大多数). ...
- LOJ10145郁闷的出纳员
传送门:https://loj.ac/problem/10145 简单的平衡树 ------------------------------------ 1 #include<bits/stdc ...