• HDU 3729 I'm Telling the Truth


    I'm Telling the Truth

    Time Limit: 1000ms
    Memory Limit: 32768KB
    This problem will be judged on HDU. Original ID: 3729
    64-bit integer IO format: %I64d      Java class name: Main
     
    After this year’s college-entrance exam, the teacher did a survey in his class on students’ score. There are n students in the class. The students didn’t want to tell their teacher their exact score; they only told their teacher their rank in the province (in the form of intervals).

    After asking all the students, the teacher found that some students didn’t tell the truth. For example, Student1 said he was between 5004th and 5005th, Student2 said he was between 5005th and 5006th, Student3 said he was between 5004th and 5006th, Student4 said he was between 5004th and 5006th, too. This situation is obviously impossible. So at least one told a lie. Because the teacher thinks most of his students are honest, he wants to know how many students told the truth at most.
     

    Input

    There is an integer in the first line, represents the number of cases (at most 100 cases). In the first line of every case, an integer n (n <= 60) represents the number of students. In the next n lines of every case, there are 2 numbers in each line, Xi and Yi (1 <= Xi <= Yi <= 100000), means the i-th student’s rank is between Xi and Yi, inclusive.

     

    Output

    Output 2 lines for every case. Output a single number in the first line, which means the number of students who told the truth at most. In the second line, output the students who tell the truth, separated by a space. Please note that there are no spaces at the head or tail of each line. If there are more than one way, output the list with maximum lexicographic. (In the example above, 1 2 3;1 2 4;1 3 4;2 3 4 are all OK, and 2 3 4 with maximum lexicographic)
     

    Sample Input

    2
    4
    5004 5005
    5005 5006
    5004 5006
    5004 5006
    7
    4 5
    2 3
    1 2
    2 2
    4 4
    2 3
    3 4

    Sample Output

    3
    2 3 4
    5
    1 3 5 6 7

    Source

     
    解题:最大匹配
     
     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 const int maxn = 100010;
     4 int L[maxn],R[maxn],LinkX[maxn],LinkY[maxn];
     5 bool used[maxn];
     6 bool match(int u) {
     7     for(int i = L[u]; i <= R[u]; ++i) {
     8         if(!used[i]) {
     9             used[i] = true;
    10             if(LinkX[i] == -1 || match(LinkX[i])) {
    11                 LinkX[i] = u;
    12                 LinkY[u] = i;
    13                 return true;
    14             }
    15         }
    16     }
    17     return false;
    18 }
    19 int main() {
    20     int kase,n;
    21     scanf("%d",&kase);
    22     while(kase--) {
    23         scanf("%d",&n);
    24         for(int i = 1; i <= n; ++i)
    25             scanf("%d%d",L + i,R + i);
    26         memset(LinkX,-1,sizeof LinkX);
    27         memset(LinkY,-1,sizeof LinkY);
    28         int ret = 0;
    29         for(int i = n; i >= 1; --i) {
    30             memset(used,false,sizeof used);
    31             if(match(i)) ++ret;
    32         }
    33         printf("%d
    ",ret);
    34         for(int i = 1; i <= n && ret; ++i) {
    35             if(LinkY[i] != -1) {
    36                 if(--ret) printf("%d ",i);
    37                 else printf("%d
    ",i);
    38             }
    39         }
    40     }
    41     return 0;
    42 }
    View Code
  • 相关阅读:
    MySQL-子查询,派生表,通用表达式
    MySQL-插入数据(INSERT)
    IDEA中如何使用debug调试项目 一步一步详细教程
    Java相对路径/绝对路径总结
    jsp九个内置对象、四个域对象及Servlet的三大域对象
    浅析MVC模式与三层架构的区别
    三层架构详解
    Java集合中List,Set以及Map等集合体系详解
    POJ3233 [C
    HDU 2829 [Lawrence] DP斜率优化
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4764528.html
Copyright © 2020-2023  润新知