G - WiFi Password Gym - 101608G (异或思维题+曲尺)
题目链接:https://cn.vjudge.net/contest/285962#problem/G
题目大意:给你n和m,n代表有n个数,然后让你找出一个最长的区间,使得这个区间内的所有的数的‘’或‘’都小于等于m。
具体思路:曲尺,两个指针来回弄就行,具体的细节在代码里面,(以前做过的题现在竟然做不出来了,,我)
AC代码:
#include<iostream>
#include<stack>
#include<stdio.h>
#include<cmath>
#include<algorithm>
using namespace std;
# define ll long long
const int maxn = 3e6+;
ll a[maxn];
int main(){
freopen("wifi.in","r",stdin);
int T;
scanf("%d",&T);
while(T--){
ll n,m,tmp=,tot=,flag=,ans=,l,r;
scanf("%lld %lld",&n,&m);
for(ll i=;i<=n;i++){
scanf("%lld",&a[i]);
ans=max(ans,tot);
if(a[i]<=m&&!flag){
l=i;
r=i;
tot=;
tmp=a[i];
ans=max(ans,tot);
flag=;
}
else if(flag){
ans=max(ans,tot);
if((tmp|a[i])<=m){
r++;
tmp|=a[i];
tot++;//计数的时候是按照合法的来记的,不能通过r-l+1来判断
ans=max(ans,tot);
continue;
}
ans=max(ans,tot);
if(a[i]>m){
tot=;
flag=;
tmp=;
continue;
}
ans=max(ans,tot);
tmp=;//注意这里的tmp直接归零就可以了。
ll pos=l;
r++;//注意先r++.
for(ll j=r;j>=pos;j--){
if((tmp|a[j])<=m){
tmp|=a[j];
l=j;
}
else break;
}
tot=r-l+;// 合法块的大小重新赋值。
ans=max(ans,tot);
}
}
printf("%lld\n",ans);
}
return ;
}
G - WiFi Password Gym - 101608G (异或思维题+曲尺)的更多相关文章
- Gym 102028C - Supreme Command - [思维题][2018-2019 ACM-ICPC Asia Jiaozuo Regional Contest Problem C]
题目链接:https://codeforces.com/gym/102028/problem/C Lewis likes playing chess. Now he has n rooks on th ...
- Gym 101775C - Traffic Light - [思维题]
题目链接:http://codeforces.com/gym/101775/problem/C 题意: 给出 $N$ 个红绿灯,又给出 $N+1$ 个距离 $S_i = S_0,S_1, \cdots ...
- Gym 100801E Easy Arithmetic (思维题)
题目:传送门.(需要下载PDF) 题意:给定一个长度不超过1000的字符串表达式,向该表达式中加入'+'或'-',使得表达式的值最大,输出该表达式. 题解:比如300-456就改成300-4+56,遇 ...
- A - Arcade Game Gym - 100814A (概率思维题)
题目链接:https://cn.vjudge.net/contest/285964#problem/A 题目大意:每一次给你你一个数,然后对于每一次操作,可以将当前的数的每一位互换,如果互换后的数小于 ...
- UVA 1394 And Then There Was One / Gym 101415A And Then There Was One / UVAlive 3882 And Then There Was One / POJ 3517 And Then There Was One / Aizu 1275 And Then There Was One (动态规划,思维题)
UVA 1394 And Then There Was One / Gym 101415A And Then There Was One / UVAlive 3882 And Then There W ...
- 思维题 Gym 100553A Alter Board
题目传送门 /* 题意:一个n×m的矩形,相邻的颜色不同,黑或白.问最少的翻转次数,每次翻转可指定任意一个子矩形 思维题:最少要把偶数行和列翻转,也就是n/2+m/2次 */ #include < ...
- C. Nice Garland Codeforces Round #535 (Div. 3) 思维题
C. Nice Garland time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- [UVA12235] Help Bubu 思维题+状态定义+Dp
Online Judge:UVA12235 Label:思维题,状态定义,状压Dp 题面: 题目描述 有一个书架,上面放了n本书,从左往右的第i本书的高度为h[i].定义书架的混乱度为连续等高段的个数 ...
- ACM思维题训练 Section A
题目地址: 选题为入门的Codeforce div2/div1的C题和D题. 题解: A:CF思维联系–CodeForces -214C (拓扑排序+思维+贪心) B:CF–思维练习-- CodeFo ...
随机推荐
- Day037--Python--线程的其他方法,GIL, 线程事件,队列,线程池,协程
1. 线程的一些其他方法 threading.current_thread() # 线程对象 threading.current_thread().getName() # 线程名称 threadi ...
- 1、CC2530单片机介绍
单片机是一种集成电路芯片,包含中央处理器CPU.随机存储器RAM.只读存储器ROM.输入输出I/O接口.中断控制系统.定时/计数器和通信等多种功能部件. 本教程使用的单片机德州仪器生产的CC2530, ...
- jquery 实现按回车键登录功能的写法
<script> //登录的逻辑函数 自己写 function submitFuc(){ var loginName= $("#loginName").val(); v ...
- 非root用户sudo_ssh免密钥
非root用户sudo_ssh免密钥 目标:从服务器上ssh登陆后sudo免密钥执行相应的命令 环境介绍: 192.168.65.130 web224 # 步骤一: # 每个节点执行(不是必须,但是建 ...
- str
print('字符串操作') s='abc DEF hij' print('首字母大写') print(s.capitalize()) print('全大写') print(s.upper()) pr ...
- Java开发中的编码分析__GET&POST
GET方式提交参数分析 code.jsp <%@ page language="java" contentType="text/html; charset=UTF- ...
- Eclipse xml中自动提示,添加 dtd或xsd依赖
下载DTD或XSD文件 添加到Eclipse
- PHP中的表单传值
前言:试想一下如果PHP没有了表单传值,那么就相当于一个没有表达能力的人,因此表单传值在php中是相当重要的,但是不难,接下来我们一起来探讨一下吧------> (一)什么是表单传值 概念:表 ...
- ACM-ICPC 2018 南京赛区网络预赛 C GDY(模拟)
https://nanti.jisuanke.com/t/30992 题意 把m张牌(牌上数字范围是1-13)放到栈里n个人,每个人首次从栈顶取5张牌,轮流取取完牌后,第1个人出他手里最小的牌,然后2 ...
- centos升级openssh版本
似乎升级就是简单的安装ssh包就行了,没进行其他修改,虚拟机24个中高低漏洞解决 安装最新包: 1.下载:https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/por ...