zoukankan      html  css  js  c++  java
  • hdu 3729 I'm Telling the Truth(二分匹配_ 匈牙利算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3729

    I'm Telling the Truth

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


    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
     
    Source
     
     
    题目大意:每个人说一个自己成绩排名的区间,但是根据他们所说的会产生矛盾。现在给你一个任务,要你来判断到底谁说的是正确的!输出说真话人的数量以及说真话的人的序号。
    解题思路:我们可以把区间的左部分看做是二分图的左枝,区间的右部分看做是二分图的右枝。
    特别注意:输出是有要求的,有很多种情况的时候,输出最大的字典序。
     
    详见代码。
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 
     5 using namespace std;
     6 
     7 int n;
     8 int ok[100000+10],vis[100000+10],as[100000+10];
     9 struct node{
    10     int x,y;
    11 }s[110];
    12 int num[100000+10];
    13 
    14 
    15 bool Find(int x)
    16 {
    17     for (int i=s[x].x;i<=s[x].y;i++)
    18     {
    19         if (!vis[i])
    20         {
    21             vis[i]=1;
    22             if (!ok[i])
    23             {
    24                 as[x]=1;
    25                 ok[i]=x;
    26                 return true;
    27             }
    28             else
    29             {
    30                 if (Find(ok[i]))
    31                 {
    32                     as[x]=1;
    33                     ok[i]=x;
    34                     return true;
    35                 }
    36             }
    37         }
    38     }
    39     return false;
    40 }
    41 
    42 int main()
    43 {
    44     int T;
    45     int x,y;
    46 
    47     scanf("%d",&T);
    48     while (T--)
    49     {
    50         int k=0;
    51         scanf("%d",&n);
    52         memset(as,0,sizeof(as));
    53         memset(ok,0,sizeof(ok));
    54         int ans=0;
    55         for (int i=1;i<=n;i++)
    56         {
    57             scanf("%d%d",&s[i].x,&s[i].y);
    58         }
    59         for (int i=n;i>0;i--)
    60         {
    61             memset(vis,0,sizeof(vis));
    62             if (Find(i))
    63                 ans++;
    64         }
    65         printf ("%d
    ",ans);
    66         for (int i=n;i>=1;i--)
    67         {
    68             if (as[i]==1)
    69             {
    70                 num[k++]=i;
    71                 //cout<<num[k-1]<<endl;
    72             }
    73         }
    74         for (int i=k-1;i>0;i--)
    75             printf ("%d ",num[i]);
    76         printf ("%d
    ",num[0]);
    77     }
    78     return 0;
    79 }
  • 相关阅读:
    在python中添加自定义模块
    jquery图片延时加载
    java的内部类与匿名类
    Oracle数据库优化器的优化方式
    JS实现画线(兼容所有浏览器)
    Ext中window的用法
    关于工作流WEB设计器的一些问题
    ORACLE EBS 价目表的导入功能存储过程BUG
    EXT编程实现人员信息的添加
    用户交互式垃圾回收机制
  • 原文地址:https://www.cnblogs.com/qq-star/p/4723471.html
Copyright © 2011-2022 走看看