贪心

题目看错了。。。还以为是从操作序列中选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. 你知道在springboot中如何使用WebSocket吗

    一.背景   我们都知道 http 协议只能浏览器单方面向服务器发起请求获得响应,服务器不能主动向浏览器推送消息.想要实现浏览器的主动推送有两种主流实现方式: 轮询:缺点很多,但是实现简单 webso ...

  2. HSSF生成excel文件损坏

    一开始我的代码是这样的: 然后打开创建的好的excel文件出现下面的问题:,, 这里改下代码就行,其实也不用改,添加下sheet就行,就是一开始是空的,没sheet,所以可能打不开,现在至少要创建一个 ...

  3. Spark学习(一) Spark初识

    一.官网介绍 1.什么是Spark 官网地址:http://spark.apache.org/ Apache Spark™是用于大规模数据处理的统一分析引擎. 从右侧最后一条新闻看,Spark也用于A ...

  4. 12/10 C语言程序设计竞赛 后五题

    Title(题目) 小朋友顺逆报数 Problem ID(题目编号) (题目添加成功后由系统自动生成) Time Limit(运行时间限制) S(秒) Memory Limit(内存限制) MByte ...

  5. ubuntu16.04安装mysql5.7.15

    1.在官网下载mysql安装包 直接选择第一个下载好了就行 2.进入你的下载文件夹下面 键入命令: tar -xvf mysql-server_5.7.13-1ubuntu16.04_i386.deb ...

  6. OSX: diskutil命令-转换成自由空间并再对其分区

    声明:本文涉及的操作非常可能会破坏你的系统文件,造成数据丢失.请谨慎模仿,一切后果作者均不承担不论什么责任. 目的: 尽管说比較熟悉diskutil命令和它的GUI前端程序磁盘工具(Disk Util ...

  7. Solidworks工程图 如何绘制向视图,辅助视图

    先画一条垂直于视野方向的中心线   点击辅助视图,然后点选刚才的中心线即可生成向视图   对向视图的标准可以得到一些用其他方法不好标注的尺寸            

  8. linux find 命令查找 复制

    find 查找 find . -mtime -2 -a -path './.git*' -prune , -path './Cache' -prune -a -exec cp {} one \; rm ...

  9. js 验证 输入值 全是中文

    1.代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...

  10. Leetcode41: Remove Duplicates from Sorted List

    Given a sorted linked list, delete all duplicates such that each element appear only once. For examp ...