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优化的更多相关文章

  1. HDU 1160 FatMouse's Speed 动态规划 记录路径的最长上升子序列变形

    题目大意:输入数据直到文件结束,每行两个数据 体重M 和 速度V,将其排列得到一个序列,要求为:体重越大 速度越低(相等则不符合条件).求这种序列最长的长度,并输出路径.答案不唯一,输出任意一种就好了 ...

  2. 题解报告:hdu 1160 FatMouse's Speed(LIS+记录路径)

    Problem Description FatMouse believes that the fatter a mouse is, the faster it runs. To disprove th ...

  3. HDU 1160 FatMouse's Speed(要记录路径的二维LIS)

    FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  4. HDU 1160 FatMouse's Speed (动态规划、最长下降子序列)

    FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  5. HDU 1160 FatMouse's Speed (DP)

    FatMouse's Speed Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Su ...

  6. HDU 1160 FatMouse's Speed LIS DP

    http://acm.hdu.edu.cn/showproblem.php?pid=1160 同样是先按它的体重由小到大排,相同就按speed排就行. 这样做的好处是,能用O(n^2)枚举,因为前面的 ...

  7. hdu 1160 FatMouse's Speed (最长上升子序列+打印路径)

    Problem Description FatMouse believes that the fatter a mouse is, the faster it runs. To disprove th ...

  8. hdu 1160 FatMouse's Speed(最长不下降子序列+输出路径)

    题意: FatMouse believes that the fatter a mouse is, the faster it runs. To disprove this, you want to ...

  9. 【最长上升子序列记录路径(n^2)】HDU 1160 FatMouse's Speed

    https://vjudge.net/contest/68966#problem/J [Accepted] #include<iostream> #include<cstdio> ...

随机推荐

  1. 使用eclipse粗略统计代码代数【原】

  2. java assert的用法简介【转】

    assert的基本用法 assertion(断言)在软件开发中是一种常用的调试方式,很多开发语言中都支持这种机制,如C,C++和Eiffel等,但是支持的形式不尽相同,有的是通过语言本身.有的是通过库 ...

  3. C#数据结构学习

    Collection类学习 using System; using System.Collections.Generic; using System.Linq; using System.Text; ...

  4. Openresty 学习笔记(一)opm 工具的使用

    1.自1.11.2.2开始,OpenResty版本已经包含并默认安装opm.所以通常你不需要自己安装opm. 2.我们在这里只需要做一个软连接就可以了 cd /usr/local/openresty/ ...

  5. cookie与session的区别与关系

    cookie与session的区别 1. 存储位置不同 cookie存储在浏览器中 session存储在服务端里 2. 大小不同 cookie最大4K session由于是存在服务端,因此理论上没有大 ...

  6. google 谷歌地图

    https://www.cnblogs.com/yincheng/p/google-map.html https://blog.csdn.net/sinat_21189673/article/deta ...

  7. Linux centos6.7网卡配置

    系统安装完成后 以此执行以下命令 相当于自动获取IP地址 setup命令——Network configuration———Device configuration———eth0 依次保存退出 实际上 ...

  8. 转载-HashMap1.7源码分析

    原文地址-https://www.cnblogs.com/chengxiao/p/6059914.html HashMap实现原理及源码分析   哈希表(hash table)也叫散列表,是一种非常重 ...

  9. linux 下的init 0,1,2,3,4,5,6知识介绍

    一. init是Linux系统操作中不可缺少的程序之一. 所谓的init进程,它是一个由内核启动的用户级进程. 内核自行启动(已经被载入内存,开始运行,并已初始化所有的设备驱动程序和数据结构等)之后, ...

  10. python加密(MD5)

    # import hashlib # # 1. 创建一个MD5对象 # obj = hashlib.md5(b"flkjsdalkfjklasdjfklasjkflasdjklfasdjfl ...