UVa1608 UVaLive6258 Non-boring sequences
填坑系列(p.248)
比较神
从两端枚举
最坏复杂度就成O(nlogn)了
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string> using namespace std; void setIO(const string& a) {
freopen((a + ".in").c_str(), "r", stdin);
freopen((a + ".out").c_str(), "w", stdout);
} template<typename Q> void read(Q& x) {
static char c;
static bool f;
for(f = ; c = getchar(), !isdigit(c); ) if(c == '-') f = ;
for(x = ; isdigit(c); c = getchar()) x = x * + c - '';
if(f) x = -x;
}
template<typename Q> Q read() {
static Q x; read(x);
return x;
} const int N = + ; int a[N], lp[N], rp[N]; #include<map>
map<int, int> cur; bool unique(int p, int l, int r) {
return lp[p] < l && rp[p] > r;
} bool check(int L, int R) {
if(L >= R) return ;
for(int k = ; L + k <= R - k; k++) {
if(unique(L + k, L, R)) return check(L, L + k - ) && check(L + k + , R);
if(unique(R - k, L, R)) return check(L, R - k - ) && check(R - k + , R);
}
return ;
} int main() {
#ifdef DEBUG
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif int T = read<int>();
while(T--) {
int n = read<int>();
cur.clear();
for(int i = ; i <= n; i++) {
read(a[i]);
if(cur.count(a[i])) lp[i] = cur[a[i]];
else lp[i] = ;
cur[a[i]] = i;
}
cur.clear();
for(int i = n; i >= ; i--) {
if(cur.count(a[i])) rp[i] = cur[a[i]];
else rp[i] = n + ;
cur[a[i]] = i;
}
puts(check(, n) ? "non-boring" : "boring");
} return ;
}
UVa1608 UVaLive6258 Non-boring sequences的更多相关文章
- 8-16 不无聊序列 non-boring sequences uva1608
题意: 如果一个序列的任意连续子序列中至少有一个只出现一次的元素 则称这个序列是 不无聊序列 输入一个n个元素的序列a 判断是不是不无聊序列 一开始想当然 以为只要 2位的子序列都满足即可 ...
- uva1608 Non-boring sequences
某个序列找到唯一元素后,判断被分成的两边的序列即可问题在于找到唯一元素连续序列,重复元素的问题:感觉很有一般性 查找相同元素用map,last,next存上一个相同元素的位置复杂度计算有点思考:记录l ...
- 题解 UVA1608 【不无聊的序列 Non-boring sequences】
思路: 算法很显然: 一.在区间\([l,r]\)找到一个只出现一次的元素P(如果不存在,那么序列\(boring\)) 二.递归处理区间\([l,p-1]\)和区间\([p+1,r]\). 其关键在 ...
- 【BZOJ-4059】Non-boring sequences 线段树 + 扫描线 (正解暴力)
4059: [Cerc2012]Non-boring sequences Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 440 Solved: 16 ...
- BZOJ 4059: [Cerc2012]Non-boring sequences ( )
要快速在一段子序列中判断一个元素是否只出现一次 , 我们可以预处理出每个元素左边和右边最近的相同元素的位置 , 这样就可以 O( 1 ) 判断. 考虑一段序列 [ l , r ] , 假如我们找到了序 ...
- ●UVA 1608 Non-boring sequences
题链: https://vjudge.net/problem/UVA-1608#author=chenchonghan题解: 分治 如果一个区间[l,r]里面在p位置出现了一个只出现一次的元素,(如果 ...
- UVA1608-Non-boring sequences(分治)
Problem UVA1608-Non-boring sequences Accept: 227 Submit: 2541Time Limit: 3000 mSec Problem Descript ...
- poj 1776 Task Sequences
http://poj.org/problem?id=1776 题意: 有一个机器要完成N个作业, 给你一个N*N的矩阵, M[i][j]=1,表示完成第i个作业后不用重启机器,继续去完成第j个作业 M ...
- 2015 Multi-University Training Contest 3 hdu 5324 Boring Class
Boring Class Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
随机推荐
- C语言带参数的main函数
C语言带参数的main函数 #include<stdio.h> int main(int argc,char*argv[]) { int i; ;i<argc;i++) printf ...
- 【POJ1707】【伯努利数】Sum of powers
Description A young schoolboy would like to calculate the sum for some fixed natural k and different ...
- php 连接mysql数据库并显示数据 实例 转载
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- 读书笔记之 - javascript 设计模式 - 装饰者模式
本章讨论的是一种为对象增添特性的技术,它并不使用创建新子类这种手段. 装饰者模式可以透明地把对象包装在具有同样接口的另一对象之中,这样一来,你可以给一些方法添加一些行为,然后将方法调用传递给原始对象. ...
- AS3.0面向对象的写法,类和实例
package /*package是包路径,例如AS文件在ActionScript文件夹下,此时路径应为package ActionScript.必须有的.package中只能有一个class,在一个 ...
- table 添加右键,并获取选中行信息
import java.awt.BorderLayout; import java.awt.Color; import java.awt.event.ActionEvent; import java. ...
- C# 启动和结束一个线程
在程序执行中会遇到启动本软件的exe问,或者启用其它的exe文件,已达到执行某些操作的作用.下面是两种最常见的启动exe文件. 1.调用系统dll使用其提供的方法. 引用的dll, [DllImpor ...
- Kernel Bypass & Offload 介绍
系统网络优化可以有两方面的工作可以做:1 绕开内核(bypass):2 用硬件替代软件(offload). 具体包括: 1. 绕开内核: 不使用内核内核子系统的功能,采用自己实现的相同功能的代码来处理 ...
- GHOST备份
整理日: 2015年2月16日 GHOST Disk2GHO STEP01 STEP02 STEP03 STEP04 STEP05 STEP06 STEP07 STEP08 STEP09 STEP10
- 前端图片预览,上传前预览,兼容IE7、8、9、10、11,Firefox,Chrome(学习到的知识)
文章地址:http://www.cnblogs.com/rubylouvre/p/4597344.html 一.window.URL 在Chrome中,window.URL和window.webkit ...