牛客网多校赛第七场--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的个数,然后我们从最后 ...
随机推荐
- ffmpeg 编解码详细过程
ffmpeg编解码详细过程 bobbypollo 转:ffmpeg编解码详细过程 原文地址:ffmpeg编解码详细过程(转)作者:心在飞翔原文出处: http://www.360doc.com ...
- linux -- Ubuntu查看修改mysql的登录名和密码、安装phpmyadmin
安装好mysql后,在终端输入 mysql -u root -p 按回车,输入密码后提示access denied......ues password YES/NO的错误 原因是用户名或密码不对! 查 ...
- postman从入门到精通
今天总监让我给测试同事们培训postman,使用过postman的朋友应该知道,这个简直就是前后端接口调试神器.根据平时的经验以及自己到网上看了相关的帖子,对于postman又有了新的认识. post ...
- vc 获取 硬盘序列号 和 cpu
vc 获取 硬盘序列号 和 cpu 唯一iD的方法?如题---------网上找来很多资料 也没找到, 要支持xp win7 32/64 系统下都能获取 硬盘序列号 和cpu ID 哪位朋友帮帮忙: ...
- Webpack vs Gulp(转载)
理想的前端开发流程 在说构建工具之前得先说说咱期望的前端开发流程是怎样的? 写业务逻辑代码(例如 es6,scss,pug 等) 处理成浏览器认识的(js,css,html) 浏览器自动刷新看到效果 ...
- NHibernate初学六之关联多对多关系
1:创建三张表T_Course.T_Student.T_Middle:其中一个学生可以对应多个课程,一个课程也可以对应多个学生,用T_Middle存放它们的关系内容: CREATE TABLE [db ...
- 单选按钮选中指定value值
$("input[name='BlogStatus'][value='" + rep.data.Status + "']").prop("checke ...
- Don‘t talk.Just do it.
对于算法,自己掌握的还是不多.并且我发现对于一个算法的理解非常重要.也许你会发现你貌似会用某总算法但是,他一旦变形,自己就无从下手. 还有就是对于算法.最好每次都自己敲,这样不仅能添加对于算法的熟度. ...
- Android移动网络如何抓取数据包
1)下载tcpdump工具 tcpdump(dump the traffic on a network)是Linux中强大的网络数据采集分析工具之一,可以将网络中传送的数据包头完全截获下来提供分析.它 ...
- NodeJS-004-Oracle驱动编译
一.参考文章 https://community.oracle.com/docs/DOC-931127 http://www.cnblogs.com/stone_w/p/4794747.html ht ...