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. NIO SocketChannel 【链接】

    Java NIO系列教程(一) Java NIO 概述 Java NIO系列教程(六) Selector Java NIO系列教程(二) Channel Java NIO系列教程(三) Buffer ...

  2. JavaSrcipt的数字(number):深入理解内部机制

    一.数字的语法 JavaScript中的数字字面量一般用十进制表示.在JavaScript中表示数字的数据类型只有一种Number,这种天使与魔鬼同体的数据类型也就只有js了. //同时表达整数和浮点 ...

  3. 利用 yEd 软件做元数据管理

    利用 yEd 软件做元数据管理 yEd Diagram editor 是我常用的 flow chart 制图工具, 另外我也用它画 ER 和 use case 图. 总结一下我喜欢 yEd 的原因:1 ...

  4. 【noip 2016】普及组

    T1.买铅笔 题目链接 #include<cstdio> #include<algorithm> #include<cstring> using namespace ...

  5. 20155324 2016-2017-2 《Java程序设计》第7周学习总结

    20155324 2016-2017-2 <Java程序设计>第7周学习总结 教材学习内容总结 认识时间与日期 - 时间的度量 1.格林威治时间(GMT):通过观察太阳而得,因为地球公转轨 ...

  6. QIM量化

    基于量化思想的水印嵌入模型的主要目的是为了实现盲检测.其主要思想是根据水印信息的不同将原始载体数据量化到不同的量化区间,而检测时根据所属的量化区间来识别水印信息.常见的两种量化方式是QIM和SCS方法 ...

  7. 时间戳time

    时间戳(timestamp)的方式:通常来说,时间戳表示的是从1970年1月1日开始按秒计算的偏移量(time.gmtime(0))此模块中的函数无法处理1970纪元年以前的时间或太遥远的未来(处理极 ...

  8. java基础 包装类

    包装类在集合中用来定义集合元素的类型. 1.Integer.MIN_VALUE:int类型的最小值:-2^31 2.Integer.MAX_VALUE:int类型的最大值:2^31-1 3.int  ...

  9. day 4 - 1 列表

    1.列表的增删改查 1) append insert extend li = ["ysg",[1,2,3,4,5],"peipei","梦幻" ...

  10. git 生成公钥 使用命令行无需输入用户名密码(windows)

    之前设置过一次,后来就忘记了,今天改完密码之后发现命令行clone时验证身份失败,重新设置公钥,记录一下 1. 由于之前设置过公钥,所以不用输入用户名密码就可以执行git命令.现在密码变了,取消公钥, ...