主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160

题意:求体重下降。速度添加的样例最多有多少个

依据体重降序排一下,然后求速度的最长上升子序列 ,经典的LIS问题,记录一下路径

代码例如以下:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int maxn = 1010; struct cat{
int w,s,id;
bool operator < (const struct cat &b) const
{
return w>b.w;
}
}c[maxn]; int q[maxn],path[maxn]; int bin_search(int x,int l,int r)
{
while(l<=r){
int mid=(l+r)>>1;
if(c[q[mid]].s<x) l=mid+1;
else r=mid-1;
}
return l;
}
int main()
{
//freopen("out.txt","w",stdout);
int cnt=0;
while(cin>>c[cnt].w>>c[cnt].s) c[cnt].id=cnt+1,cnt++;
sort(c,c+cnt);
//cout<<"**************"<<endl;
//for(int i=0;i<cnt;i++)
// cout<<c[i].w<<" "<<c[i].s<<" "<<c[i].id<<endl;
//cout<<"**************"<<endl;
int len=0;
q[len++]=0;
path[0]=0;
for(int i=1;i<cnt;i++){
if(c[i].s>c[q[len-1]].s){
path[i]=q[len-1];
q[len++]=i;
}
else{
int idex = bin_search(c[i].s,0,len-1);
path[i] = idex ? q[idex-1] : 0;
q[idex] = i;
}
}
printf("%d\n",len);
printf("%d\n",c[q[len-1]].id);
int tmp=q[len-1];
while(--len){
tmp = path[tmp];
printf("%d\n",c[tmp].id);
}
return 0;
}
/*******
6008 1300
6000 2100
500 2000
1000 4000
1100 3000
6000 2000
8000 1400
6000 1200
2000 1900
*****/

版权声明:本文博客原创文章,博客,未经同意,不得转载。

最新文章

  1. VS低版本打开高版本解决方案(如08打开10、12、13版本vs编译的项目)
  2. Service错误
  3. WebApi 登录身份验证
  4. POJ 3660 Cow Contest
  5. Java web 项目搭建
  6. IPayablebillItf
  7. codeforces 292E. Copying Data 线段树
  8. 字符串解析成easyui-tree的格式
  9. slf4j+log4j在Java中实现日志记录
  10. git tag 打标签
  11. Java学习笔记之——多线程
  12. python学习笔记(1)python中的注释和安装python
  13. 关于java中assert(断言)的使用讲解
  14. margin-left:-20px
  15. Win下更新pip出现OSError:[WinError17]与PerrmissionError:[WinError5]及解决
  16. 尚硅谷springboot学习25-嵌入式Servlet容器
  17. 一个比较全面 的web项目实战学习
  18. HDU 1251 统计难题(字典树模板题)
  19. 并发编程之 线程协作工具 LockSupport
  20. 【小白的CFD之旅】小结及预告

热门文章

  1. Class ThreadPoolExecutor
  2. UML 之 序列图和协作图
  3. zoj Reactor Cooling
  4. 游戏碰撞OBB算法(java代码)
  5. 【iOS开发-22】navigationBar导航栏,navigationItem建立:获取导航栏中的基本文本和button以及各种跳跃
  6. 变化App.config其中值,并保存
  7. centos7关闭防火墙(转)
  8. Hello World! 2010年山东省第一届ACM大学生程序设计竞赛
  9. Hadoop-2.2.0中文文档—— MapReduce下一代- 可插入的 Shuffle 和 Sort
  10. 乐在其中设计模式(C#) - 迭代器模式(Iterator Pattern)