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 ...
随机推荐
- 若菜acmer感觉自己智商全然被碾压了QAQ~~
题目大意是:输入n,m,给出n*m(n.m<=100)的不是正规的布满棋子的棋盘,求最少改几个棋子能够使得棋盘正规,正规的棋盘必须是每一个相邻的棋子颜色都不同(仅仅有黑白两种,用0,1取代) 比 ...
- 通过BSSID和无线流量传输后门Payload
本文将探讨无线接入点(AP)和BSSID(MAC地址AP).我们不借助文件系统加密和文件系统中(仅内存中)的硬编码Payload即可获得后门Payload,通过该方法可绕过所有的杀软,可以不使用Pay ...
- 基于MNIST数据的softmax regression
跟着tensorflow上mnist基本机器学习教程联系 首先了解sklearn接口: sklearn.linear_model.LogisticRegression In the multiclas ...
- 最大熵推导LR
http://www.win-vector.com/dfiles/LogisticRegressionMaxEnt.pdf https://www.zhihu.com/question/2409455 ...
- python遍历两个列表,若长度不等,用None填充
zip经常会遇到截断问题,如:a = [1,2,3], b = [4,5,6,7],则zip(a,b) = [(1, 4), (2, 5), (3, 6)] 可考虑使用map: map(lambda ...
- git log 查看版本演变历史
1.查看git操作历史 $ git log #git 查看git操作历史 $ git log --oneline #git 简洁的查看git变更记录 $ git log -n4 --onelin ...
- C# - CLR
The Common Language Runtime (CLR), the virtual-machine component of Microsoft's .NET framework, m ...
- 我所见过的最简短、最灵活的javascript日期转字符串工具函数
我们知道javascript的Date对象并没有提供日期格式化函数.将日期对象转换成"2015-7-02 20:35:11"等这样的格式又是项目中非经常常使用的需求.近期在我们项目 ...
- 使用ViewPager多页面滑动切换以及动画效果
https://github.com/eltld/Viewpager
- 解决asp.net mvc UpdateModel更新对象后出现null问题的方法
在用asp.net mvc 4.0做项目的时候遇到的这种情况:情况分析:“在填写表单的时候,有一些表单没有填写,留空,然后直接post 提交表单,action中用UpdateModel 来更新mode ...