zoukankan      html  css  js  c++  java
  • ZOJ 2319 Beautiful People

    Beautiful People

    Time Limit: 5000ms
    Memory Limit: 32768KB
    This problem will be judged on ZJU. Original ID: 2319
    64-bit integer IO format: %lld      Java class name: Main
    Special Judge
     

    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 2005 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.


    This problem contains multiple test cases!

    The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.

    The output format consists of N output blocks. There is a blank line between output blocks.


    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

    1

    4
    1 1
    1 2
    2 1
    2 2


    Sample Output

    2
    1 4


     

    Source

     
    解题:转化成LIS模型。。。关键是路径的输出。。。。。。
     
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cmath>
     5 #include <algorithm>
     6 #include <climits>
     7 #include <vector>
     8 #include <queue>
     9 #include <cstdlib>
    10 #include <string>
    11 #include <set>
    12 #include <stack>
    13 #define LL long long
    14 #define pii pair<int,int>
    15 #define INF 0x3f3f3f3f
    16 using namespace std;
    17 const int maxn = 100010;
    18 struct people {
    19     int s,b,id;
    20 };
    21 people p[maxn];
    22 int q[maxn],path[maxn],tot;
    23 bool cmp(const people &x,const people &y) {
    24     if(x.s == y.s) return x.b > y.b;
    25     return x.s < y.s;
    26 }
    27 int bsearch(int low,int high,int val) {
    28     while(low <= high) {
    29         int mid = (low + high)>>1;
    30         if(p[q[mid]].b < val) low = mid+1;
    31         else high = mid-1;
    32     }
    33     return low;
    34 }
    35 int main() {
    36     int t,n,len;
    37     scanf("%d",&t);
    38     while(t--) {
    39         scanf("%d",&n);
    40         for(int i = len = 0; i < n; i++){
    41             scanf("%d %d",&p[i].s,&p[i].b);
    42             p[i].id = i+1;
    43         }
    44         sort(p,p+n,cmp);
    45         q[len++] = 0;
    46         path[0] = 0;
    47         for(int i = 1; i < n; i++){
    48             if(p[i].b > p[q[len-1]].b){
    49                 path[i] = q[len-1];//记录它前面的元素的位置
    50                 q[len++] = i;
    51             }else{
    52                 int index = bsearch(0,len-1,p[i].b);
    53                 path[i] = index?q[index-1]:0;
    54                 q[index] = i;
    55             }
    56         }
    57         printf("%d
    ",len);
    58         printf("%d",p[q[len-1]].id);
    59         int tmp = q[len-1];
    60         while(--len){
    61             tmp = path[tmp];
    62             printf(" %d",p[tmp].id);
    63         }
    64         puts("");
    65     }
    66     return 0;
    67 }
    View Code
  • 相关阅读:
    DNS原理和智能DNS及CDN
    jvm介绍及其优化
    Java Socket网络编程
    TCP/IP协议详解
    单点登录系统
    Kibana安装及使用
    【Golang】Golang Context上下文包
    常用缓存淘汰算法(LFU、LRU、ARC、FIFO、MRU)介绍和实现
    java数据持久层框架MyBatis
    MySQL数据库设计三范式
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/3998994.html
Copyright © 2011-2022 走看看