UVALive 5033 I'm Telling the Truth

来源:互联网 发布:单片机输出电压不恒定 编辑:程序博客网 时间:2024/05/16 01:47

 I'm Telling the Truth
Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu
Submit Status Practice UVALive 5033

Description

Download as PDF

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 5004-th and 5005-th, Student2 said he was between 5005-th and 5006-th, Student3 said he was between 5004-th and 5006-th, Student4 said he was between 5004-th and 5006-th, 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$ \le$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$ \le$Xi$ \le$Yi$ \le$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 50055005 50065004 50065004 50067 4 5 2 3 1 2 2 2 4 4 2 33 4

Sample Output

3 2 3 4 5 1 3 5 6 7


题解及代码:


#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#define maxn 11111using namespace std;typedef long long ll;int match[100010];int chk[100010],n;int st[66];struct node{    int l,r;}map[62];int dfs(int p){    int i,t;    for(int i=map[p].l;i<=map[p].r;i++)    if(!chk[i])    {        chk[i]=1;        t=match[i];        match[i]=p;        if(t==-1||dfs(t))            return 1;        match[i]=t;    }    return 0;}int Pro(){    int i,res=0;    for(int i=n;i>=1;i--) //字典序最大从n到1遍历,字典序最小从1到n遍历    {        memset(chk,0,sizeof(chk));        res+=dfs(i);    }    return res;}int main(){    memset(map,0,sizeof(map));    int t;    cin>>t;    while(t--)    {        scanf("%d",&n);        memset(match,-1,sizeof(match));        for(int i=1;i<=n;i++)        {            scanf("%d%d",&map[i].l,&map[i].r);        }        printf("%d\n",Pro());        int k=0;        for(int i=1;i<=n;i++)        {            for(int j=map[i].l;j<=map[i].r;j++)            if(match[j]>0)            {                st[k++]=match[j];                match[j]=-1;            }        }        sort(st,st+k);        for(int i=0;i<k;i++)        if(i<k-1)        {            printf("%d ",st[i]);        }        else printf("%d\n",st[i]);    }    return 0;}/*二分图最大匹配的题目,直接使用模版就行了,这里主要是求出字典序最大的序列,直接在代码中进行小修改就行了,在代码中给出了需要注意的地方。*/





0 0
原创粉丝点击