当前位置:网站首页>Atcoder beginer contest 261e / / bitwise thinking + DP
Atcoder beginer contest 261e / / bitwise thinking + DP
2022-07-25 12:56:00 【Jakon_】
Topic link :E - Many Operations (atcoder.jp)
The question :
Give a number x, as well as n Operations (ti,ai):
When t = 1 when , take x & a
When t = 2 when , take x | a
When t = 3 when , take x ^ a
And print them separately n Number :x Before proceeding 1 Print after operation , Go further before 2 Print after operation ,... , Go further before n Print after operation .
Ideas :
because x、ai All less than
, Every operation is a bit operation , Then think according to each binary , At most 30 bits , The initial value of each can only be 0、1, Just preprocess it first , Each is initially 0、1 when , Before proceeding i Time (1~n) The value after operation , You can quickly find any number for front i The value after the first operation .
Code :
//dp
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int n, x, t[N], a[N];
bool f[N][30][2]; //fi,j,k: For the second j position , For the initial k Under the circumstances , Before proceeding i The value after the first operation
int main()
{
cin >> n >> x;
for(int i = 1; i <= n; i++) scanf("%d%d", &t[i], &a[i]);
for(int i = 0; i < 30; i++) f[0][i][0] = 0, f[0][i][1] = 1;
for(int i = 1; i <= n; i++)
for(int j = 0; j < 30; j++)
for(int k = 0; k < 2; k++)
if(t[i] == 1) f[i][j][k] = f[i - 1][j][k] & (a[i] >> j & 1);
else if(t[i] == 2) f[i][j][k] = f[i - 1][j][k] | (a[i] >> j & 1);
else if(t[i] == 3) f[i][j][k] = f[i - 1][j][k] ^ (a[i] >> j & 1);
for(int i = 1; i <= n; i++)
{
int res = 0;
for(int j = 0; j < 30; j++) res += f[i][j][x >> j & 1] << j;
printf("%d\n", x = res);
}
return 0;
}边栏推荐
- 使用vsftpd服务传输文件(匿名用户认证、本地用户认证、虚拟用户认证)
- shell基础知识(退出控制、输入输出等)
- 零基础学习CANoe Panel(16)—— Clock Control/Panel Control/Start Stop Control/Tab Control
- 2022.07.24 (lc_6126_design food scoring system)
- LeetCode 1184. 公交站间的距离
- 零基础学习CANoe Panel(12)—— 进度条(Progress Bar)
- If you want to do a good job in software testing, you can first understand ast, SCA and penetration testing
- JS 将伪数组转换成数组
- 什么是CI/CD?
- 深度学习MEMC插帧论文列表paper list
猜你喜欢

Cmake learning notes (II) generation and use of Library

"Wei Lai Cup" 2022 Niuke summer multi school training camp 2 supplementary problem solution (g, J, K, l)

【历史上的今天】7 月 25 日:IBM 获得了第一项专利;Verizon 收购雅虎;亚马逊发布 Fire Phone

【OpenCV 例程 300篇】239. Harris 角点检测之精确定位(cornerSubPix)

2022 年中回顾 | 大模型技术最新进展 澜舟科技

AtCoder Beginner Contest 261E // 按位思考 + dp

Selenium use -- installation and testing

程序员奶爸自制AI喂奶检测仪,预判宝宝饿点,不让哭声影响老婆睡眠

艰辛的旅程

AtCoder Beginner Contest 261 F // 树状数组
随机推荐
交换机链路聚合详解【华为eNSP】
Go: Gin custom log output format
Business visualization - make your flowchart'run'(3. Branch selection & cross language distributed operation node)
A turbulent life
程序员奶爸自制AI喂奶检测仪,预判宝宝饿点,不让哭声影响老婆睡眠
Substance Designer 2021软件安装包下载及安装教程
Implementation of recommendation system collaborative filtering in spark
Chapter5 : Deep Learning and Computational Chemistry
想要白嫖正则大全是吧?这一次给你个够!
Experimental reproduction of image classification (reasoning only) based on caffe resnet-50 network
如何用因果推断和实验驱动用户增长? | 7月28日TF67
flinkcdc可以一起导mongodb数据库中的多张表吗?
Microsoft azure and Analysys jointly released the report "Enterprise Cloud native platform driven digital transformation"
Plus SBOM: assembly line BOM pbom
什么是CI/CD?
AtCoder Beginner Contest 261 F // 树状数组
想要做好软件测试,可以先了解AST、SCA和渗透测试
零基础学习CANoe Panel(15)—— 文本输出(CAPL Output View )
MySQL remote connection permission error 1045 problem
需求规格说明书模板