职务地址:HDU 1950

这题是求最长上升序列,可是普通的最长上升序列求法时间复杂度是O(n*n)。显然会超时。于是便学了一种O(n*logn)的方法。也非常好理解。

感觉还用到了一点贪心的思想。

详细的见这篇博客吧,写的非常通俗易懂。传送门

代码例如以下:

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <queue>
#include <map>
#include <set>
#include <algorithm> using namespace std;
#define LL long long
int a[50000], b[50000], len;
int bin_seach(int x)
{
int low=1, high=len, mid, ans;
while(low<=high)
{
mid=low+high>>1;
if(b[mid]>=x) {high=mid-1;ans=mid;}
else low=mid+1;
}
return ans;
}
int main()
{
int t, n, i, pos;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
len=0;
b[++len]=a[0];
for(i=1;i<n;i++)
{
if(a[i]>b[len])
{
b[++len]=a[i];
}
else
{
pos=bin_seach(a[i]);
b[pos]=a[i];
}
}
printf("%d\n",len);
}
return 0;
}

版权声明:本文博主原创文章,博客,未经同意不得转载。

最新文章

  1. JSON.parse与eval的区别
  2. win7配置ftp服务
  3. a questions
  4. oracle 特殊符号
  5. C#深入浅出 C#语法中的重中之重——委托(四)
  6. codeforce 600C - Make Palindrome
  7. jQuery Validate验证框架使用
  8. Unity3d fur真实毛发渲染
  9. Ubuntu12.04 下svn服务搭建及Windows客户端tortoisesvn的使用
  10. Java web 基础
  11. UML示例图
  12. jquery中防止冒泡事件
  13. BotVS配置托管者-基于新浪云
  14. sea.js简单使用教程
  15. Linux性能工具图册-便于查阅
  16. 干货!一篇文章集合所有Linux基础命令
  17. MVCC(Multi-version Cocurrent Control)多版本并发控制协议
  18. asp.net执行顺速
  19. D2
  20. 有关自动化构建gulp的搭建

热门文章

  1. 转:svn命令行操作
  2. GCC的使用(编译,链接,运行)
  3. hdu 4465 Candy(2012 ACM-ICPC 成都现场赛)
  4. (40)JS运动之右下角悬浮框
  5. BZOJ 1109 POI2007 堆积木Klo LIS
  6. 彻底理解Javascript原型继承
  7. js检测浏览器中是否安装了flash播放插件
  8. ios日历视图实现日期输入
  9. 如何使用ZEROBRANE STUDIO远程调试COCOS2D-X的LUA脚本(转)
  10. android 网络运营商的名字显示规则(锁定屏幕,下拉列表)