当前位置:网站首页>E - Many Operations (按位考虑 + dp思想记录操作后的结果
E - Many Operations (按位考虑 + dp思想记录操作后的结果
2022-08-05 00:08:00 【__Rain】
E - Many Operations
思路:
虽然第 i i i 次操作的初始值是第 i − 1 i-1 i−1 次操作后的结果,但是按位考虑,开始操作时每一位只能是 0 0 0 或者 1 1 1,并且每次操作顺序每次都是一样的
可以想到用 d p dp dp 思想记录下来每一位按顺序操作后的结果
f [ i ] [ j ] [ k ] f[i][j][k] f[i][j][k] 表示第 j j j 位初始值为 k k k ,进行 i i i 次操作后的值
code:
#include<bits/stdc++.h>
#define endl '\n'
#define ll long long
#define ull unsigned long long
#define ld long double
#define all(x) x.begin(), x.end()
#define mem(x, d) memset(x, d, sizeof(x))
#define eps 1e-6
using namespace std;
const int maxn = 2e5 + 9;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
ll n, m;
bool f[maxn][30][2];
// f[i][j][k] 表示第j位初始值为k,进行 i 次操作后的值
void work()
{
cin >> n >> m;
vector <int>t(n + 1), a(n + 1);
for(int i = 1; i <= n; ++i){
cin >> 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){
int x = (a[i] >> j & 1);
for(int k = 0; k < 2; ++k){
if(t[i] == 1){
f[i][j][k] = f[i-1][j][k] & x;
}
else if(t[i] == 2){
f[i][j][k] = f[i-1][j][k] | x;
}
else {
f[i][j][k] = f[i-1][j][k] ^ x;
}
}
}
}
for(int i = 1; i <= n; ++i){
int ans = 0;
for(int j = 0; j < 30; ++j){
int k = (m >> j & 1);
if(f[i][j][k]) ans += 1 << j;
}
cout << ans << endl;
m = ans;
}
}
int main()
{
ios::sync_with_stdio(0);
// int TT;cin>>TT;while(TT--)
work();
return 0;
}
边栏推荐
- 招标公告 | 海纳百创公众号运维项目
- .net (C#) get year month day between two dates
- Day118. Shangyitong: order list, details, payment
- Mysql based
- IDEA file encoding modification
- 资深游戏建模师告知新手,游戏场景建模师必备软件有哪些?
- 【云原生--Kubernetes】Pod控制器
- 【无标题】线程三连鞭之“线程池”
- Modelers experience sharing: model study method
- Couple Holding Hands [Greedy & Abstract]
猜你喜欢
MongoDB权限验证开启与mongoose数据库配置
Implementation principle of golang coroutine
"Relish Podcast" #397 The factory manager is here: How to use technology to empower the law?
VMware NSX 4.0 -- 网络安全虚拟化平台
uniapp横向选项卡(水平滚动导航栏)效果demo(整理)
翁恺C语言程序设计网课笔记合集
【LeetCode】双指针题解汇总
入门3D游戏建模师知识必备
Three tips for you to successfully get started with 3D modeling
How to automatically push my new articles to my fans (very simple, can't learn to hit me)
随机推荐
网站最终产品页使用单一入口还是多入口?
Flutter启动流程(Skia引擎)介绍与使用
uniapp横向选项卡(水平滚动导航栏)效果demo(整理)
线程三连鞭之“线程的状态”
Day118. Shangyitong: order list, details, payment
Basic web in PLSQL
Brainstorm: Complete Backpack
入门3D游戏建模师知识必备
手写分布式配置中心(1)
Cloud native - Kubernetes 】 【 scheduling constraints
子连接中的参数传递
上课笔记(6)(2)——#742. 周末舞会
测试经理要不要做测试执行?
MVCC是什么
Huggingface入门篇 II (QA)
《MySQL入门很轻松》第2章:MySQL管理工具介绍
LeetCode Hot 100
The master teaches you the 3D real-time character production process, the game modeling process sharing
【云原生--Kubernetes】调度约束
情人节---快来学习一下程序员的专属浪漫吧