SGU 199 Beautiful People lcs O (nlogn) Algorithm

Source: Internet
Author: User

SGU 199 Beautiful People lcs O (nlogn) Algorithm

Click to open the link.

199. Beautiful Peopletime limit per test: 0.25 sec.
Memory limit per test: 65536 KBinput: standard
Output: standard


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 wowould simultaneouly attend the party, after a drink or two they wowould start a fight. so no two people who hate each other shoshould be invited. on the other hand, to keep the club presti ≥ at the apropriate level, administration wants to invite as your people as possible.

Being the only one among administration who is not afraid of touching a computer, you are to write a program which wocould find out whom to invite to the party.

Input
The first line of the input file contains integer N-the number of members of the club. (2 ≤ N ≤100,000 ). next N lines contain two numbers each-Si and Bi respectively (1 ≤ Si, Bi ≤109 ).

Output
On the first line of the output file print the maximum number of the people that can be invited to the party. on the second line output N integers-numbers of members to be invited in arbitrary order. if several solutions exist, output any one.

Sample test (s)
Input
4 1 1 1 2 2 1 2 Output 
 

2
1 4

Big Data

O (nlogn) algorithm is required

Binary =

Note the status of this question

Because the output path is required

So you cannot simply record that value.

Instead, we should record the location of this value.

#include
 
  #include
  
   #includeusing namespace std;const int MAXN=100100;int id[MAXN],pre[MAXN];struct Node{    int a,b,id;}node[100100];int n;int cmp(Node x,Node y){    if(x.a!=y.a)        return x.a
   
    y.b;}void print(int x){    if(x==-1)        return ;    print(pre[x]);    printf("%d ",node[x].id);}int main(){    int i,left,right,mid;    int len;    while(scanf("%d",&n)!=EOF)    {        for(i=1;i<=n;i++)        {            scanf("%d %d",&node[i].a,&node[i].b);            node[i].id=i;        }        sort(node+1,node+1+n,cmp);        //for(i=1;i<=n;i++)          //  printf("%d %d %d\n",node[i].a,node[i].b,node[i].id);        len=1;        memset(pre,-1,sizeof(pre));        id[0]=1;        for(i=2;i<=n;i++)        {            if(node[i].b>node[id[len-1]].b)            {                id[len++]=i;                pre[i]=id[len-2];                continue;            }            left=0;            right=len-1;            while(left
    
     

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.