879C
贪心
题目看错了。。。还以为是从操作序列中选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的更多相关文章
- codeforces 879c
C. Short Program time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- Codeforces 879C/878A - Short Program
传送门:http://codeforces.com/contest/879/problem/C 本题是一个位运算问题——位运算的等价变换. 假设位运算符“&”“|”“^”是左结合的,且优先级相 ...
- Linux内核使用浮点运算问题
上一篇博文中 电池温度检测原理和示例代码 ,由于驱动要使用对数函数而从网上参看一个实现 double ln(double a) { ; int k,nk; double x,xx,y; x = (a- ...
- 2021.1.23--vj补题
B - B CodeForces - 879B n people are standing in a line to play table tennis. At first, the first tw ...
随机推荐
- 【Todo】Java类型转换总结
参考 http://www.cnblogs.com/lwbqqyumidi/p/3700164.html 这篇文章也可以对照着看:http://www.360doc.com/content/10/09 ...
- NAND FLash基础概念介绍
一.引脚介绍 引脚名称 引脚功能 CLE 命令锁存功能 ALE 地址锁存功能 /CE 芯片使能 /RE 读使能 /WE 写使能 /WP 写保护 R/B 就绪/忙输出信号 Vcc 电源 Vss 地 N. ...
- Android Studio——gradle同步出错:MALFORMED
Android Studio之前使用本地的gradle-2.10,而后创建新的工程总是报错,信息如下: Gradle sync failed: MALFORMED 而后在File->Projec ...
- IntelliTrace窗口无法弹出的解决办法
最近在使用EF框架,所以需要IntelliTrace窗口进行对ADO的SQL生成监控.可找了半天都无法Call出该窗口. 在Debug模式下,选择调试->窗口 里面根本没有IntelliTrac ...
- java 短信猫发送短信的方法
用java实现短信收发的功能,目前一般项目中短信群发功能的实现方法大致有下面三种: · 1. 向运行商申请短信网关,不需要额外的设备,利用运行商提供的API调用程序发送 ...
- C#连接数据库 增删改查
- ISC DHCP: Enterprise grade solution for configuration needs
https://www.isc.org/downloads/dhcp/ ISC DHCP: Enterprise grade solution for configuration needs All ...
- oracle 11G direct path read 非常美也非常伤人
direct path read 在11g中,全表扫描可能使用direct path read方式,绕过buffer cache,这种全表扫描就是物理读了. 在10g中,都是通过gc buffer来读 ...
- 疯狂Java学习笔记(77)-----------凝视注意事项
代码凝视,能够说是比代码本身更重要.这里有一些方法能够确保你写在代码中的凝视是友好的: 不要反复阅读者已经知道的内容 能明白说明代码是做什么的凝视对我们是没有帮助的. // If the color ...
- pom.xml和testng.xml
转自:http://www.cnblogs.com/penghong2014/p/4380199.html <project xmlns="http://maven.apache.or ...