hd 1677 Nested Dolls
来源:互联网 发布:网络招生渠道 编辑:程序博客网 时间:2024/04/28 14:15
比赛中没做出来,题目类似求最多需要多少拦截系统的题目.就是要求多次最长递增子序列,反过来就是求一次最长递减子序列.比赛的末尾阶段想到了用这个dp,但是n^2的复杂度是超时的,后来用模板改的nlogn的算法,结果有死循环.今天看了解题报告,发现我的整体算法是对的.即nlogn的dp,但是就是预处理的时候排序有问题,就是先按w递增,当w相等时就按h的递减排序.后来在网上搜了一下,发现是老题了,只是我没做到过...呵呵.这回真的是对nlogn的dp有了认识.希望下次碰到类似的题不会再失误了.!
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef struct
{
int w;
int h;
}Node;
Node a[20002];
int b[20002];
int n;
bool comp(Node &a, Node &b)
{
if(a.w < b.w)
return true;
else if(a.w == b.w)
{
return a.h > b.h;
}
else
return false;
}
int main()
{
int t;
int i, j, k;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(i=0; i<n; ++i)
scanf("%d%d",&a[i].w, &a[i].h);
sort(a, a+n, comp);
int cnt = 1;
b[1] = a[0].h;
for (i=1; i<n; ++i)
{
if(a[i].h <= b[cnt])
{
b[++cnt] = a[i].h;
continue;
}
int l = 1, r = cnt;
while (l < r)
{
int mid = (l+r)/2;
if(a[i].h <= b[mid])
l = mid+1;
else
r = mid;
}
b[l] = a[i].h;
}
printf("%d ", cnt);
}
return 0;
}
#include <algorithm>
#include <vector>
using namespace std;
typedef struct
{
int w;
int h;
}Node;
Node a[20002];
int b[20002];
int n;
bool comp(Node &a, Node &b)
{
if(a.w < b.w)
return true;
else if(a.w == b.w)
{
return a.h > b.h;
}
else
return false;
}
int main()
{
int t;
int i, j, k;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(i=0; i<n; ++i)
scanf("%d%d",&a[i].w, &a[i].h);
sort(a, a+n, comp);
int cnt = 1;
b[1] = a[0].h;
for (i=1; i<n; ++i)
{
if(a[i].h <= b[cnt])
{
b[++cnt] = a[i].h;
continue;
}
int l = 1, r = cnt;
while (l < r)
{
int mid = (l+r)/2;
if(a[i].h <= b[mid])
l = mid+1;
else
r = mid;
}
b[l] = a[i].h;
}
printf("%d ", cnt);
}
return 0;
}
- hd 1677 Nested Dolls
- hdu 1677 Nested Dolls
- HDU 1677Nested Dolls
- HDU 1677 Nested Dolls
- HDU 1677 Nested Dolls
- hdu 1677 Nested Dolls
- HDU 1677:Nested Dolls
- Nested Dolls
- Nested Dolls
- Nested Dolls
- HDU OJ 1677 Nested Dolls【二分,LIS】
- HDU/HDOJ 1677 Nested Dolls 搜索
- HDU 1677 Nested Dolls(排序+二分)
- HDOJ 1677 Nested Dolls(贪心+LIS)
- hdu 1677 Nested Dolls 子串
- HDU 1677 Nested Dolls (贪心)
- hdu 1677 Nested Dolls LIS + 动态规划
- zoj 2882 Nested Dolls
- 一个综合使用GDI对象的比较全面的例子
- MFC 对话框程序中直接使用RichEdit需要初始化
- IMAP
- DA04 – 动态方法绑定
- 关于MFC自定义消息的几点思考
- hd 1677 Nested Dolls
- 关于数的悖论
- 如何才能改变ORACLE9I 中系统默认的SPFILE 路径?
- GDI对象使用的几点体会
- JS(jquery)实现图片放大镜效果
- TTS在185系统中的应用
- 在工作中追女指导原则
- DA05 – 控制数据更新的高级选项
- ASP.NET 2.0 中的异步页