HDU - 1160 FatMouse's Speed 动态规划LIS,路径还原与nlogn优化
HDU - 1160
给一些老鼠的体重和速度
要求对老鼠进行重排列,并找出一个最长的子序列,体重严格递增,速度严格递减
并输出一种方案
原题等于定义一个偏序关系 $(a,b)<(c.d)$ 当且仅当 $a<c,b>d$ 然后找出最长链
...我们就按照他说的重新排个序,然后找LIS吧,不过还需要去路径还原
数据量可以用$O(n^2)$的算法
不过我这里用来$O(nlogn)$的算法加上一个路径还原
嗯,其实是在一个单调栈上乱搞的二分罢了....
最后要回溯一下并且记录答案才行

#include <bits/stdc++.h>
#define ll long long
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pp pair<int,int>
#define rep(ii,a,b) for(int ii=a;ii<=b;ii++)
#define per(ii,a,b) for(int ii=a;ii>=b;ii--)
#define show(x) cout<<#x<<"="<<x<<endl
#define show2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define show3(x,y,z) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl
#define showa(b,a) cout<<#a<<"["<<b<<"]="<<a[b]<<endl;
using namespace std;
const int maxn=1e5+10;
const int maxm=1e6+10;
const int INF=0x3f3f3f3f;
int casn,n,m,k;
struct node {
int a,b,id;
int operator <(node x){
if(x.a==a) return b>x.b;
else return a<x.a;
}
}ms[maxn];
int pre[maxn];
int stk[maxn],top;
int ans[maxn];
int main(){
//#define test
#ifdef test
freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#endif while(cin>>ms[n].a>>ms[n].b){ms[n].id=n+1;n++;}
sort(ms,ms+n);
memset(stk,0xc0,sizeof stk);
rep(i,0,n-1) ms[i].b=-ms[i].b;
rep(i,0,n-1){
int b=ms[i].b;
if(stk[top]<b){
stk[++top]=b;
pre[i]=top;
}else {
int l=1,r=top;
while(l<r){
int mid=(l+r)>>1;
if(stk[mid]<b)l=mid+1;
else r=mid;
}
stk[l]=b;
pre[i]=l;
}
}
cout<<top<<endl;
int t=top;
per(i,n,0){
if(pre[i]==t) ans[--t]=ms[i].id;
if(t<0) break;
}
rep(i,0,top-1) cout<<ans[i]<<endl;
#ifdef test
fclose(stdin);fclose(stdout);system("gedit ./out.txt");
#endif
return 0;
}
HDU - 1160 FatMouse's Speed 动态规划LIS,路径还原与nlogn优化的更多相关文章
- HDU 1160 FatMouse's Speed 动态规划 记录路径的最长上升子序列变形
题目大意:输入数据直到文件结束,每行两个数据 体重M 和 速度V,将其排列得到一个序列,要求为:体重越大 速度越低(相等则不符合条件).求这种序列最长的长度,并输出路径.答案不唯一,输出任意一种就好了 ...
- 题解报告:hdu 1160 FatMouse's Speed(LIS+记录路径)
Problem Description FatMouse believes that the fatter a mouse is, the faster it runs. To disprove th ...
- HDU 1160 FatMouse's Speed(要记录路径的二维LIS)
FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1160 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)
FatMouse's Speed Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Su ...
- HDU 1160 FatMouse's Speed LIS DP
http://acm.hdu.edu.cn/showproblem.php?pid=1160 同样是先按它的体重由小到大排,相同就按speed排就行. 这样做的好处是,能用O(n^2)枚举,因为前面的 ...
- hdu 1160 FatMouse's Speed (最长上升子序列+打印路径)
Problem Description FatMouse believes that the fatter a mouse is, the faster it runs. To disprove th ...
- hdu 1160 FatMouse's Speed(最长不下降子序列+输出路径)
题意: FatMouse believes that the fatter a mouse is, the faster it runs. To disprove this, you want to ...
- 【最长上升子序列记录路径(n^2)】HDU 1160 FatMouse's Speed
https://vjudge.net/contest/68966#problem/J [Accepted] #include<iostream> #include<cstdio> ...
随机推荐
- js中的blob,图片base64URL,file之间的关系
js的base64编码和解码 英文是这样的:// atob() 将base64解码 // btoa() 将字符串转码为base64 var str = 'javascript'; window.bto ...
- Trap 冷启动与热启动告警
冷启动: 设备断电重启. 热启动: snmp agent 从未使能到使能的操作会产生此告警.
- Eclipse复制web项目怎么改
在学习中,做一个项目时 , 完成到了某一阶段 实现了部分功能,有必要保存这一项目, 1 在以后的学习中如果能顺利的完成后续部分,可以在需要特定功能时 复习这个项目, (必要性) 2 如果在后续的 ...
- [时序图笔记] 步步为营UML建模系列五、时序图(Squence diagram)【转】
概述 顺序图是一种详细表示对象之间以及对象与参与者实例之间交互的图,它由一组协作的对象(或参与者实例)以及它们之间可发送的消息组成,它强调消息之间的顺序. 顺序图是一种详细表示对象之间以及对象与系统外 ...
- HDU 1015(字符运算 **)
题意是在一段大写英文字符中找出 5 个字符通过代入公式运算得到目标值,如有多组字符满足题意,则输出字典序最大的一组,否则输出 no solution. 应该是用深搜做的,但是直接暴力也过了……(应该没 ...
- yum 安装时错误 Errno 14 Couldn't resolve host 解决办法
后来网上查了一下说是DNS服务器错误.于是修改一下 /etc/resolv.conf 添加一个nameserver 8.8.8.8完成
- Mongodb aggregation 基本操作示例
MongoDB二个主要的操作:一个是查询,另一个是统计.对于查询而言,主要是find()方法,再配合Filters组合多个查询条件. 对于统计而言,则主要是aggregate操作,比如 group.s ...
- Native/Webview bridge for Hybrid
Native/Webview bridge for Hybrid 安装 npm i --save webview-bridge 特点 支持自定义app URL scheme 支持多种处理方式(全部涵盖 ...
- postfix 邮箱接收限制
Postfix 限制 QQ 邮箱发送到 我的 test.com 域下邮箱. 1.编辑 main.cf 添加限制: smtpd_sender_restrictions = check_sender_a ...
- Tomcat多应用启动报错:org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading Illegal access: this web application instance has been stopped already. Could not load [].
Loaded org.apache.tomcat.util.net.NioBlockingSelector$BlockPoller$RunnableRemove from .M22/lib/tomca ...