牛客网多校赛第七场--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 4 官方文档学习(十一)Web MVC 框架之URI Builder
http://docs.spring.io/spring/docs/current/spring-framework-reference/html/mvc.html#mvc-uri-building ...
- JavaScript 杂乱的小总结
基本类型只有String.number.boolean.null.undefined,还有一个Object.存在装箱类型,不过后台自动转换. 通过new创建对象时,如果没有参数,可以省略“()”.-- ...
- 二叉查找树 _ 二叉排序树 _ 二叉搜索树_C++
一.数据结构背景+代码变量介绍 二叉查找树,又名二叉排序树,亦名二叉搜索树 它满足以下定义: 1.任意节点的子树又是一颗二叉查找树,且左子树的每个节点均小于该节点,右子树的每个节点均大于该节点. 2. ...
- 多媒体开发之h264中的sps---sps信息提取之分辨率宽高提取2
-------------------author:pkf -----------------------------time:2015-8-20 -------------------------- ...
- Python3的tcp socket接收不定长数据包接收到的数据不全。
Python Socket API参考出处:http://blog.csdn.net/xiangpingli/article/details/47706707 使用socket.recv(pack_l ...
- jquery-根据现有结果集得到另一个结果集(后代、祖先或兄弟元素)
1.获取后代元素 1)children() 不传参数:得到结果集内所有元素的子元素 传入选择器:得到结果集内元素的匹配传入选择器的子元素 2)find() 传入选择器:得到匹配选择器的后代元素 传入j ...
- 五步让你玩转CocoaPods
1 安装和升级 $ sudo gem install cocoapods $ pod setup 2 更换为taobao的源 $ gem sources -r https://rubygems.or ...
- asp.net线程批量导入数据时通过ajax获取执行状态
最近因为工作中遇到一个需求,需要做了一个批量导入功能,但长时间运行没个反馈状态,很容易让人看了心急,产生各种臆想!为了解决心里障碍,写了这么个功能. 通过线程执行导入,并把正在执行的状态存入sessi ...
- kendo-ui的使用和开发自己的组件
摘要: 前面介绍了一款非常不错的前端框架kendo-ui,如果你想阅读,请点这里.通过使用它一段时间,感觉是非常好用.下面就介绍一下如何使用它和开发自己的组件 引入: 只需要引进下面三个文件即可 ke ...
- Oracle中的三种循环(For、While、Loop)
from:http://jingyan.baidu.com/article/c275f6ba38036ae33c756773.html GOTO用法,以下是SQL源码: DECLARE x numb ...