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) ...
随机推荐
- CentOs 设置静态IP 方法[测试没问题]
首先关闭VMware的DHCP: Edit->Virtual Network Editor 选择VMnet8,去掉Use local DHCP service to distribute IP ...
- 《C++ Primer Plus》第13章 类继承 笔记
类继承通过使用已有的类(基类)定义新的来(派生类),使得能够根据需要修改编程代码.共有继承建立is-a关系,这意味着派生类对象也应该是某种基类对象.作为is-a模型的一部分,派生类继承基类的数据称源和 ...
- spring AOP底层原理实现——jdk动态代理
spring AOP底层原理实现——jdk动态代理
- Runtime 应用(一)拦截系统自带的方法交换实现
动态的交换方法能够给项目中大量已经使用的方法 进行拦截增加操作 实践:利用运行时交换系统的ImageNamed:方法 应用背景 当系统需要适配ios7和ios8时可能会有显示不同图片的需求,但在老项目 ...
- mysql的介绍和安装
本节内容 1.数据库介绍 2.mysql管理 3.mysql数据类型 4.常用mysql命令 创建数据库 外键 增删改查表 5.事务 6.索引 1.数据库介绍 什么是数据库? 数据库(Database ...
- LeetCode——Sqrt(x)
Description: Implement int sqrt(int x). Compute and return the square root of x. 好好学习数学还是非常有用的,牛顿迭代法 ...
- LeetCode——Rectangle Area
Description:https://leetcode.com/problems/rectangle-area/ public class Solution { public int compute ...
- 【BZOJ3434】[Wc2014]时空穿梭 莫比乌斯反演
[BZOJ3434][Wc2014]时空穿梭 Description Input 第一行包含一个正整数T,表示有T组数据求解每组数据包含两行,第一行包含两个正整数N,C(c>=2),分别表示空间 ...
- kafka简介【转】
一.为什么需要消息系统 () 解耦 在项目启动之初来预测将来项目会碰到什么需求,是极其困难的.消息系统在处理过程中间插入了一个隐含的.基于数据的接口层,两边的处理过程都要实现这一接口.这允许你独立的扩 ...
- 徐州网络赛J-Maze Designer【最小生成树】【LCA】
After the long vacation, the maze designer master has to do his job. A tour company gives him a map ...