题目传送门

Mars Rover

格式难调,题面就不放了。


  分析:

  今天考试的时候考了这道题目的加强版,所以来做。

  其实也并不难,我们建立好树形结构以后先把初始权值全部求出,然后就得到了根节点的初始值。因为一次只修改一个点的值,所以我们只要自上而下根据位运算的种类得出每一个节点的值修改后是否会改变根节点的值就行了。

  Code:

  

//It is made by HolseLee on 2nd Nov 2018
//CF1010D
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std; const int N=1e6+;
int n,dp[N];
struct Node { int ls,rs,val,type; }t[N]; inline int read()
{
char ch=getchar(); int x=; bool flag=false;
while( ch<'' || ch>'' ) {
if( ch=='-' ) flag=true; ch=getchar(); }
while( ch>='' && ch<='' ) {
x=x*+ch-''; ch=getchar(); }
return flag ? -x : x;
} void dfs(int x)
{
if( t[x].type== ) return;
switch (t[x].type) {
case :
dfs(t[x].ls), dfs(t[x].rs);
t[x].val=t[t[x].ls].val&t[t[x].rs].val;
break;
case :
dfs(t[x].ls), dfs(t[x].rs);
t[x].val=t[t[x].ls].val^t[t[x].rs].val;
break;
case :
dfs(t[x].ls), dfs(t[x].rs);
t[x].val=t[t[x].ls].val|t[t[x].rs].val;
break;
case :
dfs(t[x].ls); t[x].val=(t[t[x].ls].val^);
break;
}
} void DP(int x)
{
if( t[x].type== ) return;
switch (t[x].type) {
case :
if( t[t[x].ls].val== && t[t[x].rs].val== ) {
dp[t[x].ls]=dp[t[x].rs]=;
DP(t[x].ls), DP(t[x].rs);
} else if( t[t[x].ls].val== && t[t[x].rs].val== ) {
dp[t[x].rs]=; DP(t[x].rs);
} else if( t[t[x].ls].val== && t[t[x].rs].val== ) {
dp[t[x].ls]=; DP(t[x].ls);
}
break;
case :
dp[t[x].ls]=dp[t[x].rs]=;
DP(t[x].ls), DP(t[x].rs);
break;
case :
if( t[t[x].ls].val== && t[t[x].rs].val== ) {
dp[t[x].ls]=, DP(t[x].ls);
} else if( t[t[x].ls].val== && t[t[x].rs].val== ) {
dp[t[x].rs]=, DP(t[x].rs);
} else if( t[t[x].ls].val== && t[t[x].rs].val== ) {
dp[t[x].ls]=dp[t[x].rs]=;
DP(t[x].ls), DP(t[x].rs);
}
break;
case :
dp[t[x].ls]=, DP(t[x].ls);
break;
}
} int main()
{
n=read(); char s[];
for(int i=; i<=n; ++i) {
scanf("%s",s);
switch (s[]) {
case 'A': t[i].type=, t[i].ls=read(), t[i].rs=read(); break;
case 'X': t[i].type=, t[i].ls=read(), t[i].rs=read(); break;
case 'O': t[i].type=, t[i].ls=read(), t[i].rs=read(); break;
case 'N': t[i].type=, t[i].ls=read(); break;
case 'I': t[i].type=, t[i].val=read(); break;
}
}
dfs(); DP();
for(int i=; i<=n; ++i) {
if( t[i].type!= ) continue;
if( dp[i] ) putchar((t[].val^)+'');
else putchar(t[].val+'');
}
puts("");
return ;
}

CF1010D Mars rover [位运算,DP]的更多相关文章

  1. [CF1010D]Mars Over_位运算性质

    Mars rover 题目链接:http://codeforces.com/problemset/problem/1010/D 数据范围:略. 题解: 因为每次只改一个,改完之后改回去,这个性质很重要 ...

  2. CF1010D Mars rover

    CF1010D Mars rover 洛谷评测传送门 题目描述 Natasha travels around Mars in the Mars rover. But suddenly it broke ...

  3. 【洛谷 P4934】 礼物 (位运算+DP)

    题目链接 位运算+\(DP\)=状压\(DP\)?(雾 \(a\&b>=min(a,b)\)在集合的意义上就是\(a\subseteq b\) 所以对每个数的子集向子集连一条边,然后答案 ...

  4. bzoj5108 [CodePlus2017]可做题 位运算dp+离散

    [CodePlus2017]可做题 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 87  Solved: 63[Submit][Status][Dis ...

  5. 【CF908E】New Year and Entity Enumeration 位运算+DP

    [CF908E]New Year and Entity Enumeration 题意:给定$M=2^m-1$,我们称一个集合S是好的,当且仅当它满足:1.$\forall a\in S,a\  \ma ...

  6. [BZOJ3054] Rainbow的信号(考虑位运算 + DP?)

    传送门 BZOJ没数据范围... 其实数据范围是这样的.. 前20%可以直接n^3暴力枚举每个区间 前40%可以考虑每一位,因为所有数每一位都是独立的,而和的期望=期望的和,那么可以枚举每一位,再枚举 ...

  7. 2019 ICPC Asia Nanchang Regional C And and Pair 找规律/位运算/dp

    题意: 给定一个二进制表示的n,让你找满足如下要求的数对(i,j)的个数 $0 \leqslant j \leqslant i \leqslant n$ $ i & n = i $ $ i & ...

  8. 51nod 1406 位运算/dp

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1406 1406 与查询 题目来源: CodeForces 基准时间限制: ...

  9. leetcode 201. Bitwise AND of Numbers Range(位运算,dp)

    Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...

随机推荐

  1. Docker镜像加速==》阿里云加速器

    1.使用阿里云加速器加快获取docker官方的镜像 步骤一:如果没有阿里云账号,需要注册阿里云开发账号 https://dev.aliyun.com/ 步骤二:进入加速器页面获取加速信息 https: ...

  2. bug4 导入新工程时报 Target runtime com.genuitec.runtime.generic.jee60 is not defined

    系统加载工程后,报错Target runtime com.genuitec.runtime.generic.jee60 is not defined,在发布工程的同事电脑上正常.新导入的工程,出问题很 ...

  3. postgresql常见命令及操作

    pgsql已经更新到beta11了,不同版本的服务器启动或相关命令.配置可能会有不同,所以得根据pg版本进行操作.下面记录一些工作中常用到的一些操作,主要包括服务启动.备份/恢复数据.数据目录迁移.常 ...

  4. [0,x)的随机数

    #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #in ...

  5. DataGridView刷新数据

    在DataGridView上操作数据之后,无论是增删改都是对数据库进行了操作,而DataGridView这个控件在操作之后是不会变化的,需要重新的去数据库里读取一下数据才行,可以理解为之刷新 Data ...

  6. Sql Server数据库小知识点总结

    把我在开发时候遇到的一点小知识持续更新在这里~ 1.where条件时常变 where UserID='1' 这里的UserID呢,它的值是经常在变化的,有时候要查2,有时候要查3的,有时候要查全部人! ...

  7. Linux 命令详解(一)export 命令

    一.Windows 环境变量 1.在Windows 系统下,很多软件安装都需要配置环境变量,比如 安装 jdk ,如果不配置环境变量,在非软件安装的目录下运行javac 命令,将会报告找不到文件,类似 ...

  8. python 基础部分重点复习整理--从意识那天开始进阶--已结

    pythonic 风格编码 入门python好博客 进阶大纲 有趣的灵魂 老齐的教程 老齐还整理了很多精华 听说 fluent python + pro python 这两本书还不错! 元组三种遍历, ...

  9. History of Monte Carlo Methods - Part 1

    History of Monte Carlo Methods - Part 1 Some time ago in June 2013 I gave a lab tutorial on Monte Ca ...

  10. CodeAction_beta02 斐波那契 (多维DP)

    题面: solution: 这题和斐波那契数列没有任何关系!!!!! 这题就是一个无脑DP!!!!!!!!!! 因为所有数都要出现至少一次,所以只需考虑其组合而不用考虑其排列,最后乘个 n!就是了(意 ...