zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    Shell特殊变量:Shell $0, $#, $*, $@, $?, $$和命令行参数
    linux命令学习7-jstat命令
    linux命令学习6-dpkg命令
    PSSH 批量管理服务器
    堆排序 (Heap Sort)
    极客时间-左耳听风-程序员攻略-程序员修养
    应急响应-GHO提取注册表快照
    nc替代技术方案
    从无文件技术到使用隐写术:检查Powload的演变
    CVE-2019-0797漏洞:Windows操作系统中的新零日在攻击中被利用
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4764528.html
Copyright © 2011-2022 走看看