【贪心】LIS @The 15th Zhejiang Provincial Collegiate Programming Contest E
题意要你构造一个序列,使得该序列的每个位置上的最长上升子序列的长度能构成给定的序列。
构造序列的元素要求还要求满足给定的上下界
solution
我们可以把给出的最长上升子序列的长度按升序排列,长度相同的按下标降序排列。
排完序后第一个数可以贪心的取其下界,同一层(即长度相同)的下标小的取值应该大于等于下标较大的取值
同时取值应该大于前一层下标最大且小于该位置的数
#define IN_LB() freopen("F:\\in.txt","r",stdin)
#define IN_PC() freopen("C:\\Users\\hz\\Desktop\\in.txt","r",stdin)
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
struct node {
int ind,ceil,d,u;
int ans;
} nd[maxn];
bool cmp(node a,node b) {
if(a.ceil==b.ceil)return a.ind>b.ind;
return a.ceil<b.ceil;
}
bool cmp1(node a,node b) {
return a.ind<b.ind;
}
struct qnode{
int yuanind,xianind,ceil;
};
queue <qnode> que;
int main() {
// IN_LB();
int T;
scanf("%d",&T);
while(T--) {
int n;
scanf("%d",&n);
for(int i=0; i<n; i++) {
nd[i].ind = i;
scanf("%d",&nd[i].ceil);
}
for(int i=0; i<n; i++) {
scanf("%d%d",&nd[i].d,&nd[i].u);
}
sort(nd,nd+n,cmp);
nd[0].ans = nd[0].d;
qnode seed;
seed.yuanind = nd[0].ind;
seed.xianind = 0;
seed.ceil = 1;
while(!que.empty())que.pop();
que.push(seed);
for(int i=1; i<n; i++) {
if(nd[i].ceil==nd[i-1].ceil) {
if(nd[i].ceil>1){
int exind;
while(!que.empty()) {
if(que.front().yuanind<nd[i].ind) {
exind = que.front().xianind;
break;
}
que.pop();
}
nd[i].ans = max(max(nd[exind].ans+1,nd[i-1].ans),nd[i].d);
}
else nd[i].ans = max(nd[i-1].ans,nd[i].d);
qnode cur;
cur.yuanind = nd[i].ind;
cur.xianind = i;
cur.ceil = nd[i].ceil;
que.push(cur);
} else {
int exind;
while(!que.empty()) {
if(que.front().ceil==nd[i].ceil-1&&que.front().yuanind<nd[i].ind) {
exind = que.front().xianind;
break;
}
que.pop();
}
nd[i].ans = max(nd[exind].ans+1,nd[i].d);
qnode cur;
cur.yuanind = nd[i].ind;
cur.xianind = i;
cur.ceil = nd[i].ceil;
que.push(cur);
}
}
sort(nd,nd+n,cmp1);
for(int i=0; i<n; i++) {
printf("%d%s",nd[i].ans,(i==n-1)?"\n":" ");
}
}
return 0;
}
【贪心】LIS @The 15th Zhejiang Provincial Collegiate Programming Contest E的更多相关文章
- 2018浙江省赛(ACM) The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple
我是铁牌选手 这次比赛非常得爆炸,可以说体验极差,是这辈子自己最脑残的事情之一. 天时,地利,人和一样没有,而且自己早早地就想好了甩锅的套路. 按理说不开K就不会这么惨了啊,而且自己也是毒,不知道段错 ...
- The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - L Doki Doki Literature Club
Doki Doki Literature Club Time Limit: 1 Second Memory Limit: 65536 KB Doki Doki Literature Club ...
- The 15th Zhejiang Provincial Collegiate Programming Contest(部分题解)
ZOJ 4024 Peak 题意 给出n和n个数,判断该数列是否是凸形的. 解题思路 从前往后第一对逆序数,和从后往前第一队逆序数,如果都非零而且相邻,证明该数组是凸形的. 代码 #include & ...
- The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - M Lucky 7
Lucky 7 Time Limit: 1 Second Memory Limit: 65536 KB BaoBao has just found a positive integer se ...
- The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - J CONTINUE...?
CONTINUE...? Time Limit: 1 Second Memory Limit: 65536 KB Special Judge DreamGrid has clas ...
- The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - B King of Karaoke
King of Karaoke Time Limit: 1 Second Memory Limit: 65536 KB It's Karaoke time! DreamGrid is per ...
- The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple -A Peak
Peak Time Limit: 1 Second Memory Limit: 65536 KB A sequence of integers is called a peak, if ...
- ZOJ 4033 CONTINUE...?(The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple)
#include <iostream> #include <algorithm> using namespace std; ; int a[maxn]; int main(){ ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Capture the Flag
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5503 The 12th Zhejiang Provincial ...
随机推荐
- thinkphp调用微信jssdk开发
一:准备文件,并将文件置于网站根目录下 access_token.json {"access_token":"","expire_time" ...
- HashMap、HashTable与ConcurrentHashMap区别
线程不安全的HashMap 在多线程环境下,使用HashMap进行put操作会引起死循环,导致CPU利用率接近100%,所以在并发情况下不能使用HashMap.例如,执行如下代码会引起死循环. fin ...
- nginx-fastcgi 反向代理
Nginx处理php页面 用fpm-server 基于fastcgi模块实现 Ngx_http_proxy_module 只能反代后端http server的主机 Ngx_fastcgi_prox ...
- 将input或textarea设置为disabled的样式问题
input:disabled{ -webkit-text-fill-color: #333;//是用来做填充色使用的 -webkit-opacity: 1; color: #333; } textar ...
- BZOJ2084 [Poi2010]Antisymmetry Manachar
题目传送门 - BZOJ2084 题解 对于一个0我们把它看作01,1看作10,然后只要原串中的某个子串可以通过这两个变换成为回文串就可以满足条件了. 对于转换过的串,Manachar随便弄几下就可以 ...
- BZOJ3531 [Sdoi2014]旅行 树链剖分 线段树
原文链接:http://www.cnblogs.com/zhouzhendong/p/8080189.html 题目传送门 - BZOJ3531 题意概括 一棵树,n个节点,每一个节点两个值,一个颜色 ...
- 【转】Linux 虚拟内存和物理内存的理解
http://www.cnblogs.com/dyllove98/archive/2013/06/12/3132940.html 首先,让我们看下虚拟内存: 第一层理解 1. 每个进程 ...
- Spring Boot Starters 列表
Spring Boot application starters 名称 描述 Pom spring-boot-starter 核心starter,包括自动配置支持,日志和YAML Pom spring ...
- Python图表数据可视化Seaborn:4. 结构化图表可视化
1.基本设置 import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns ...
- 000 Security的计划
可重用的,企业级的,认证和授权模块 1.主要涉及的模块 2.最终的目标 3.开发的项目模块结构