美人鱼 hdu 5784
Peter has a sequence a1,a2,...,ana1,a2,...,an and he define a function on the sequence -- F(a1,a2,...,an)=(f1,f2,...,fn)F(a1,a2,...,an)=(f1,f2,...,fn) , where fifi is the length of the longest increasing subsequence ending with aiai .
Peter would like to find another sequence b1,b2,...,bnb1,b2,...,bn
in such a manner that F(a1,a2,...,an)F(a1,a2,...,an)
equals to F(b1,b2,...,bn)F(b1,b2,...,bn)
. Among all the possible sequences consisting of only positive integers, Peter wants the lexicographically smallest one.
The sequence a1,a2,...,ana1,a2,...,an
is lexicographically smaller than sequence b1,b2,...,bnb1,b2,...,bn
, if there is such number ii
from 11
to nn
, that ak=bkak=bk
for 1≤k<i1≤k<i
and ai<biai<bi
.InputThere are multiple test cases. The first line of input contains an integer TT
, indicating the number of test cases. For each test case:
The first contains an integer nn
(1≤n≤100000)(1≤n≤100000)
-- the length of the sequence. The second line contains nn
integers a1,a2,...,ana1,a2,...,an
(1≤ai≤109)(1≤ai≤109)
.OutputFor each test case, output nn
integers b1,b2,...,bnb1,b2,...,bn
(1≤bi≤109)(1≤bi≤109)
denoting the lexicographically smallest sequence.
Sample Input
3
1
10
5
5 4 3 2 1
3
1 3 5
Sample Output
1
1 1 1 1 1
1 2 3
题意:
就是求fi,即求以ai为最后一位的最长子序列
解法:
扫描这一个数组a,每一个数进入dp数组,在里面找到<=a[i]的下标最小的指针,在这里面存储a[i]。
lower_bound(dp,dp+n,a[i])-dp+1 这个是找到>=a[i]的最小指针减去dp数组的首指针再加1
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#define inf 0x3f3f3f
using namespace std;
typedef long long ll;
ll a[110000],dp[110000]; int main()
{
int t;
cin>>t;
while(t--)
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%I64d",&a[i]);
memset(dp,inf,sizeof(dp));
for(int i=0;i<n-1;i++)
{
*lower_bound(dp,dp+n,a[i])=a[i];
printf("%d ",lower_bound(dp,dp+n,a[i])-dp+1);
}
*lower_bound(dp,dp+n,a[n-1])=a[n-1];
printf("%d\n",lower_bound(dp,dp+n,a[n-1])-dp+1);
}
return 0;
}
美人鱼 hdu 5784的更多相关文章
- HDU 5784 (计算几何)
Problem How Many Triangles (HDU 5784) 题目大意 给定平面上的n个点(n<2000),询问可以组成多少个锐角三角形. 解题分析 直接统计锐角三角形较困难,考虑 ...
- hdu 5784 How Many Triangles 计算几何,平面有多少个锐角三角形
How Many Triangles 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5784 Description Alice has n poin ...
- HDU 5784 How Many Triangles
计算几何,极角排序,双指针,二分. 直接找锐角三角形的个数不好找,可以通过反面来求解. 首先,$n$个点最多能组成三角形个数有$C_n^3$个,但是这之中还包括了直角三角形,钝角三角形,平角三角形,我 ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
随机推荐
- filter listener interceptor的区别
转自: http://www.cnblogs.com/shangxiaofei/p/5328377.html https://www.cnblogs.com/jinb/p/6915351.html 一 ...
- Maven教程(2)--Maven的配置,MyEclipse与Eclipse的配置
1.修改Maven的 repository的路径 2.找到mirrors 使用阿里云镜像 <mirror> <id>alimaven</id> <name&g ...
- [CF833B] The Bakery
Description 将一个长度为n的序列分为k段 使得总价值最大一段区间的价值表示为区间内不同数字的个数 \(n\leq 35000,k\leq 50,1\leq a_i\leq n\) Solu ...
- SpringMVC4集成ehcache
前言 使用SpringMVC4集成ehcache来缓存服务器数据. 开发环境 SpringMVC4.ehcache2.6. 项目结构 SpringMVC 集成ehcache 1.pom.xml //除 ...
- python元祖操作和内置方法
1 元祖:元祖可以理解为一个不可变的列表 2 用途:用于存放多个值,当存放的多个值只有读的需求而没有改的需求时用元祖最合适 3 定义:在()内用逗号分隔开多个任意类型的值.注意:当只有一个元素的时候, ...
- [转]JS组件系列——Bootstrap组件福利篇:几款好用的组件推荐
本文转自:https://www.cnblogs.com/landeanfen/p/5461849.html#_label3 阅读目录 一.时间组件 1.效果展示 2.源码说明 3.代码示例 二.自增 ...
- C#实现微信AES-128-CBC加密数据的解密
小程序登录时,获得用户的信息,只是昵称,无法用作ID.而有用的数据,都加密着,腾讯给出了解密的方法: 加密数据解密算法 接口如果涉及敏感数据(如wx.getUserInfo当中的 openId 和un ...
- c# 过滤html
public static string StripHTML(string html) { try { System.Text.RegularExpressions.Regex regex1 = ne ...
- scala中的isInstanceOf和asInstanceOf
如果实例化了子类的对象,但是将其赋予了父类类型的变量, 在后续的过程中,又需要将父类类型的变量转换为子类类型的变量,应该如何做? Ø 首先,需要使用isInstanceOf 判断对象是否为指定类的对 ...
- [android] 手机卫士自定义滚动控件
TextView控件设置单行显示 android:singleLine=”true” 设置TextView开始的位置显示省略号,android:ellipsize=”start” 设置滚动属性,and ...