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 ...
随机推荐
- 使用bcftools提取指定样本的vcf文件(extract specified samples in vcf format)
1.下载安装bcftools. 2.准备样本ID文件,这里命名为samplelistname.txt,一个样本一行,如下所示: sample1 sample2 sample3 3.输入命令: bcft ...
- 对C# .Net4.5异步机制测试
static void Main(string[] args) { Test(); // 这个方法其实是多余的, 本来可以直接写下面的方法 // await GetName() // 但是由于控制台的 ...
- appium desktop 1.7 的swipe功能不能用,重写。
rt // @Override public void swipe(int startx,int starty,int endx,int endy,int ms){ Duration duration ...
- JVM与GC
1.JVM的内存分配参考文章: https://www.cnblogs.com/wangjzh/p/5258254.html 2. java之GC https://www.cnblogs.com/hn ...
- 修复./mysql/proc
mysql数据库只能建不能删的错误提示及处理方法: mysql> drop database zabbixaa; ERROR 145 (HY000): Table ‘./mysql/proc‘ ...
- Mark标记功能的实现(像手工标记的一样)
今天看到一个网站的标记功能,觉得很不错,先记录一下,emm <!DOCTYPE html> <html lang="en"> <head> &l ...
- Git(管理修改)
现在,假定你已经完全掌握了暂存区的概念.下面,我们要讨论的就是,为什么Git比其他版本控制系统设计得优秀,因为Git跟踪并管理的是修改,而非文件. 你会问,什么是修改?比如你新增了一行,这就是一个修改 ...
- 阅读:重新介绍 JavaScript(JS教程)
这篇文章是记录自己阅读重新介绍 JavaScript(JS 教程)的记录和个人体会 在线调试代码工具:https://codepen.io/pen 引言 分歧根源:名字Javascript和Java有 ...
- Elasticsearch学习笔记——安装、数据导入和查询
到elasticsearch网站下载最新版本的elasticsearch 6.2.1 ? 1 https://www.elastic.co/downloads/elasticsearch 中文文档请参 ...
- JS盒模型
JS盒模型 ***** 1.width | height parseInt(getComputedStyle(ele, null).getPropertyValue('width')) parseIn ...