牛客网多校赛第七场--C Bit Compression【位运算】【暴力】
链接:https://www.nowcoder.com/acm/contest/145/C
来源:牛客网
时间限制:C/C++ 2秒,其他语言4秒
空间限制:C/C++ 262144K,其他语言524288K
Special Judge, 64bit IO Format: %lld
题目描述
A binary string s of length N = 2n is given. You will perform the following operation n times :
- Choose one of the operators AND (&), OR (|) or XOR (^). Suppose the current string is S = s1s2...sk. Then, for all , replace s2i-1s2i with the result obtained by applying the operator to s2i-1 and s2i. For example, if we apply XOR to {1101} we get {01}.
After n operations, the string will have length 1.
There are 3n ways to choose the n operations in total. How many of these ways will give 1 as the only character of the final string.
输入描述:
The first line of input contains a single integer n (1 ≤ n ≤ 18).
The next line of input contains a single binary string s (|s| = 2n). All characters of s are either 0 or 1.
输出描述:
Output a single integer, the answer to the problem.
示例1
输入
2
1001
输出
4
说明
The sequences (XOR, OR), (XOR, AND), (OR, OR), (OR, AND) works.
发现读题的时候理解有点偏差
每次操作应该是固定的 也就是说从头到尾做一次操作 这个位运算符都是一样的
暴力也不会.....用map优化的暴力
mp[i]表示关键字的字符串长度都是2^i
哦值得一提 牛客网c++11TLE c++14能过
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#define inf 0x3f3f3f3f
using namespace std;
int n;
const int maxn = 20;
string s;
map<string, int> mp[maxn];
int main()
{
while(scanf("%d", &n) != EOF){
cin>>s;
mp[n][s] = 1;
for(int i = n; i >= 1; i--){
map<string, int>::iterator it;
for(it = mp[i].begin(); it != mp[i].end(); it++){
s = it->first;
int cnt = it->second;
int len = 1 << i;
string sa = "", sb = "", sc = "";
for(int j = 0; j < len; j += 2){
sa += ((s[j] - '0') & (s[j + 1] - '0')) + '0';
sb += ((s[j] - '0') | (s[j + 1] - '0')) + '0';
sc += ((s[j] - '0') ^ (s[j + 1] - '0')) + '0';
}
mp[i - 1][sa] += cnt;
mp[i - 1][sb] += cnt;
mp[i - 1][sc] += cnt;
}
}
printf("%d\n", mp[0]["1"]);
}
return 0;
}
牛客网多校赛第七场--C Bit Compression【位运算】【暴力】的更多相关文章
- 牛客网多校赛第七场J--Sudoku Subrectangle
链接:https://www.nowcoder.com/acm/contest/145/J 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言6553 ...
- 牛客网多校赛第七场A--Minimum Cost Perfect Matching【位运算】【规律】
链接:https://www.nowcoder.com/acm/contest/145/A 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524 ...
- 牛客网多校赛第9场 E-Music Game【概率期望】【逆元】
链接:https://www.nowcoder.com/acm/contest/147/E 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524 ...
- 牛客网-湘潭大学校赛重现H题 (线段树 染色问题)
链接:https://www.nowcoder.com/acm/contest/105/H来源:牛客网 n个桶按顺序排列,我们用1~n给桶标号.有两种操作: 1 l r c 区间[l,r]中的每个桶中 ...
- 牛客网多校赛第九场A-circulant matrix【数论】
链接:https://www.nowcoder.com/acm/contest/147/A 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524 ...
- 牛客网多校训练第四场C sequence
(牛客场场有笛卡尔树,场场都不会用笛卡尔树...自闭,补题心得) 题目链接:https://ac.nowcoder.com/acm/contest/884/C 题意:给出两个序列a,b,求max{mi ...
- 牛客网多校训练第三场 C - Shuffle Cards(Splay / rope)
链接: https://www.nowcoder.com/acm/contest/141/C 题意: 给出一个n个元素的序列(1,2,...,n)和m个操作(1≤n,m≤1e5),每个操作给出两个数p ...
- 牛客网多校训练第三场 A - PACM Team(01背包变形 + 记录方案)
链接: https://www.nowcoder.com/acm/contest/141/A 题意: 有n(1≤n≤36)个物品,每个物品有四种代价pi,ai,ci,mi,价值为gi(0≤pi,ai, ...
- 牛客网多校训练第八场A All one Matrix
题目链接:https://ac.nowcoder.com/acm/contest/888/A 题意:求出有多少个不被包含的全1子矩阵 解题思路:首先对列做处理,维护每个位置向上1的个数,然后我们从最后 ...
随机推荐
- 解析 Spring ConversionService
弄了张图,方便以后一眼能想起是怎么回事. 前提,看这里:Spring Framework 官方文档学习(四)之Validation.Data Binding.Type Conversion(二) .
- Android Studio怎样查看资源或者函数在哪些类中被引用
很多人在做完Keymap匹配到Eclispe快捷键后,发现查看资源或者函数在哪些地方被引用的快捷键"Ctrl+Shift+G"不灵 了.你选中某个函数后,使用这个快捷键.发现仅仅会 ...
- centos6.5的软件安装,用户管理等
1.软件的安装命令: 第一种:以 软件名.rpm 为结尾的二进制文件,这样的文件的安装 rpm -ivh 软件名.rpm i 是 install v 是校验 h 进度 卸载软件 是 rpm -e 软件 ...
- IOS 命令行编译
转自:简书 IOS 命令行编译 发表于 IOS2013-08-17 07:07 字数: 583 阅读量: 61 This document will note about the ios comm ...
- 基于Nginx反向代理及负载均衡
基于Nginx反向代理及负载均衡 参考:http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass 只要没有被启用,默认就是 ...
- 第五章 使用 SqlSession(MyBatis)
在 MyBatis 中,你可以使用 SqlSessionFactory 来创建 SqlSession.一旦你获得一个 session 之后,你可以使用它来执行映射语句,提交或回滚连接,最后,当不再需要 ...
- 电脑开机提示 NTLDR is missing
电脑开机,黑屏并提示NTLDR is missing Press Ctrl+Alt+Del to restart,并且反复重启都不行,这是怎么回事呢?首先我们来分析下这段英语的含义:NTLDR是指NT ...
- Windows中目录及文件路径太长无法删除的解决方法
用windows自带的命令解决 win7以上的系统有 robocopy 命令 http://www.jianshu.com/p/95a269951a1b 导致目录太深的原因就是用node中的node ...
- 第三章 Spring.Net 环境准备和搭建
在前面一章我们介绍了依赖注入,控制反转的概念.接下来我们来真正动手搭建一下Spring.Net的环境,看一下Spring.Net 中的控制反转和依赖注入是什么样子. 3.1 Spring.Net 下 ...
- android开发源代码分析--多个activity调用多个jni库的方法
android开发源代码分析--多个activity调用多个jni库的方法 有时候,我们在开发android项目时会遇到须要调用多个native c/jni库文件,下面是本人以前实现过的方法,假设有知 ...