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 ...
随机推荐
- 【译】11. Java反射——动态代理
原文地址:http://tutorials.jenkov.com/java-reflection/dynamic-proxies.html 博主最近比较忙,争取每周翻译四篇.等不急的请移步原文网页. ...
- opencv: flip函数的使用;
flip函数用于图像翻转,比较方便.在opencv中有几种形式: C++: void flip(InputArray src, OutputArray dst, int flipCode) Pytho ...
- HDU5542 BIT优化dp
http://acm.hdu.edu.cn/showproblem.php?pid=5542 题意:求严格递增的长度为M的序列的组数. 当dp的优化方案不那么容易一眼看出来的时候,我们可以考虑先写一个 ...
- perl trick
一.die if以及文件的操作 #!/usr/bin/perl -w use strict; die "USAGE:\n\tperl $0 <><><>\ ...
- 腾讯云ping wget yum 常用命令设置问题
遇到ping wget yum 命令不能正常使用的情况是因为腾讯云有些配置: root执行如下即可: wget -q http://mirrors.tencentyun.com/install/sof ...
- 网络编程基础【day10】:操作系统介绍
一.为什么要有操作系统 现代的计算机系统主要是由一个或者多个处理器,主存,硬盘,键盘,鼠标,显示器,打印机,网络接口及其他输入输出设备组成. 一般而言,现代计算机系统是一个复杂的系统. 其一:如果每位 ...
- Spring Boot笔记五: Web开发之Webjar和静态资源映射规则
目录 Webjar /** 访问当前项目的任何资源 欢迎页 标签页图标 Webjar 开始讲到Spring Boot的Web开发了,先介绍Webjar,这个其实就是把一些前端资源以jar包的形式导入到 ...
- 关于PHP中会话技术的知识点分享
前言:在PHP中会话技术也是特别重要的,主要应用在免登录,保存一些持久化数据等等的方面,但是后期的介绍中,我将会放弃这种技术改用redis方法来替换这种方法. (一)cookie技术(即数据缓存在客户 ...
- HDU - 5119 Happy Matt Friends(dp)
题目链接 题意:n个数,你可以从中选一些数,也可以不选,选出来的元素的异或和大于m时,则称满足情况.问满足情况的方案数为多少. 分析:本来以为是用什么特殊的数据结构来操作,没想到是dp,还好队友很强. ...
- 解析ArcGis的字段计算器(一)——数值型数据计算,从“面积计算”开始
先来点儿背景知识铺垫: ArcMap的字段计算器提供了两种脚本语言的支持用以计算,两种脚本语言是VBScript与Python. 多数人选择使用前者,因为它的基本函数和Excel的函数貌似一样.注意我 ...