贪心

题目看错了。。。还以为是从操作序列中选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. ByteArrayInputStream的作用,和BufferedOutputStream 的区别

    个人好奇ByteArrayInputStream,到底是有什么用于是百度了一些资料 整合了下,********这两个类对于要创建临时性文件的程序以及网络数据的传输.数据压缩后的传输等可以提高运行的的效 ...

  2. svm、logistic regression对比

    相同点:都是线性分类算法 不同点: 1.损失函数不同 LR:基于“给定x和参数,y服从二项分布”的假设,由极大似然估计推导 SVM: hinge loss + L2 regularization的标准 ...

  3. spring-quartz定时任务使用小结

    在实际项目中,通常须要用到定时任务(定时作业).spring框架提供了非常好的实现. 1.  下载spring-quartz插件包 这里默认当前系统中是集成了spring框架的基本功能的.去网上下载s ...

  4. SolidEdge如何打开或关闭自动标注尺寸

    工具-聪慧-自动标注尺寸                    

  5. Java学习之基本概念

    1.java体系结构: j2se:是Java的标准版,用于标准的应用开. j2ee:是Java的企业版,用于企业级的应用服务,web服务开发. j2me:是Java的微型版,用户手机或嵌入式开发. p ...

  6. linux 输入子系统(3) button platform driver

    button platform driver 一般位于driver/input/keyboard/gpio_keys.c /*用于按键事件的上报,它将在按键的中断发生后被调用.其中逻辑就是获取到按键类 ...

  7. 距特征之k阶距概念

    k阶原点距和k阶中心距各是说明什么数字特征 http://www.cnblogs.com/emanlee/archive/2011/04/25/2028628.html 二阶中心距,也叫作方差,它告诉 ...

  8. DRF 之 路由组件

    组件路由的步骤 1.先要导入DefaultRouter from rest_framework.routers import DefaultRouter 2.实例化DeaultRouter对象 rou ...

  9. Springboot读取自定义的yml文件中的List对象

    Yml文件(novellist.xml)如下: novellist:   list:     - name: 笑傲江湖       type: 武侠       master: 令狐冲       a ...

  10. 用WaveX实现音频文件的录音

    原文地址:https://blog.csdn.net/gongluck93/article/details/53096013 1.WaveInOpen waveInOpen MMRESULT wave ...