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
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 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\n",k);
i = dp[k--];
printf("%d",p[i].id);
while(k--){
i = pre[i];
printf(" %d",p[i].id);
}
puts("");
return 0;
}

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

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

Beautiful People 分类: Brush Mode 2014-10-01 14:33 100人阅读 评论(0) 收藏的更多相关文章

  1. MS SQL数据批量备份还原(适用于MS SQL 2005+) 分类: SQL Server 数据库 2015-03-10 14:32 103人阅读 评论(0) 收藏

    我们知道通过Sql代理,可以实现数据库的定时备份功能:当数据库里的数据库很多时,备份一个数据库需要建立对应的定时作业,相对来说比较麻烦: 还好,微软自带的osql工具,比较实用,通过在命令行里里输入命 ...

  2. A Plug for UNIX 分类: POJ 图论 函数 2015-08-10 14:18 2人阅读 评论(0) 收藏

    A Plug for UNIX Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14786 Accepted: 4994 Desc ...

  3. NYOJ-456 邮票分你一半 AC 分类: NYOJ 2014-01-02 14:33 152人阅读 评论(0) 收藏

    #include<stdio.h> #define max(x,y) x>y?x:y int main(){ int n,x,y; scanf("%d",& ...

  4. nginx 安装手记 分类: Nginx 服务器搭建 2015-07-14 14:28 15人阅读 评论(0) 收藏

    Nginx需要依赖下面3个包 gzip 模块需要 zlib 库 ( 下载: http://www.zlib.net/ ) zlib-1.2.8.tar.gz rewrite 模块需要 pcre 库 ( ...

  5. RedHat Enterprise Linux 6.4使用Centos 6 的yum源 分类: 服务器搭建 Nginx 2015-07-14 14:11 5人阅读 评论(0) 收藏

    转载自:http://blog.sina.com.cn/s/blog_50f908410101cto6.html 思路:卸载redhat自带yum,然后下载centos的yum,安装后修改配置文件 1 ...

  6. 使用Broadcast实现android组件之间的通信 分类: android 学习笔记 2015-07-09 14:16 110人阅读 评论(0) 收藏

    android组件之间的通信有多种实现方式,Broadcast就是其中一种.在activity和fragment之间的通信,broadcast用的更多本文以一个activity为例. 效果如图: 布局 ...

  7. android开发之broadcast学习笔记 分类: android 学习笔记 2015-07-19 16:33 32人阅读 评论(0) 收藏

    android中的广播用的太多了,今天稍微总结一下. 按注册方式分为两种: 1.静态注册广播: 静态注册广播就是在androidManifest.xml文件中注册广播,假设我们要实现这样一个效果,在一 ...

  8. 使用JavaScriptSerializer序列化集合、字典、数组、DataTable为JSON字符串 分类: 前端 数据格式 JSON 2014-10-30 14:08 169人阅读 评论(0) 收藏

    一.JSON简介 JSON(JavaScript Object Notation,JavaScript对象表示法)是一种轻量级的数据交换格式. JSON是"名值对"的集合.结构由大 ...

  9. vs2008 多人同时开发项目时的代码注释规范格式 分类: C#小技巧 2014-04-23 14:12 297人阅读 评论(0) 收藏

    多人同时开发一个项目,区分项目的那个窗体是谁开发的,例:下面的格式 /************************************************       模块:服务器设置   ...

随机推荐

  1. CSS3 column-rule-style 属性

    CSS column-rule-style属性用于在多列布局中指定列与列之间通过column rule属性设置的分隔线的样式.column-rule是列与列之间的一条垂直分隔线,你可以使用column ...

  2. express中使用 connect-flash 及其源码研究

    刚开始摸node.js, 在用express 4.x 的过程中 有一个connect-flash的玩意 如上图, 在 /reg 页面提交注册信息的时候 如若两次输入的密码不匹配则调用请求对象req的f ...

  3. Collection中的排序

    我们来了解一下Collection的框架与接口: Set接口下面已经有SortedSet接口,其中提供了很多自带排序的实现类,例如ThreeSet,用户还能够自定义比较器来规定自己的排序规则. 本篇着 ...

  4. char与 int 类型转化问题汇总

    1.char变为int时高位符号扩展问题 int main() { char a = 0x9a; int util; util = (int)a; if(util > 0) printf(&qu ...

  5. Hello World程序

    本文最初发表于2015-8-??,是由别的地方迁移过来的 本文利用改写内存的办法在屏幕中央显示“Hello world”字符串. 首先我们需要了解80*25彩色字符模式显示缓冲区的结构. 〉〉内存中B ...

  6. 菜鸟学习Spring——初识Spring

    一.概念. Spring是一个开源框架,Spring是于2003 年兴起的一个轻量级的Java 开发框架,由Rod Johnson 在其著作Expert One-On-One J2EE Develop ...

  7. ORACLE-用户常用数据字典的查询使用方法

    一.用户 查看当前用户的缺省表空间 SQL> select username,default_tablespace from user_users; USERNAME DEFAULT_TABLE ...

  8. web relase

    http://wenku.baidu.com/link?url=uOAV9QwXGGLjeqt6M1KTqwp0Jbhhguvz9IxExCHNiUlrYMX584Io3ByNJJIkAVzEqzv9 ...

  9. linux下安装protobuf教程+示例(详细)

    (.pb.h:9:42: fatal error: google/protobuf/stubs/common.h: No such file or directory 看这个就应该知道是没有找到头文件 ...

  10. Web开发者和设计师必须要知道的 iOS 8 十个变化

    原文出处: mobilexweb   译文出处:罗磊(@罗罗磊磊)   欢迎分享原创到伯乐头条 喜大普奔,喜极而泣,喜当爹,随着iPhone 6和iPhone 6 plus的上市,ios 8终于在上周 ...