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. 9.组合模式(Composite Pattern)

    动机(Motivate):    组合模式有时候又叫做部分-整体模式,它使我们树型结构的问题中,模糊了简单元素和复杂元素的概念,客户程序可以向处理简单元素一样来处理复杂元素,从而使得客户程序与复杂元素 ...

  2. Docker 从入门到放弃(一)安装

    前言 Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的Linux机器上,也可以实现虚拟化,容器是完全使用沙箱机制,相互之间不会有任 ...

  3. 10.tesseract

    1.Tesseract-OCR简介  一个Google支持的开源的OCR图文识别开源项目.支持多种语言(我使用的是3.02 版本,支持包括英文,简体中文,繁体中文),支持Windows,Linux,M ...

  4. systemctl命令详解

    一.查询服务是否开机启动   systemctl is-enabled xxx.service 二.开机运行服务   systemctl enable xxx.service 三.取消开机运行   s ...

  5. ie8 background背景图片不显示问题

    在chrome,FF可以显示,但是在ie8背景图片显示不出来 css改为如下可以正常显示: background: url(../images/goods.png) no-repeat !import ...

  6. 用PHP来获取access_token

    $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".A ...

  7. 3D图像算法

    http://dev.gameres.com/Program/Visual/3D/3Darit.htm 3D简介 我们首先从坐标系统开始.你也许知道在2D里我们经常使用Ren?笛卡儿坐标系统在平面上来 ...

  8. 第26月第28天 avplayer cache

    1.urlsession https - (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticati ...

  9. Spark思维导图之Shuffle

  10. jira迁移数据

    jira迁移数据有两种方式 方式一: jira系统自带的备份恢复操作 最简单的,但不一定能成功   从/export/atlassian/application-data/jira/export下载至 ...