当前位置:网站首页>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;
}边栏推荐
- Eccv2022 | transclassp class level grab posture migration
- clickhouse笔记03-- Grafana 接入ClickHouse
- Experimental reproduction of image classification (reasoning only) based on caffe resnet-50 network
- LeetCode 0133. 克隆图
- 公安部:国际社会普遍认为中国是世界上最安全的国家之一
- [shutter -- layout] stacked layout (stack and positioned)
- 我在源头SQLServer里面登记绝对删除的数据,传到MaxComputer,在数据清洗的时候写绝对
- 需求规格说明书模板
- shell基础知识(退出控制、输入输出等)
- I register the absolutely deleted data in the source sqlserver, send it to maxcomputer, and write the absolute data when cleaning the data
猜你喜欢
软件测试流程包括哪些内容?测试方法有哪些?

“蔚来杯“2022牛客暑期多校训练营2 补题题解(G、J、K、L)

【问题解决】ibatis.binding.BindingException: Type interface xxDao is not known to the MapperRegistry.

Use of hystrix

【问题解决】org.apache.ibatis.exceptions.PersistenceException: Error building SqlSession.1 字节的 UTF-8 序列的字

Jenkins configuration pipeline

EMQX Cloud 更新:日志分析增加更多参数,监控运维更省心

word样式和多级列表设置技巧(二)

Selenium use -- installation and testing

Mid 2022 review | latest progress of large model technology Lanzhou Technology
随机推荐
Can flinkcdc import multiple tables in mongodb database together?
[shutter -- layout] stacked layout (stack and positioned)
Clickhouse notes 03-- grafana accesses Clickhouse
Keeping MySQL highly available
Table partition of MySQL
软件测试流程包括哪些内容?测试方法有哪些?
ECCV 2022 | 登顶SemanticKITTI!基于二维先验辅助的激光雷达点云语义分割
web安全入门-UDP测试与防御
《富兰克林自传》修身
Mid 2022 review | latest progress of large model technology Lanzhou Technology
[ROS advanced chapter] Lecture 9 programming optimization of URDF and use of xacro
[high concurrency] deeply analyze the execution process of worker threads in the thread pool through the source code
Kyligence 入选 Gartner 2022 数据管理技术成熟度曲线报告
Zero basic learning canoe panel (12) -- progress bar
Alibaba cloud technology expert Qin long: reliability assurance is a must - how to carry out chaos engineering on the cloud?
深度学习MEMC插帧论文列表paper list
AtCoder Beginner Contest 261E // 按位思考 + dp
EMQX Cloud 更新:日志分析增加更多参数,监控运维更省心
massCode 一款优秀的开源代码片段管理器
Deployment of Apache website services and implementation of access control