luogu P2114 [NOI2014]起床困难综合症 位运算 二进制
建议去uoj那里去测,数据比较强
位运算的题目,就得一位一位的分开考虑
然后枚举初始值的最高位是0 是1 的最终攻击
(二进制内)最高位是1肯定比次位是1次次位是1次次次位是1···的大吧,显然
然后贪心O(N)就能过去啦
感觉自己是学傻了,看到n=5w就写了个nlog
情况好像有某一位的初始值是0最终那一位是1,初始值是1,最终那一位也是1的,所以要注意一下
代码:
(咦,好像别人家的代码呀)
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <bitset>
#define ll long long
using namespace std;
const int maxn = 1e5 + 7;
int n, m, one, ling, ans, end, cz[maxn], num[maxn];
int read() {
int x = 0, f = 1; char s = getchar();
for (; s > '9' || s < '0'; s = getchar()) if (s == '-') f = -1;
for (; s <= '9' && s >= '0'; s = getchar()) x = x * 10 + s - '0';
return x * f;
}
int check(int ans) {
for (int i = 1; i <= n; ++ i) {
if (cz[i] == 1) {
ans = ans & num[i];
} else if (cz[i] == 2) {
ans = ans | num[i];
} else if (cz[i] == 3) {
ans = ans ^ num[i];
}
}
return ans;
}
int main() {
n = read(), m = read();
for (int i = 1; i <= n; ++ i) {
char s = getchar();
while (s == '\n' || s == ' ') s = getchar();
if (s == 'A') cz[i] = 1;
else if (s == 'O') cz[i] = 2;
else cz[i] = 3;
num[i] = read();
}
one = check((1 << 30) - 1), ling = check(0);
for (int i = 30 ; i >= 0; --i) {
if (!(ling & (1 << i)) && (one & (1 << i)) && (ans + (1 << i) <= m))
ans += 1 << i, end += 1 << i;
else if (ling & (1 << i))
end += 1 << i;
}
cout << end << "\n";
return 0;
}
luogu P2114 [NOI2014]起床困难综合症 位运算 二进制的更多相关文章
- [P2114] [NOI2014]起床困难综合症 (位运算)
题面 传送门:https://www.luogu.org/problemnew/show/P2114 Solution 一道很有意思的位运算题. 要做这一题,我们首先得了解一个很重要的特点 位运算过程 ...
- 洛谷 P2114 [NOI2014]起床困难综合症 位运算
题目描述 21世纪,许多人得了一种奇怪的病:起床困难综合症,其临床表现为:起床难,起床后精神不佳.作为一名青春阳光好少年,atm一直坚持与起床困难综合症作斗争.通过研究相关文献,他找到了该病的发病原因 ...
- luogu 2114 [NOI2014]起床困难综合症 位运算+贪心
感觉这个思路非常巧妙啊~ code: #include <bits/stdc++.h> #define ll long long #define setIO(s) freopen(s&qu ...
- [Bzoj3668][Noi2014]起床困难综合症(位运算)
3668: [Noi2014]起床困难综合症 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 2612 Solved: 1500[Submit][St ...
- Luogu P2114[NOI2014]起床困难综合症 【贪心/位运算】By cellur925
题目传送门 所以NOI的题现在简单惹? 30分做法:枚举开始的权值,n²过掉. 100分做法:竟然是贪心qwq.因为我们的计算背景是二进制下,所以我们贪心地想让每一位都是1.我们现在需要解决的问题,就 ...
- 洛谷P2114 [NOI2014]起床困难综合症
P2114 [NOI2014]起床困难综合症 题目描述 21世纪,许多人得了一种奇怪的病:起床困难综合症,其临床表现为:起床难,起床后精神不佳.作为一名青春阳光好少年,atm一直坚持与起床困难综合症作 ...
- 洛谷 P2114 [NOI2014]起床困难综合症 解题报告
P2114 [NOI2014]起床困难综合症 题目描述 21世纪,许多人得了一种奇怪的病:起床困难综合症,其临床表现为:起床难,起床后精神不佳.作为一名青春阳光好少年,atm一直坚持与起床困难综合症作 ...
- P2114 [NOI2014]起床困难综合症(二进制)
P2114 [NOI2014]起床困难综合症 我们开始设俩数,一个二进制表示全是1,另一个全是0(就是2147483647 和 0 辣) 蓝后跑一遍门 于是最后有4种情况 1->0,1-> ...
- BZOJ-3668 起床困难综合症 位运算+贪心
faebdc学长杂题选讲中的题目...还是蛮简单的...位运算写的不熟练... 3668: [Noi2014]起床困难综合症 Time Limit: 10 Sec Memory Limit: 512 ...
随机推荐
- oracle数据迁移到mysql
今天遇到需求要把oracle的部分数据搬到mysql,用java代码抓数据,然后拼接成sql语句,然后用navicat执行sql脚本的方法,导入数据库. import oracle.jdbc.driv ...
- 【Loadrunner】Error -26601: Decompression function 错误解决、27728报错解决方案
一. Error -26601: Decompression function 错误解决 Action2.c(30): Error -26601: Decompression function ...
- mysql python pymysql模块 增删改查 查询 fetchone
import pymysql mysql_host = '192.168.0.106' port = 3306 mysql_user = 'root' mysql_pwd = ' encoding = ...
- [git]git版本管理学习记录
今天看到别人用这玩意记录自己的进度, 我也学习了一下. 1,适当的工具会提升效率 2,关注点还是得放在代码本身上. github/gitignore github提供了各种gitignore文件 有p ...
- 阻止提交按钮的默认 action
使用 preventDefault() 函数来阻止对表单的提交. 示例代码如下: <html><head><script type="text/javascri ...
- 性能测试之nmon对linux服务器的监控
大家都知道在做性能测试的时候,需要监控服务器的资源情况,而大多数服务器是Linux系统,网上资料嘿多,这里汇总介绍下Nmon监控工具: -------------------------------- ...
- 安装selenium python
https://pypi.org/project/selenium/#files selenium-3.13.0-py2.py3-none-any.whl 安装成功后才能用 from selenium ...
- [LeetCode] 203. Remove Linked List Elements_Easy tag: Linked LIst
Remove all elements from a linked list of integers that have value val. Example: Input: 1->2-> ...
- sqlplus与shell互相传值的几种情况
2578人阅读 sqlplus与shell互相传值的几种情况 情况一:在shell中最简单的调用sqlplus $cat test.sh #!/bin/sh sqlplus oracle/orac ...
- 大神的博客地址liferay
http://www.huqiwen.com/category/technology-share/liferay/