【贪心】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 ...
随机推荐
- Linux拷贝U盘文件(命令行)
Linux系统有的有界面,有的没有只要命令窗口,因此导入外部文件就变得困难,没有可视化的方便. 这里通过挂载u盘进行文件拷贝. 首先挂载u盘:这里以centos为例 1.进入命令行模式下,输入命令 s ...
- Codeforces 420D Cup Trick 平衡树
Cup Trick 平衡树维护一下位置. #include<bits/stdc++.h> #include <bits/extc++.h> #define LL long lo ...
- Python 事件驱动与异步IO
一.事件驱动编程是一种编程范式,这里程序的执行流由外部事件来决定.它的特点是包含一个事件循环,当外部事件发生时使用回调机制来出发相应的处理.另外两种常见的编程范式是(单线程)同步以及多线程编程. 1. ...
- python--实践--模拟浏览器(http)登陆
#方法一:直接使用coookies登陆,此方法需要提前在浏览器中使用账号密码登陆后,获取浏览器中的cookies,在构造的请求中携带这个cookies(缺点是有时效性). #方法二:通过账号密码(Fr ...
- php5.6安装redis各个版本地址集合
igbinary扩展 http://windows.php.net/downloads/pecl/releases/igbinary/2.0.1/ redis扩展 http://windows.php ...
- P1605 迷宫 dfs回溯法
题目背景 迷宫 [问题描述] 给定一个N*M方格的迷宫,迷宫里有T处障碍,障碍处不可通过.给定起点坐标和 终点坐标,问: 每个方格最多经过1次,有多少种从起点坐标到终点坐标的方案.在迷宫 中移动有上下 ...
- 分享一段奇葩的DBMS_JOB书写经历
declare JOB_ILEARN_ONLINE number :=1; begin dbms_job.submit(JOB_ILEARN_ONLINE,'clear_product;',sysda ...
- group by 和where 条件后面不能用刚设置的别名。
select count(*),c_xy_bj a from z_user group by c_xy_bj 这个group by后面不能使用c_xy_bj 字段的别名a,只有外面再嵌套sel ...
- oracle中date数据的转换问题
(TO_NUMBER(TO_CHAR(FP.KPRQ, 'HH24')) >= 18 kprq >= to_DATE ('2017-01-12 18:00:00','yyyy-MM-dd ...
- RBM:深度学习之Restricted Boltzmann Machine的BRBM学习+LR分类—Jason niu
from __future__ import print_function print(__doc__) import numpy as np import matplotlib.pyplot as ...