1893. [国家集训队2011]等差子序列(bitset)
★★ 输入文件:nt2011_sequence.in 输出文件:nt2011_sequence.out 简单对比
时间限制:0.3 s 内存限制:512 MB
【试题来源】
【问题描述】
【输入格式】
下接T组数据,每组第一行一个整数N,每组第二行为一个1到N的排列,数字两两之间用空格隔开。
【输出格式】
【样例输入】
3
1 3 2
3
3 2 1
【样例输出】
Y
【数据说明】
对于30%的数据,N<=1000
对于100%的数据,N<=10000,T<=7
对于100%的数据,时间限制为0.3s。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
using namespace std;
using std::bitset;
const int MAXN=;
bitset<MAXN>bit;
int a;
inline void read(int &n)
{
char c='+';int x=;bool flag=;
while(c<''||c>''){c=getchar();if(c=='-')flag=;}
while(c>=''&&c<=''){x=x*+(c-);c=getchar();}
n=flag==?-x:x;
}
int main()
{
freopen("nt2011_sequence.in","r",stdin);
freopen("nt2011_sequence.out","w",stdout);
int T;
read(T);
while(T--)
{
bit.reset();
int n;
read(n);
bool flag=;
for(int i=;i<=n;i++)
{
read(a);
if(flag)continue;
bit.set(a);
for(int j=a-;j!=;j--)
{
int k=a*-j;
if(k>n)continue;
if(bit.test(j)^bit.test(k))
{
flag=;
break;
}
}
}
flag==?printf("Y\n"):printf("N\n");
}
return ;
}
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<bitset>
using namespace std;
const int SIZEN=;
int N;
int A[SIZEN];
bitset<SIZEN> pre,suf;
bool test(void){//只能检测递增的
pre.reset();suf.reset();
for(int i=;i<=N;i++) suf[i]=;
static bitset<SIZEN> tmp;
for(int i=;i<=N;i++){
suf[A[i]]=;
if(i>) pre[N+-A[i-]]=;
tmp=(suf>>A[i])&(pre>>(N+-A[i]));
if(tmp.any()) return true;
}
return false;
}
void work(void){
scanf("%d",&N);
for(int i=;i<=N;i++) scanf("%d",&A[i]);
if(test()){
printf("Y\n");
return;
}
reverse(A+,A++N);
if(test()){
printf("Y\n");
return;
}
printf("N\n");
}
int main(){
freopen("nt2011_sequence.in","r",stdin);
freopen("nt2011_sequence.out","w",stdout);
int T;
scanf("%d",&T);
while(T--) work();
return ;
}
一份可以A的bool
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
using namespace std;
using std::bitset;
const int MAXN=;
bool bit[MAXN];
int a;
inline void read(int &n)
{
char c='+';int x=;bool flag=;
while(c<''||c>''){c=getchar();if(c=='-')flag=;}
while(c>=''&&c<=''){x=x*+(c-);c=getchar();}
n=flag==?-x:x;
}
int main()
{
freopen("nt2011_sequence.in","r",stdin);
freopen("nt2011_sequence.out","w",stdout);
int T;
read(T);
while(T--)
{
memset(bit,,sizeof(bit));
//bit.reset();
int n;
read(n);
bool flag=;
for(int i=;i<=n;i++)
{
read(a);
if(flag)continue;
bit[a]=;
for(int j=a-;j!=;j--)
{
int k=a*-j;
if(k>n)continue;
if(bit[j]^bit[k])
{
flag=;
break;
}
}
}
flag==?printf("Y\n"):printf("N\n");
}
return ;
}
1893. [国家集训队2011]等差子序列(bitset)的更多相关文章
- AC日记——[国家集训队2011]旅游(宋方睿) cogs 1867
[国家集训队2011]旅游(宋方睿) 思路: 树链剖分,边权转点权: 线段树维护三个东西,sum,max,min: 当一个区间变成相反数时,sum=-sum,max=-min,min=-max: 来, ...
- cogs 1901. [国家集训队2011]数颜色
Cogs 1901. [国家集训队2011]数颜色 ★★★ 输入文件:nt2011_color.in 输出文件:nt2011_color.out 简单对比时间限制:0.6 s 内存限制 ...
- BZOJ 2150 cogs 1861 [国家集训队2011]部落战争
题目描述 lanzerb的部落在A国的上部,他们不满天寒地冻的环境,于是准备向A国的下部征战来获得更大的领土. A国是一个M*N的矩阵,其中某些地方是城镇,某些地方是高山深涧无人居住.lanzerb把 ...
- happiness[国家集训队2011(吴确)]
[试题来源] 2011中国国家集训队命题答辩 [问题描述] 高一一班的座位表是个n*m的矩阵,经过一个学期的相处,每个同学和前后左右相邻的同学互相成为了好朋友.这学期要分文理科了,每个同学对于选择文科 ...
- COGS1882 [国家集训队2011]单选错位
★ 输入文件:nt2011_exp.in 输出文件:nt2011_exp.out 简单对比时间限制:1 s 内存限制:512 MB [试题来源] 2011中国国家集训队命题答辩 [问题 ...
- bzoj2144 【国家集训队2011】跳跳棋
Description 跳跳棋是在一条数轴上进行的.棋子只能摆在整点上.每个点不能摆超过一个棋子.我们用跳跳棋来做一个简单的游戏:棋盘上有3颗棋子,分别在a,b,c这三个位置.我们要通过最少的跳动把他 ...
- COGS.1901.[模板][国家集训队2011]数颜色(带修改莫队)
题目链接 COGS BZOJ2120 洛谷P1903 /* Add和Subd函数中的vis不能直接设为=1或=0 比如 l=1,r=0 -> l=3,r=5 时,[1,5]的vis标记全都是1 ...
- COGS1871 [国家集训队2011]排队(魏铭)
bzoj:http://www.lydsy.com/JudgeOnline/problem.php?id=2141 cogs:http://cogs.pro:8080/cogs/problem/pro ...
- [国家集训队2011]happiness
Description 高一一班的座位表是个n*m的矩阵,经过一个学期的相处,每个同学和前后左右相邻的同学互相成为了好朋友.这学期要分文理科了,每个同学对于选择文科与理科有着自己的喜悦值,而一对好朋友 ...
随机推荐
- 用自定义的函数将gps转换为高德坐标
<?php echo<<<_END <!doctype html> <html> <head> <meta charset=" ...
- linux怎么开启telnet服务
1>编辑telent的配置文件/etc/xinetd.d/telnet 如下: (设置disable = no,也就是开启telnet服务) service telnet { disable = ...
- [codeforces 1037D] Valid BFS? 解题报告(验证bfs序,思维题)
题目链接:http://codeforces.com/problemset/problem/1037/D 题目大意: 给出一棵树,询问一个序列是否可能为这棵树从节点1开始遍历的bfs序 题解: 对于每 ...
- MyBatis数据持久化(五)数据源配置优化
在前面的教程中,我们把数据库的驱动.用户名.密码等配置项全部写在 SqlMapConfig.xml中: <dataSource type="POOLED"> <p ...
- STM8S103之中断优先级设置
STM8S的中断由中断控制器(ITC)控制.STM8所有IO都支持中断,分为PA~PE 5个组,每组IO对应一个中断服务函数(也就是每组IO只有一个向量).STM8没有专门的中断状态寄存器,所以只能通 ...
- DotNetCore.1.0.1-VS2015Tools.Preview2.0.2 安装错误分析及解决办法(so far)
折腾了这么多天总算弄完了,真恶心.为了让其他童靴避免掉进我遇到的坑里,我决定把最近遇到问题及其解决办法总结一下,希望对大家有帮助. 1.对于2016年7月底以前安装VS用户来说,可能不会那么迫切安装这 ...
- Dispatch Groups
Dispatch Groups are objects that allow several tasks to be grouped for later joining. Tasks can be a ...
- tigergao
互联网从业 6 年.前码农&DBA,现运维&电商创业者,也在做自媒体.终生学习者. 运营微信公众号:高哥咋么看 感兴趣的朋友们可以订阅.
- CTSC2012 熟悉的文章 广义后缀自动机_单调队列
没啥难的,主要是单调队列忘了咋求了QAQ... Code: #include <cstdio> #include <algorithm> #include <cstrin ...
- js 监听ios手机键盘弹起和收起的事件
document.body.addEventListener('focusin', () => { //软键盘弹起事件 console.log("键盘弹起") }) docu ...