zoukankan      html  css  js  c++  java
  • hdu3729(二分图)

    比赛的时候没有想到二分图,一直在想dp和贪心。 原因是因为看到数据是100000所以直接就没有往二分图匹配上想。 

    现在想想。 因为二分图两边的太不对称了,60 和100000 , 如果用匈牙利算法考虑的话,左边的点应该可以很快的找到一个与之匹配的点。 如果边不多的话那么找起来也是很快的。

    还是太弱。 

    I'm Telling the Truth

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


    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
     

    Recommend
    zhouzeyong
     
    // 题目数据比较水 ,用邻接表都不会超内存. 用邻接矩阵稍微优化也能过。。
    #include <iostream>
    #include <string.h>
    #include <stdio.h>
    using namespace std;
    
    int n;
    bool g[61][100010];
    int save[66];
    int mark[100010];
    int pre[100010];
    int mx,mi;
    
    int dfs(int s)
    {
        for(int i=mi;i<=mx;i++)
        {
            if(mark[i]==1||g[s][i]==0) continue;//表示不可达
            mark[i]=1;
            if(pre[i]==-1||dfs(pre[i])==1)
            {
                pre[i]=s;
                return 1;
            }
        }
        return 0;
    }
    
    int main()
    {
        int T;
        scanf("%d",&T);
        while(T--)
        {
            mx=0;
            mi=1000000;
            memset(g,0,sizeof(g));
            scanf("%d",&n);
            for(int i=1;i<=n;i++)
            {
                int x,y;
                scanf("%d%d",&x,&y);
                mx=max(mx,y);
                mi=min(x,mi);
                for(int j=x;j<=y;j++)
                {
                    g[i][j]=1;
                }
            }
            memset(pre,-1,sizeof(pre));
            int ans=0;
            for(int i=n;i>=1;i--)
            {
                memset(mark,0,sizeof(mark));
                if(dfs(i))
                {
                    save[ans++]=i;
                }
            }
            printf("%d
    ",ans);
            for(int i=ans-1;i>0;i--)
                printf("%d ",save[i]);
            printf("%d
    ",save[0]);
        }
        return 0;
    }

  • 相关阅读:
    第四节 pandas 数据加载
    第五节 matplotlib库
    第二节 pandas 基础知识
    第一节 anaconda+jupyter+numpy简单使用
    枚举效率测试 --简单计算题
    Tree 树形结构
    django url分发,视图,模板回顾
    django自定义分页器
    转git的使用
    转Git配置SSH,并Push到GitHub上的相关流程
  • 原文地址:https://www.cnblogs.com/chenhuan001/p/3379320.html
Copyright © 2011-2022 走看看