• 题意:给你一个只含\(+\)和\(-\)的字符串,统计它的加减和,然后再给你一个包含\(+,-,?\)的字符串,其中\(?\)可以表示为\(+\)或\(-\),问有多少种情况使得第二个字符串的加减和等于第一个.

  • 题解:首先我们统计第一个字符串的和,然后统计第二个字符串的加减和以及\(?\)的个数,然后对于\(?\)我们进行二进制枚举,枚举它的所有可能情况的和,再加上第二个字符串的和每次判断一下是否和第一个相等即可.

  • 代码:

    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 (暴力二进制枚举)的更多相关文章

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

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

  3. Codeforces Round #272 (Div. 2) E. Dreamoon and Strings 动态规划

    E. Dreamoon and Strings 题目连接: http://www.codeforces.com/contest/476/problem/E Description Dreamoon h ...

  4. Codeforces Round #272 (Div. 2) D. Dreamoon and Sets 构造

    D. Dreamoon and Sets 题目连接: http://www.codeforces.com/contest/476/problem/D Description Dreamoon like ...

  5. Codeforces Round #272 (Div. 2) A. Dreamoon and Stairs 水题

    A. Dreamoon and Stairs 题目连接: http://www.codeforces.com/contest/476/problem/A Description Dreamoon wa ...

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

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

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

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

随机推荐

  1. 【JS学习】数组过滤方法的使用filter

    前言:本博客系列为学习后盾人js教程过程中的记录与产出,如果对你有帮助,欢迎关注,点赞,分享.不足之处也欢迎指正,作者会积极思考与改正. 使用效果: 可以返回参数函数为真的值 //情景:实现从stu数 ...

  2. Python绘制雷达图(俗称六芒星)

    原文链接:https://blog.csdn.net/Just_youHG/article/details/83904618 背景 <Python数据分析与挖掘实战> 案例2–航空公司客户 ...

  3. 配置 Docker 镜像加速源地址

    docker 安装官方文档 根据实例的操作系统类型,参考相应的文档进行安装. 查看 linux 是 CentOS 还是 Ubuntu uname -a #查看系统信息 lsb_release -a # ...

  4. 【Python】部署上手App后端服务器 - Linux环境搭建安装Python、Tornado、SQLAlchemy

    基于阿里云服务器端环境搭建 文章目录 基于阿里云服务器端环境搭建 配置开发环境 安装 Python 3.8.2 安装 Tornado 安装 MySQL 安装 mysqlclient 安装 SQLAlc ...

  5. django ajax应用

    ajax: 什么是ajax,有什么作用: 以前我们在页面向后台提交数据的时候都是使用from表单,这样的提交会在提交的时候将整个页面全部刷新,如果你在填写表单的时候提交之后发现某个数据不对,但是你已提 ...

  6. 数据库 | 001-MySQL梳理系列(一)

    MySQL基本组成 SQL执行流程 Server 层主要包括连接器.查询缓存.分析器.优化器.执行器,包含了MySQL主要的很多核心功能,以及所有的内置函数.存储过程.触发器.视图等,其实就是所有跨存 ...

  7. NAT模式、路由模式、桥接模式的区别

    NAT模式 NAT模式概述 NAT是"Network Address Translation"的缩写,中文意思是"网络地址转换",它允许一个整体机构以一个公用I ...

  8. 通过 profiling 定位 golang 性能问题 - 内存篇 原创 张威虎 滴滴技术 2019-08-02

    通过 profiling 定位 golang 性能问题 - 内存篇 原创 张威虎 滴滴技术 2019-08-02

  9. https://design-patterns.readthedocs.io/zh_CN/latest/index.html

    图说设计模式 - Graphic Design Patterns https://design-patterns.readthedocs.io/zh_CN/latest/index.html

  10. 流量染色与gRPC服务托管 微服务协作开发、灰度发布之流量染色 灰度发布与流量染色

    大规模微服务场景下灰度发布与流量染色实践 https://mp.weixin.qq.com/s/UBoRKt3l91ffPagtjExmYw [go-micro]微服务协作开发.灰度发布之流量染色 - ...