HDU1160FatMouse's Speed
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
const int maxn=;
struct point
{
int w,s,per,id;
}p[maxn];
int cmp(point a,point b)
{
return a.s>b.s;
}
int dp[maxn];
int main()
{
int i,j,k,n,m;
n=;
memset(dp,,sizeof(dp));
while(scanf("%d%d",&p[n].w,&p[n].s)!=EOF)
{
p[n].id=n;
p[n].per=;
n++;
}
sort(p+,p+n,cmp);
int max;
dp[]=;//dp[i]记录以第i个元素结尾的最长递增的长度
for(i=;i<n;i++)
{
max=;
for(j=;j<i;j++)
{
if(p[j].w<p[i].w && p[j].s>p[i].s)
{
if(dp[j]>=max)
{
max=dp[j];
p[i].per=j;//记录i位置的前驱
}
}
dp[i]=max+;
}
}
max=-0x3f3f3f3f;
int end;
for(i=;i<n;i++)
{
if(max<=dp[i])
{
max=dp[i];
end=i;
}
}
printf("%d\n",max);
stack<int> ok;
while(end!=)
{
ok.push(end);
end=p[end].per;
}
while(!ok.empty())
{
printf("%d\n",p[ok.top()].id);
ok.pop();
}
return ;
} /*二分写法*/
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
struct X{
int s,w,sb;
};
bool cmp(X a,X b)
{
return (a.s>b.s)||(a.s==b.s&&a.w>b.w);//这里排序注意了,由于本题数据水的不能再水,a.w<b.w也过了,正解应该是a.w>b.w
}
X xx[];
int pre[];
int fnm[];
int shuchu[];
int main()
{
int i=,n=,w,s;
while(scanf("%d%d",&w,&s)!=EOF)
{
xx[n].w=w;
xx[n].s=s;
xx[n].sb=n++;
}
n--;
sort(xx+,xx+n+,cmp);/*
for(i=1;i<=n;i++)
printf("%d %d\n",xx[i].w,xx[i].s);*/
int lsb=,j,l,r;
fnm[]=;
pre[fnm[]]=-;
for(i=;i<=n;i++)
{
l=,r=lsb;
while (l<=r) //二分查找
{
int mid = (l+r)>>;
if (xx[fnm[mid]].w < xx[i].w)
l=mid+;
else
r=mid-;
}
j=l;
if(j>lsb)
lsb++;
fnm[j]=i;//存下标,相当于c[j]=a[i];
if(j!=)//fnm小标从0开始,所以要判断第一个
pre[i]=fnm[j-];//j-1的元素肯定是最长递增中的元素
else
pre[i]=-;
}
printf("%d\n",lsb+);
int xsb=fnm[lsb];
i=;
while(pre[xsb]!=-)
{
shuchu[i++]=xx[xsb].sb;
xsb=pre[xsb];
}
printf("%d\n",xx[xsb].sb);
for(i=lsb-;i>=;i--)
printf("%d\n",shuchu[i]);
return ;
}
HDU1160FatMouse's Speed的更多相关文章
- HDU-1160-FatMouse's Speed(线性DP,LIS)
FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 动态规划:HDU1160-FatMouse's Speed(记录动态规划状态转移过程)
FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU-1160-FatMouse's Speed(DP, 最长递增子序列)
链接: https://vjudge.net/problem/HDU-1160 题意: FatMouse believes that the fatter a mouse is, the faster ...
- hdu FatMouse's Speed 动态规划DP
动态规划的解决方法是找到动态转移方程. 题目地址:http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=3§ionid ...
- LYDSY模拟赛day2 Dash Speed
/* 弃坑 */ #include<cstdio> #include<algorithm> using namespace std; ,M=N*; ],nxt[N<< ...
- FatMouse's Speed——J
J. FatMouse's Speed FatMouse believes that the fatter a mouse is, the faster it runs. To disprove th ...
- OpenVZ VPS加速方案–Final Speed
body,td { font-family: 微软雅黑; font-size: 10pt } OpenVZ VPS加速方案–Final Speed OpenVZ VPS加速方案–Final Spe ...
- UNITY3D单词学习 speed和velocity的区别
在日常用语中,这两个词没有区别,可以通用. 而在物理学里,velocity 是一个矢量(vector quantity)表示起点与终点间直线距离的长度除以所用时间所得的量,并注明方向;而 speed ...
- HD1160FatMouse's Speed(最长单调递增子序列)
FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
随机推荐
- N76E003学习之路(二)
最近一直在想N76E003和STM8M003的对比情况,在网上找了不少资料,看了不少文档,具体总结如下: STM8S003F3P6:一共20个脚,最多支持16个GPIO,支持16个外部中断:2个16位 ...
- ubuntu下code::blocks设置运行窗口为gnome命令行
code::blocks编译运行C++程序(F9)默认出现的运行串口在有鼠标的情况下进行粘贴还是很方便的,只要按下鼠标滑轮,位与剪切板中的数据就能粘贴到运行串口中.但是对于用笔记本而且没有鼠标地童鞋这 ...
- Android 使用Spinner实现下拉列表
课程目标1.了解Spinner下拉列表的使用和功能2.学会使用系统默认的Spinner3.学会使用自定义样式的Spinner 执行步骤第一步:添加一个下拉列表项的list,这里添加的项就是下拉列表的菜 ...
- 当新增页面和编辑页面使用同一jsp时
<c:if test="${type eq '1'}"><title>新增页面</title></c:if> <c:if te ...
- Day04_数据类型占位符使用及进制转换
2013年10月09日 星期三 10时03分51秒 回顾: 1.变量 2.scanf标准函数 字符类型是一种数据类型 在C语言程序中字符类型用char表示 字符类型中包含了256个不同的字符,例如 ...
- ts和js中let和var定义变量的区别
javascript 严格模式 第一次接触let关键字,有一个要非常非常要注意的概念就是”JavaScript 严格模式”,比如下述的代码运行就会报错: let hello = 'hello worl ...
- Android 使用动画效果后的控件位置处理 类似系统通知栏下拉动画
Android的动画的使用,请参考.Android的动画,在设计方面,我有点不太理解,觉得这样搞很怪,因为在控件动画后,即使设置了停留在动画结束时的位置,我们也确实看到了控件停在那个位置,但其实该控件 ...
- JS三级联动实例
简单的HTML实例: <h4>选择省</h4> <div class="selectSheng"></div> <select ...
- python 10分钟入门pandas
本文是对pandas官方网站上<10 Minutes to pandas>的一个简单的翻译,原文在这里.这篇文章是对pandas的一个简单的介绍,详细的介绍请参考:Cookbook .习惯 ...
- mysql 修改配置文件性能优化
vim /etc/my.cnf 原配置文件 [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock user=mysql # ...