贪心

题目看错了。。。还以为是从操作序列中选5个。。。然后半个小时没了。。。

我们把每位分别用0和1带入,看看返回值是什么,然后分类讨论。千万不用特判!!!之前忘了删了就fst。。。

#include<bits/stdc++.h>
using namespace std;
const int N = 5e5 + ;
int n, x1, x2, x3;
int a[N], mark[N];
char s[N][];
int calc(int x, int t)
{
t = (t << x);
for(int i = ; i <= n; ++i)
{
if(s[i][] == '|') t |= a[i];
if(s[i][] == '&') t &= a[i];
if(s[i][] == '^') t ^= a[i];
}
return (t & ( << x)) > ;
}
int main()
{
scanf("%d", &n);
for(int i = ; i <= n; ++i)
{
int x;
scanf("%s%d", s[i], &a[i]);
for(int j = ; j < ; ++j) if(a[i] & ( << j)) mark[j] = ;
}
x2 = ;
for(int i = ; i < ; ++i)
{
int x = calc(i, ), y = calc(i, );
// printf("i = %d x = %d y = %d\n", i, x, y);
if(x == && y == ) x2 -= ( << i);
if(x == && y == ) x3 += ( << i);
// if(x == 0 && y == 1) x2 += (1 << i);
if(x == && y == ) x1 += ( << i);
}
int cnt = ;
if(!x1) --cnt;
// if(!x2) --cnt;
if(!x3) --cnt;
printf("%d\n", cnt);
if(x1) printf("| %d\n", x1);
printf("& %d\n", x2);
if(x3) printf("^ %d\n", x3);
return ;
}

879C的更多相关文章

  1. codeforces 879c

    C. Short Program time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  2. Codeforces 879C/878A - Short Program

    传送门:http://codeforces.com/contest/879/problem/C 本题是一个位运算问题——位运算的等价变换. 假设位运算符“&”“|”“^”是左结合的,且优先级相 ...

  3. Linux内核使用浮点运算问题

    上一篇博文中 电池温度检测原理和示例代码 ,由于驱动要使用对数函数而从网上参看一个实现 double ln(double a) { ; int k,nk; double x,xx,y; x = (a- ...

  4. 2021.1.23--vj补题

    B - B CodeForces - 879B n people are standing in a line to play table tennis. At first, the first tw ...

随机推荐

  1. 设计模式之装饰(Decorator)模式

    设计模式之装饰(Decorator)模式 (一)什么是装饰(Decorator)模式 装饰模式,又称为包装模式,它以对客户端透明的方式扩张对象的功能,是继承关系的替代方案之一. 装饰模式可以在不使用创 ...

  2. 《Java虚拟机原理图解》 1.1、class文件基本组织结构

    作为Java程序猿,我们知道,我们写好的.java 源代码,最后会被Java编译器编译成后缀为.class的文件,该类型的文件是由字节组成的文件,又叫字节码文件.那么,class字节码文件里面到底是有 ...

  3. uiimage缩放图片大小和属性UIViewContentModeScaleAspectFit

    UIImageView *tmp = [[UIImageView alloc]initWithFrame:CGRectMake(5.0f, 5.0f, 40.0f, 40.0f)];          ...

  4. maven删除不必要的依赖;优化pom依赖研究

    mvn dependency:copy-dependencies -DoutputDirectory=/home/admin/git/oceanus/test 会把所有依赖的插件版本都拷贝进去,而不是 ...

  5. flask使用debug模式时,存在错误时,会占用设备内存直至服务重启才释放;debug模式会开启一个守护进程(daemon process)

    函数调用顺序flask的app.py的run-->werkzeug的serving.py的run_simple-->调用werkzeug的debug的__init__.py里的类Debug ...

  6. C语言之基本算法34—分解质因数(方法一)

    //矩阵基础 /* ================================================================== 题目:输入一个正整数.将其分解为质因式,如:6 ...

  7. 写2个线程,其中一个线程打印1~52,另一个线程打印A~z,打印顺序应该是12A34B45C……5152Z

    我写的 class LN { private int flag = 0; public static char ch = 'A'; public static int n = 1; public sy ...

  8. npm 的常用操作

    cd 项目目录 npm install -y 初始化信息,-y表示所有的选择都表示确定 执行完之后会自动生成一个package.json文件 添加依赖: npm -i(install) jquery ...

  9. mysql使用“.frm”文件恢复表结构

    mysql创建每张表后都会在“mysql安装目录/data/数据库名/”目录下创建一个“表名.frm”文件. 该.frm文件并不能直接打开,但是它可以帮助你恢复你的表结构~~ 具体操作如下: 我现在准 ...

  10. 诺基亚(Microsoft Devices Group)2014暑期实习生笔试题知识点

    总结一下Microsoft Devices Group的软件类笔试题,全部笔试题分两份试卷,逻辑题一份和软件測试题一份,仅仅总结技术题喽~题目全英文,仅仅包括选择题和填空题.选择题居多.分单选和多选. ...