牛客网多校赛第七场--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的个数,然后我们从最后 ...
随机推荐
- C++函数类型
继续上一篇 #include <iostream> using namespace std; void swap1(int &v1, int &v2); typedef v ...
- unity3d绘画手册-------地形各个参数解释
关于Unity3D是什么.我就不多做解释了.由于工作原因,该系列原创教程不定期更新.每月必然有更新.谢谢各位. Unity地形:: 新建地形: <ignore_js_op> 如图在菜单中新 ...
- Java 的JSON、XML转换方法——目录索引(转)
JSON及XML的Java序列化.反序列化(转换)在WebService.Ajax数据传递中,用得比较多.如:在用ExtJS.jQuery.mootools以及一些WebService时,你可以需要用 ...
- [LeetCode] Subsets II [32]
题目 Given a collection of integers that might contain duplicates, S, return all possible subsets. Not ...
- python编码问题1
爬虫,新手很容易遇到编码解码方面的问题.在这里总结下. 如果处理不好编码解码的问题,爬虫轻则显示乱码,重则报错UnicodeDecodeError: 'xxxxxx' codec can't deco ...
- 深入分析JavaWeb Item43 -- Struts2开发入门
一.Struts2概述 1.Struts2是什么? Struts2是一个M(模型-域–范围模型)V(View视图)C(控制器)框架(模型2).框架都是一个半成品. 提高开发效率. Struts1是一个 ...
- python2.0_s12_day19_前端结合后端展示客户咨询纪录
接下来就是将后台视图与前端页面结合起来了完成后台系统了.实现前端展示用户列表1.先在base.html代码中把模版中Dashboard下面的内容清空,如下: 具体删除哪些html代码,自己找吧.2.我 ...
- centos 安装 phalcon
git clone --depth 1 --branch phalcon-v2.0.3 https://github.com/phalcon/cphalcon.git cd cphalcon/ext ...
- List自定义排序
List自定义排序我习惯根据Collections.sort重载方法来实现,下面我只实现自己习惯方式.还有一种就是实现Comparable接口. 挺简单的,直接上代码吧. package com.so ...
- 【RF库Collections测试】Copy Dictionary
Name: Copy DictionarySource:Collections <test library>Arguments:[ dictionary ]Returns a copy o ...