• Hdu


    先上题目

    I'm Telling the Truth

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 1013    Accepted Submission(s): 498


    Problem Description
    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
     
     
      题意是这样的:老师要统计成绩,但是不是每个学生都愿意报出自己的真实成绩,所以每个学生会报出一个分数的区间,代表他的分数有可能在这之间。现在问最多有多少个学生说了真话,并且从小到大输输出他们的编号,如果有多重情况,输出最大字典序。
      排位赛的时候觉得是求覆盖点一类的问题,想了很久也想不出,后来同学告诉我这是一题二分图,想了一下,还真是= =。
      这题是二分图的最大匹配,数据范围比较小,所以比较简单,在输入的时候正序输入,然后调用匈牙利匹配的时候逆序匹配就可以了。同时在每一次匹配的时候都记录下当前x子图的某一点a与y子图的哪一个点匹配了,然后打印就可以了。
     
    上代码:
     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <algorithm>
     4 #define MAX (100000+10)
     5 using namespace std;
     6 
     7 typedef struct
     8 {
     9     int l,r;
    10 }stu;
    11 
    12 stu p[100];
    13 
    14 int res[MAX],cx[100];
    15 bool state[MAX];
    16 
    17 bool Find(int a)
    18 {
    19     int i;
    20     for(i=p[a].l;i<=p[a].r;i++)
    21     {
    22         if(!state[i])
    23         {
    24             state[i]=1;
    25             if(res[i]==0 || Find(res[i]))
    26             {
    27                    cx[a]=i;
    28                    res[i]=a;
    29                    return 1;
    30             }
    31         }
    32     }
    33     return 0;
    34 }
    35 
    36 void hungary(int n)
    37 {
    38     int i,count=0;
    39     bool f;
    40     memset(res,0,sizeof(res));
    41     memset(cx,0,sizeof(cx));
    42     for(i=n;i>=1;i--)
    43     {
    44         memset(state,0,sizeof(state));
    45         if(Find(i)) count++;
    46     }
    47     printf("%d
    ",count);
    48     f=0;
    49     for(i=1;i<=n;i++)
    50     {
    51         if(cx[i])
    52         {
    53             if(f) printf(" ");
    54             printf("%d",i);
    55             f=1;
    56         }
    57     }
    58     printf("
    ");
    59 }
    60 
    61 int main()
    62 {
    63     int t,n,i;
    64     //freopen("data.txt","r",stdin);
    65     scanf("%d",&t);
    66     while(t--)
    67     {
    68         scanf("%d",&n);
    69         for(i=1;i<=n;i++)
    70         {
    71             scanf("%d %d",&p[i].l,&p[i].r);
    72         }
    73         hungary(n);
    74     }
    75     return 0;
    76 }
    3729
     
  • 相关阅读:
    Python使用阿里云镜像
    Charles抓取https请求中文乱码的处理方法
    Charles 注册码
    BAT随笔记录(1)
    NodeJS使用puppeteer进行截图
    Centos中文语言乱码解决方法
    CentOS下安装Chrome浏览器中文显示为方框
    CentOS下安装Chrome浏览器
    Jenkines邮件中添加图片
    将HTML转IMAGE
  • 原文地址:https://www.cnblogs.com/sineatos/p/3241958.html
Copyright © 2020-2023  润新知