zoukankan      html  css  js  c++  java
  • Beautiful People 分类: Brush Mode 2014-10-01 14:33 100人阅读 评论(0) 收藏

    Beautiful People

    Time Limit: 10000/5000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others)     Special Judge

    Problem Description

          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.

    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 Brespectively (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 Input

    4
    1 1
    1 2
    2 1
    2 2

    Sample Output

    2
    1 4

    #include<cstdio>
    #include<algorithm>
    using namespace std;
    const int N=100001;
    struct P{
    	int s,b,id;
    }p[N];
    
    bool cmp(P a,P b)
    {
    	if(a.s==b.s)	return a.b>b.b;
    	return a.s<b.s;
    }
    
    int dp[N];
    int pre[N];
    int main()
    {
    	int T,n,i,k,l,r,m;
    		scanf("%d",&n);
    		for(i=1;i<=n;i++)
    		{
    			scanf("%d%d",&p[i].s,&p[i].b);
    			p[i].id=i;
    		}	
    		sort(p+1,p+n+1,cmp);
    		dp[1] = 1,k = 1;
    		for(i=2;i<=n;i++)
    		{
    			if(p[i].b > p[dp[k]].b)
    			{
    				pre[i] = dp[k];
    				dp[++k] = i;
    			}
    			else{
    				l=1,r=k;
    				while(l<r)
    				{
    					m=(l+r)>>1;
    					if(p[dp[m]].b<p[i].b)l=m+1;
    					else r=m;
    				}
    				
    				dp[l] = i;
    				pre[i] = dp[l-1];
    			}
    		}
    		printf("%d
    ",k);
    		i = dp[k--];
    		printf("%d",p[i].id);
    		while(k--){
    			i = pre[i];
    			printf(" %d",p[i].id);
    		}
    		puts("");
    	return 0;
    }
    
    

    心好累啊,完全不明白什么意思,这代码


    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    最新第四套人民币冠号大全
    使用Java程序调用MatLab
    Android 横屏时禁止输入法全屏
    linux 从命令行自动识别文件并将其打开的命令
    deep learning 的java库
    重磅!神经网络浅讲:从神经元到深度学习
    开源的c语言人工神经网络计算库 FANN
    开源java神经网络组件Joone、Encog和Neuroph
    基于Storm 分布式BP神经网络,将神经网络做成实时分布式架构
    git:could not open a connection to your authentication agent
  • 原文地址:https://www.cnblogs.com/you-well-day-fine/p/4671622.html
Copyright © 2011-2022 走看看