zoukankan      html  css  js  c++  java
  • I'm Telling the Truth

    I'm Telling the Truth

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


    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

    /*************************************************************************
     > File Name: hdu3729.cpp
     > Author: Henry Chen
     > Mail: 390989083@qq.com 
     > Created Time: 六  9/20 20:32:48 2020
     ************************************************************************/
    #include<bits/stdc++.h>
    using namespace std;
    int l[101],r[101];
    int tog[101];
    map <int,int> tos;
    map <int,int> visited;
    bool find(int x)
    {
     for(int i = l[x];i <= r[x];i++)
     {
      if(visited[i]) continue;
      visited[i] = 1;
      if(tos[i] == 0 || find(tos[i]))
      {
       tos[i] = x;
       tog[x] = i;
       return 1;
      }
     }
     return 0;
    } 
    void work()
    {
     memset(tog,0,sizeof(tog));
     map<int,int>empty;
     tos = empty;
     int n;
     int ans = 0;
     cin >> n;
     for(int i = 1;i <= n;i++)
     {
      scanf("%d%d",&l[i],&r[i]);
     }
     for(int i = n;i >= 1;i--)
     {
      visited = empty;
      //memset(visited,0,sizeof(visited));
      if(find(i)) ans++;
     }
     cout << ans << endl;
     int k = 0;
     for(int i = 1;i <= n;i++)
     {
      if(tog[i]) 
      {
       if(k) printf(" ");
       else k = 1;
       printf("%d",i);
      }
     }
     puts("");
     return;
    }
    int main()
    {
     int t;
     cin >> t;
     while(t--)
     {
      work();
     }
     return 0;
    }
  • 相关阅读:
    SQL Server中生成指定长度的流水号
    属性与字段的区别
    Tomcat启动时的异常~!!!
    全面认识验证身份的数字证书
    MyEclipse 5.5 开发 Spring + Struts + Hibernate 的详解视频(长1.5小时)
    resin是什么?是Application Server吗?是WebLogic,Websphere他们的竞争对手吗?
    发现一个HTML得秘密
    用 MyEclipse 开发的最简单的 Spring 例子
    什么是WebSphere?WebSphere是干什么用的?中间件是什么意思?
    简单jsp+servlet实例
  • 原文地址:https://www.cnblogs.com/mzyy1001/p/13703064.html
Copyright © 2011-2022 走看看