HDU 3700 Cat

Cat

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768
K (Java/Others)

Total Submission(s): 451    Accepted Submission(s): 100

Special Judge

Problem Description

There is a cat, cat likes to sleep.

If he sleeps, he sleeps continuously no less than A hours.

For some strange reason, the cat can not stay awake continuously more than B hours.

The cat is lazy, it could sleep all the time,

but sometimes interesting events occur(such as cat food, TV show, etc) .

The cat loves these events very much.

So, Please help the cat plan their day so as not to miss any interesting events.

Every day the cat wants to live on the same schedule.

Input

The first line of the input file contains two integers A and B (1 <= A, B <= 24).

The second line of the input file contains the number n, the number of interesting events (1 <= n <= 20).

Following n rows describe the interesting events.

Each event is described line of the form hh:mm-hh:mm, which specifies

the time period during which it occurs. Time varies from 00:00 to 23:59.

No two interesting events will overlap.

If the event is completed earlier than the beginning, This means that it captures midnight.

The event is considered to be occupying the whole minute,

when it begins and the moment when it ends (event 12:00-13:59 lasted exactly 120 minutes). Start time and time end of the event are different.

Output

If the cat can organize their day so that during all the interesting events not sleep, print to output file Yes.

On the second line Bring k - how many times a day cat should go to bed.

In the following k rows Bring out the intervals in which the cat sleeps in the same format, in which interesting events are set in the input file. If making a few, display any.

If the cat can not organize their day desired way, print to the output file No.

Sample Input

12 12
1
23:00-01:00
3 4
3
07:00-08:00
11:00-11:09
19:00-19:59

Sample Output

Yes
1
01:07-22:13
No

细节很多,比赛的时候卡了全场,实在是感人肺腑,不能多说


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <deque>
#include <vector>
#include <bitset>
#include <cmath>
#include <utility>
#define Maxn 100005
#define Maxm 1000005
#define Inf (1LL<<62)
#define inf 0x3f3f3f3f
#define eps 1e-8
#define lowbit(x) x&(-x)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define PI acos(-1.0)
#define make_pair MP
#define LL long long
#define re freopen("in.txt","r",stdin)
#define wr freopen("out.txt","w",stdout)
using namespace std;
struct Node
{
    int st,ed,t;
    bool friend operator <(Node a,Node b)
    {
        return a.st<b.st;
    }
}time[25],ans[25];
int main()
{
    int a,b,n,h1,h2,m1,m2,k,Max;
    bool flag;
    //re;wr;
    while(~scanf("%d%d%d",&a,&b,&n))
    {
        Max=0;
        k=0;
        flag=true;
        memset(ans,0,sizeof(ans));
        for(int i=0;i<n;i++)
        {
            scanf("%02d:%02d-%02d:%02d",&h1,&m1,&h2,&m2);
            time[i].st=h1*60+m1;time[i].ed=h2*60+m2;
            if(time[i].ed<time[i].st)
                time[i].ed+=1440;
            time[i].t=time[i].ed-time[i].st+1;
            Max=max(Max,time[i].t);
        }
        if(Max>b*60)
        {
            puts("No");
            continue;
        }
        int tt=1440-time[0].t;
        if(n==1)
        {
            if(tt>=a*60)
            {
                puts("Yes");
                puts("1");
                int hh1=((time[0].ed+1)/60)%24;
                int mm1=(time[0].ed+1)%60;
                int hh2=time[0].st-1>=0?((time[0].st-1)/60)%24:23;
                int mm2=((time[0].st-1)+60)%60;
                printf("%02d:%02d-%02d:%02d\n",hh1,mm1,hh2,mm2);
            }
            else
                puts("No");
            continue;
        }
        sort(time,time+n);
        tt=time[0].st+1440-time[n-1].ed-1;
        int tmp;
        if(tt>=a*60)
        	tmp=0;
        else
        {
        	tmp=tt+time[n-1].t;
        	int p=n-1;
        	while(p>=1&&time[p].st-time[p-1].ed-1<a*60)
        	{
        		tmp+=time[p].st-time[p-1].ed-1+time[p-1].t;
        		p--;
        	}
        }
        for(int i=0;i<n;i++)
        {
            tmp+=time[i].t;
            if(tmp>b*60)
            {
                flag=false;
                break;
            }
            if(i!=n-1)
            {
            	if(time[i+1].st-time[i].ed-1>=a*60)
            	{
                	ans[++k].st=time[i].ed+1;
                	ans[k].ed=time[i+1].st-1;
                	tmp=0;
            	}
            	else
                	tmp+=time[i+1].st-1-time[i].ed;
            	if(tmp>b*60)
           	 	{
                	flag=false;
               	 	break;
            	}
            }
        }
        if(tt>=a*60)
        {
            k++;
            ans[k].st=time[n-1].ed+1;ans[k].ed=time[0].st-1;
        }
        if(flag&&k)
        {
            puts("Yes");
            printf("%d\n",k);
            for(int i=1;i<=k;i++)
            {
                int hh1=(ans[i].st/60)%24;
                int mm1=(ans[i].st+60)%60;
                int hh2=ans[i].ed>=0?(ans[i].ed/60)%24:23;
                int mm2=(ans[i].ed+60)%60;
                printf("%02d:%02d-%02d:%02d\n",hh1,mm1,hh2,mm2);
            }
        }
        else
            puts("No");
    }
    return 0;
}
时间: 2024-09-14 18:03:07

HDU 3700 Cat的相关文章

hdu 2768 Cat vs. Dog (二分匹配)

Cat vs. Dog Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1422    Accepted Submission(s): 534 Problem Description The latest reality show has hit the TV: ``Cat vs. Dog''. In this show, a bunch

HDU 3829 - Cat VS Dog (二分图最大独立集)

题意:动物园有n只猫和m条狗,现在有p个小孩,他们有的喜欢猫,有的喜欢狗,其中喜欢猫的一定不喜欢狗,喜欢狗的一定不喜欢猫.现在管理员要从动物园中移除一些动物,如果一个小孩喜欢的动物留了下来而不喜欢的动物被移走,这个小孩会很高兴.现在问最多可以让多少个小孩高兴. 此题是求二分图最大独立集. 二分图比较明显,但是难在建图.这个题是找到最多的喜欢猫和喜欢狗而不互相冲突的小孩,这样我们将喜欢动物相互冲突的小孩之间连边,问题就变成了求二分图的最大独立集. 在二分图中,最大独立集=顶点数-最大匹配数. 求解

HDU 3289 Cat VS Dog (二分匹配 求 最大独立集)

题意:每个人有喜欢的猫和不喜欢的狗.留下他喜欢的猫他就高心,否则不高心.问最后最多有几个人高心. 思路:二分图求最大匹配 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<iostream> 5 #include<cstdlib> 6 #include<string> 7 #include<cmath> 8 #include<

hdu 3829 Cat VS Dog 二分图匹配 最大点独立集

Cat VS Dog Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others) Problem Description The zoo have N cats and M dogs, today there are P children visiting the zoo, each child has a like-animal and a dislike-animal, if the

HDU——2768 Cat vs. Dog

Cat vs. Dog Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2279    Accepted Submission(s): 886 Problem Description The latest reality show has hit the TV: ``Cat vs. Dog''. In this show, a bunc

hdu 3829 Cat VS Dog 二分匹配 最大独立点集

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3829 题目大意: 给定N个猫,M个狗,P个小朋友,每个小朋友都有喜欢或者不喜欢的某猫或者某狗 管理员从中删除一些猫狗,使得尽可能多的小朋友开心 思路: 假设A小朋友喜欢的猫是B小朋友所不喜欢的,或者说A不喜欢的狗是B喜欢的,那么说明两者之间存在矛盾关系 问题就是求出互相之间没有矛盾的小朋友的集合 那么就是点数-最大匹配数的问题了,就是读入数据有点麻烦 代码: 1 #include <iostream

HDU 3829 Cat VS Dog

题意: p个人  每个人有喜欢和讨厌的动物  如果选出的动物中包含这个人喜欢的动物同时不包含他讨厌的动物那么这个人会开心  问  最多几个人开心 思路: 二分图最大独立集  利用人与人之间的冲突建边  求最大匹配即可 注意: 题中的样例给出动物的名字是D1.C1之类的  其实名字可能比这个长-  所以数组开长点 代码: #include<cstdio> #include<iostream> #include<cstring> #include<string>

HDU 3829 Cat VS Dog(最大独立集)

题目大意: 有n只猫,有m只狗.现在有P个学生去参观动物园.每个孩子有喜欢的动物和不喜欢的动物.假如他喜欢猫那么他就一定不喜欢狗(反之亦然). 如果一个孩子喜欢一个动物,那么这个动物不会被移除,若是不喜欢则移除.现在管理员想知道移除哪些动物可以使最大数量的孩子高兴. 输入数据: 输入包含多组测试实例. 第一行是三个数字n, m, p. 接下来p行. 每行 CX, DX 代表他喜欢第X只猫,讨厌第X只狗(反之亦然) 题目思路: 构图思路:我们把所有人进行构图,如果两个人之间有矛盾就建立一条边.然后

hdu 2768 Cat vs. Dog 最大独立集 巧妙的建图

题目分析: 一个人要不是爱狗讨厌猫的人,要不就是爱猫讨厌狗的人.一个人喜欢的动物如果离开,那么他也将离开.问最多留下多少人. 思路: 爱猫和爱狗的人是两个独立的集合.若两个人喜欢和讨厌的动物是一样的,那么就建一条边.留下多少人,就是求最大独立集. 最大独立集= 顶点数 - 最大匹配数 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #inc