SGU 199 Beautiful People

来源:互联网 发布:linux 打开防火墙端口 编辑:程序博客网 时间:2024/06/10 13:24
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define N 500010int pre[N],id[N];struct peo{int s,b,id;void read(){scanf("%d%d",&s,&b);}bool operator <(const peo &t)const{if(s==t.s) return b>t.b;else return s<t.s;}}mem[N];int main(){int n,m,i,j,k;while(scanf("%d",&n)!=EOF){for(i=1;i<=n;i++){mem[i].read();mem[i].id=i;}sort(mem+1,mem+1+n);int len=1,low,high;id[1]=1;for(i=2;i<=n;i++){if(mem[id[len]].b<mem[i].b){len++;id[len]=i;pre[i]=id[len-1];}low=1,high=len;while(low<high){int mid=(low+high)/2;if(mem[id[mid]].b<mem[i].b) low=mid+1;else high=mid;}id[low]=i;pre[i]=id[low-1];}printf("%d\n",len);for(i=id[len];i;i=pre[i]){printf("%d ",mem[i].id);}printf("\n");}return 0;}

0 0
原创粉丝点击