标签:
The most prestigious sports club in one city has exactly N members. Each of its members is strong and beautiful. More precisely, i-th member of this club (members being numbered by the time they entered the club) has strength Si and beauty Bi. Since this is a very prestigious club, its members are very rich and therefore extraordinary people, so they often extremely hate each other. Strictly speaking, i-th member of the club Mr X hates j-th member of the club Mr Y if Si <= Sj and Bi >= Bj or if Si >= Sj and Bi <= Bj (if both properties of Mr X are greater then corresponding properties of Mr Y, he doesn‘t even notice him, on the other hand, if both of his properties are less, he respects Mr Y very much).
To celebrate a new 2003 year, the administration of the club is planning to organize a party. However they are afraid that if two people who hate each other would simultaneouly attend the party, after a drink or two they would start a fight. So no two people who hate each other should be invited. On the other hand, to keep the club prestige at the apropriate level, administration wants to invite as many people as possible.
Being the only one among administration who is not afraid of touching a computer, you are to write a program which would find out whom to invite to the party.
4 1 1 1 2 2 1 2 2
2 1 4
#include<stdio.h> #include<string.h> #include<algorithm> #include<stdlib.h> using namespace std; const int maxn=1e5+200; const int INF = 0x3f3f3f3f; int dp[maxn],endminv[maxn]; //dp[i]表示以i结尾的最长递增子序列长度 //endminv[i]表示LIS长度为i时,LIS结尾的最小值是多少 int path[maxn]; struct Number{ int x,y,idx; }numbers[maxn]; bool cmp(Number a,Number b){ if(a.x==b.x) return a.y>b.y; //必须有这个排序,下面那个样例就卡这里不排序的写法 return a.x<b.x; } int BinSearch(int l,int r,int key){ //二分查找大于等于key的第一个位置(下界) int md; while(l<r){ md=(l+r)/2; if(endminv[md]>key){ r=md; }else if(endminv[md]<key){ l=md+1; }else{ return md; } } return l; } int main(){ int n; while(scanf("%d",&n)!=EOF){ for(int i=1;i<=n;i++){ scanf("%d%d",&numbers[i].x,&numbers[i].y); numbers[i].idx=i; } sort(numbers+1,numbers+1+n,cmp); memset(endminv,INF,sizeof(endminv)); int len=1,x,maxv=0; for(int i=1;i<=n;i++){ x=BinSearch(1,n,numbers[i].y); endminv[x]=numbers[i].y; if(x>=len){ len++; } dp[i]=x; } len = len -1; printf("%d\n",len); int i,minx=INF,miny=INF; int fir=1; for(i=n;i>=1;i--){ if(dp[i]==len){ if(numbers[i].x<minx&&numbers[i].y<miny){ len--; minx=numbers[i].x; miny=numbers[i].y; if(fir){ fir=0; }else printf(" "); printf("%d",numbers[i].idx); } } } } return 0; } /* 5 1 3 2 6 3 1 3 2 3 3 */
ACdream 1216——Beautiful People——————【二维LIS,nlogn处理】
标签:
原文地址:http://www.cnblogs.com/chengsheng/p/4870651.html