ACdream 1216
来源:互联网 发布:asp 导出数据到excel 编辑:程序博客网 时间:2024/06/05 20:26
本题目,我用了一种较简单的解题方法依然求LIS
但不同的是要先进行排序,排序方法为先按x 升序排序,在按照y降序排序,然后用nlogn算法即可求解LIS
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;#define INF 1000010000const int maxn = 100100;struct node {int x,y,id;node (int x=0,int y=0,int id=0):x(x),y(y),id(id){}bool operator <(const node& rhs) const{return x<rhs.x||x==rhs.x&&y>rhs.y;}}a[maxn];int n,d[maxn],g[maxn];int main(){ while(scanf("%d",&n)==1){ for(int i=0;i<n;i++){ scanf("%d %d",&a[i].x,&a[i].y); a[i].id=i+1; } for(int i=1;i<=n;i++) g[i]=INF; sort(a,a+n); int ans=1; for(int i=0;i<n;i++){ int posi=lower_bound(g+1,g+n+1,a[i].y)-g; g[posi]=a[i].y; d[i]=posi; ans=max(ans,posi); } int temp=ans,nx,ny; printf("%d\n",ans); for(int i=n-1;i>=0;i--){ if(d[i]==temp){ if(temp==ans||nx>a[i].x&&ny>a[i].y){ nx=a[i].x; ny=a[i].y; if(temp!=ans) printf(" "); temp--; printf("%d",a[i].id); } } } printf("\n"); } return 0;}
0 0
- ACdream 1216
- ACdream 1216 Beautiful People
- ACdream
- Acdream
- ACdream
- ACdream
- ACdream
- ACdream
- ACdream
- ACdream
- ACdream
- ACdream
- ACdream
- ACdream
- ACdream
- ACdream 1216 Beautiful People(LIS)
- 二路单调自增子序列模型【acdream 1216】
- ACdream 1216 (ASC训练1) Beautiful People(DP)
- iPhone 6/6 Plus 出现后,如何改进工作流以实现一份设计稿支持多个尺寸?
- Codefoeces 2B. The least round way
- 算法学习 - LRUCache学习(C++)
- 总结 thinkphp 发邮件 找回密码 问题
- 当今流行的HTML5技术门户网站——HTML5星空
- ACdream 1216
- [LeetCode] Restore IP from string 从字符串恢复IP地址
- window下使用dos 管理用户
- 使用ASM存储EXPDP转储文件
- vs2010 头文件注意事项
- 郑州大学第八届校赛正式赛题解
- Java读取注册表的三种方法
- 使用Eclipse构建Maven的SpringMVC项目
- ASP.Net TextBox只读时不能取值的解决方案