Codeforces702A - Maximum Increase【尺取】
题意:
求一个连续的最长子序列长度;
思路:
没看仔细还wa1了…以为LIS…
然后写了尺取吧。。。= =太不仔细了。不过收获是LIS特么写挫了然后看了学长的blog<-点我…
题目的挫code…
#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
using namespace std;
typedef __int64 LL;
const int N=1e5+10;
int n;
int a[N];
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
int s,t,ans,temp;
s=t=1;
ans=1;
temp=0;
while(s<=n)
{
while(t+1<=n&&a[t]<a[t+1])
{
temp=t-s+2;
t++;
}
s=t+1;
t=t+1;
ans=max(temp,ans);
}
printf("%d\n",ans);
return 0;
}
LIS的nlogn写法:
#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
using namespace std;
typedef __int64 LL;
const int N=1e5+10;
int n;
int dp[N];
int a[N];
int kill(int x,int len)
{
int s=1,t=len;
while(s<=t)
{
int mid=(s+t)/2;
if(dp[mid]>=x)//这里等于也写成末尾-1,主要是最后返回起点,因为最重要的是要找到哪个点比他大然后就放那
t=mid-1;
else
s=mid+1;
}
return s;
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
int len=1,j;
dp[1]=a[1];
for(int i=2;i<=n;i++)
{
if(a[i]<=dp[1]) //如果a[i]比dp数组的第一位小;
j=1;
else if(a[i]>dp[len]) //如果a[i]比dp数组最大的还大;
j=++len;
else
j=kill(a[i],len); //寻找在dp数组的位置;
dp[j]=a[i];
}
printf("%d\n",len);
return 0;
}
Codeforces702A - Maximum Increase【尺取】的更多相关文章
- Gym 100703I---Endeavor for perfection(尺取)
题目链接 http://codeforces.com/problemset/gymProblem/100703/I Description standard input/outputStatement ...
- hdu 4123 Bob’s Race 树的直径+rmq+尺取
Bob’s Race Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Probl ...
- Intense Heat(前缀和或尺取)
The heat during the last few days has been really intense. Scientists from all over the Berland stud ...
- HDU-4123-树形dp+rmq+尺取
Bob’s Race Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- Educational Codeforces Round 53 (Rated for Div. 2) C. Vasya and Robot 【二分 + 尺取】
任意门:http://codeforces.com/contest/1073/problem/C C. Vasya and Robot time limit per test 1 second mem ...
- NOJ 1072 The longest same color grid(尺取)
Problem 1072: The longest same color grid Time Limits: 1000 MS Memory Limits: 65536 KB 64-bit in ...
- Codeforces Educational Codeforces Round 15 A. Maximum Increase
A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #116 (Div. 2, ACM-ICPC Rules) E. Cubes (尺取)
题目链接:http://codeforces.com/problemset/problem/180/E 给你n个数,每个数代表一种颜色,给你1到m的m种颜色.最多可以删k个数,问你最长连续相同颜色的序 ...
- cf702A Maximum Increase
A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input standard ...
随机推荐
- Solidworks如何标注垂直度,平行度
1 标注一个基准特征,放到一个平面的线上即可,比如下图生成了一个基准面A 2 点击形位公差,设置形位公差的符号,公差值,相对基准面(主要那一栏),然后不要点确定,直接在图上点击某个面,就生成一个形 ...
- 【转载】.NET Remoting学习笔记(二)激活方式
目录 .NET Remoting学习笔记(一)概念 .NET Remoting学习笔记(二)激活方式 .NET Remoting学习笔记(三)信道 参考:百度百科 ♂风车车.Net 激活方式概念 在访 ...
- C3P0连接池配置和实现详解(转)
一.配置 <c3p0-config> <default-config> <!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数.Default: 3 --> ...
- 【网络协议】IP协议、ARP协议、RARP协议
IP数据报 IP是TCP/IP协议族中最核心的协议,全部的TCP.UDP.ICMP.IGMP数据都以IP数据报的格式传输.IP仅提供尽力而为的传输服务.假设发生某种错误.IP会丢失该数据.然后发送IC ...
- HDOJ_ How can I read input data until the end of file ?
Language C C++ Pascal To read numbers int n;while(scanf("%d", &n) != EOF){ ...} int n; ...
- 2016/05/25 PHP mysql_insert_id() 函数 返回上一步 INSERT 操作产生的 ID
定义和用法 mysql_insert_id() 函数返回上一步 INSERT 操作产生的 ID. 如果上一查询没有产生 AUTO_INCREMENT 的 ID,则 mysql_insert_id() ...
- A nonrecursive list compacting algorithm
A nonrecursive list compacting algorithm Each Erlang process has its own stack and heap which are al ...
- To verify Hadoop releases using GPG
To verify Hadoop releases using GPG http://hadoop.apache.org/releases.html To verify Hadoop releases ...
- poj 2228 Naptime(DP的后效性处理)
\(Naptime\) \(solution:\) 这道题不做多讲,它和很多区间DP的套路一致,但是这一道题它不允许断环成链,会超时.但是我们发现如果这只奶牛跨夜休息那么它在不跨夜的二十四个小时里一定 ...
- LIS n^2&nlogn模板
LIS nlogn模板 http://acm.hdu.edu.cn/showproblem.php?pid=1950 #include <iostream> #include <st ...