hdu 3700 cat

2023-05-16

Cat

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 181    Accepted Submission(s): 52
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
 

 

Author
ZhengZhao@SJTU
 

 

Source
HDOJ 5th Anniversary Contest
 

 

Recommend
lcy
 
玩笑开大了= =!为以防cat挂掉,它必须睡觉。that is to say, if (segn==0) -> ouput "No"

 

 

#include<iostream>
#include<stdlib.h>
using namespace
std;
#define N 21
int n,sleep,awake;
struct
Time
{

    int
hour;
    int
minite;
    int
sec;
    void
trans()
    {
        sec=hour*60+minite;    }
    void
retrans()
    {
        sec+=24*60;        }
    void
minusonesecond()
    {

        if
(minite==0)
            hour--,minite=59;
        else
minite--;
        if
(hour<0)
            hour+=24;
    }

    void
addonesecond()
    {

        if
(minite==59)
            hour++,minite=0;
        else
minite++;
        if
(hour>23)
            hour-=24;
    }

    bool
operator < (const Time a)const
    {
   
        if
(hour==a.hour)
        {

            return
minite<a.minite;
        }

        return
hour<a.hour;       
    }
};


struct
Arrange
{

    Time tb,te;
}
affire[N];

int
cmp(const void *a,const void *b)
{

    struct
Arrange *A=(Arrange*)a;
    struct
Arrange *B=(Arrange*)b;
    if
(B->tb<A->tb)
        return
1;
    return
-1;
}


Time sle[N][2];//sleep segment
char evn[20];

void
solve(bool flag)
{

    int
i,j,begin,end,temp=0,nowlast=0,segn=0;
    Time temp1,temp2;
    for
(i=2;i<=n;i++)
    {

        end=affire[i].tb.sec-1;
        begin=affire[i-1].te.sec+1;
        if
(end<begin&&begin-end!=1)
            end+=24*60;
        if
(end-begin+1>=sleep)//can sleep
        {
            ++
segn;
            temp1=affire[i-1].te;
            temp1.addonesecond();
            sle[segn][0]=temp1;
            temp1=affire[i].tb;
            temp1.minusonesecond();
            sle[segn][1]=temp1;
            nowlast=0;
        }

        else if
(end-begin+1<sleep)//cannot sleep
        {
            if
(nowlast==0)
                nowlast+=affire[i-1].te.sec-affire[i-1].tb.sec+1;
            nowlast+=affire[i].te.sec-affire[i-1].te.sec+1;
            if
(nowlast>awake)
            {

                printf("No/n");
                return
;
            }
        }
    }

// [deal with the n-th and 1-st]
        end=affire[1].tb.sec-1;
        begin=affire[n].te.sec+1;
        if
(end<begin&&begin-end!=1)
            end+=24*60;
        if
(end-begin+1>=sleep)//can sleep
        {
            ++
segn;
            temp2=affire[n].te;
            temp2.addonesecond();
            sle[segn][0]=temp2;
            temp1=affire[1].tb;
            temp1.minusonesecond();
            sle[segn][1]=temp1;
            nowlast=0;
        }

        else if
(end-begin+1<sleep)//cannot sleep
        {
            if
(nowlast==0)
                nowlast+=affire[n].te.sec-affire[n].tb.sec+1;
            nowlast+=affire[1].te.sec-affire[n].te.sec+1;
            if
(nowlast>awake)
            {

                printf("No/n");
                return
;
            }
        }


    if
(n==0)
    {

        segn=1;
        printf("Yes/n%d/n",segn);
        printf("00:00-23:59/n");
        return
;
    }

    else

    {

        if
(segn!=0)
        {

        printf("Yes/n%d/n",segn);
        for
(i=1;i<=segn;i++)
        {

            printf("%02d:%02d-%02d:%02d/n",sle[i][0].hour,sle[i][0].minite,sle[i][1].hour,sle[i][1].minite);
        }
        }

        else

            printf("No/n");
    }
}


int
main()
{

    while
(scanf("%d%d",&sleep,&awake)!=EOF)
    {

        sleep*=60,awake*=60;
        scanf("%d",&n);
        int
i,j;
        bool
flag=false;
        bool
ss=false;
        for
(i=1;i<=n;i++)
        {

            Time T1,T2;
            scanf("%d:%d-%d:%d",&T1.hour,&T1.minite,&T2.hour,&T2.minite);
            T1.trans(),T2.trans();

            if
(T2.sec-T1.sec+1>awake)
            {

                ss=true;
            }

            if
(T2<T1)
            {

                flag=true;
                T2.retrans();
            }

            affire[i].tb=T1,affire[i].te=T2;
        }

        if
(ss)
        {

            printf("No/n");
            continue
;
        }

        qsort(affire+1,n,sizeof(Time)*2,cmp);
        solve(flag);//flag->是否跨午夜
    }
}

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

hdu 3700 cat 的相关文章

  • python源设置及查看

    记录一下 python 设置源及查看方法 xff1a span class token comment 查看设置 span python m pip config list span class token comment 设置源 span

随机推荐

  • linux环境C++执行bash脚本

    所需头文件 xff1a include lt stdio h gt 例如 xff0c 希望执行脚本 mkdir testDir C 43 43 Code xff1a FILE fp 61 popen 34 mkdir testDir 34
  • Visual Studio 远程调试设置

    VisualStudio远程调试很方便 xff0c 设置也非常简单 远程调试器安装 安装VisualStudio时默认就会安装远程调试器 xff0c 所以一般无需单独安装 被连接方设置 被连接方需要打开远程调试器 xff0c 它位于目录Re
  • 【windows11系统进行ubuntu系统安装详细步骤】

    windows11系统进行ubuntu系统安装详细步骤 2022年新购入一台win11台式电脑 xff0c 进行python的学习经历 xff0c 教程里边要求安装linux系统 xff0c 所以从网上搜索如何安装ubuntu系统 xff0
  • Win7远程控制fedora ——通过xrdp

    原文地址 http blog sohu com s MTU5MTY3OTE1 302888160 html 最近要分析RDP协议的相关东西 xff0c 然后需要抓包 xff0c 实验室空着的电脑只有Fedora系统了 xff0c 就找了一下
  • 解决Win10/11 WSL 子系统 WslRegisterDistribution failed with error: 0x800701bc 错误

    原因 xff1a wsl1升级到wsl2之后 xff0c 内核却没有升级 xff0c 所以会出现这种错误提示 xff01 解决方法 xff1a 1 下载最新的wsl安装包 2 安装包下载后 xff0c 直接运行安装即可 xff01 3 下载
  • 分布式事务之Seata AT 事务

    1 Seata介绍 Seata 是一款开源的分布式事务解决方案 xff0c 致力于提供高性能和简单易用的分布式事务服务 Seata 将为用户提供了 AT TCC SAGA 和 XA 事务模式 xff0c 为用户打造一站式的分布式解决方案 1
  • Vue引用Element-UI时,组件无效果解决方案

    问题 xff1a Vue在使用Element UI组件的时候 xff0c 已经安装好依赖 span class token operator gt span npm install element span class token oper
  • C语言:编译成可执行程序的步骤

    1 预处理 xff08 头文件的展开 xff0c 宏的替换 ifdef else endif xff09 gcc E test c o test i 2 编译 xff08 生成汇编文件 xff0c 对词法和语法进行检查 xff09 gcc
  • 服务器蓝屏的原因及解决办法

    硬件故障 xff1a 1 散热问题 2 内存主板问题 3 电源问题 4 显卡问题 解决办法 xff1a 1 清理下灰尘 xff0c 风扇 xff0c 温度高会蓝屏 2 检查内存 xff0c 新机器后加的内存是不是不兼容 xff0c 拔插下内
  • 在 CentOS 8 中使用 KVM 安装 Windows 10

    在 CentOS 8 中使用 KVM 安装 Windows 10 本文地址 xff1a blog lucien ink archives 514 使用 esxi 的话总觉得有些别扭 xff1f 故尝试 KVM xff0c 本文使用 Cent
  • 树莓派初始化备忘

    树莓派初始化备忘 本文地址 xff1a blog lucien ink archives 515 最近又开始折腾树莓派了 xff0c 记录一下初始化一个树莓派需要做的一些操作 本次操作以 64 位 Raspberry Pi OS xff08
  • 树莓派禁用 Wi-Fi 和蓝牙

    树莓派禁用 Wi Fi 和蓝牙 本文地址 xff1a blog lucien ink archives 516 因为我的树莓派是直接通过网线连接的 xff0c 并没有启用 Wi Fi xff0c 所以在每次 SSH 连进去之后 Raspbi
  • 树莓派安装 OMV

    树莓派安装 OMV 本文地址 xff1a blog lucien ink archives 517 终究还是忍住了 xff0c 没有出手买 x86 的 NAS xff0c 选择自己折腾树莓派 xff08 因为实在是太穷了 xff09 1 初
  • 树莓派安装 docker 和 docker-compose

    树莓派安装 docker 和 docker compose 本文地址 xff1a blog lucien ink archives 518 因为总是频繁地初始化树莓派 xff0c 所以把安装 docker 的过程也记录下来 1 安装 doc
  • 打印 Go Test 的代码覆盖

    打印 Go Test 的代码覆盖 本文地址 xff1a blog lucien ink archives 520 使用方法 将这段代码复制进 zshrc 或者是 bashrc 等文件中 xff08 取决于你的命令行 xff09 xff0c
  • Typecho HTTPS 无法登陆后台

    Typecho HTTPS 无法登陆后台 本文地址 xff1a blog lucien ink archives 523 背景 因为百度云加速的 HTTPS 证书各种难用 xff0c 最近将博客的 CDN 解决方案整体迁移至 Cloud F
  • git 显示中文

    git 显示中文 本文地址 xff1a blog lucien ink archives 524 默认情况下 xff0c git 会对中文进行转译 xff0c 具体表现如下 xff1a span class token function g
  • 在 PVE 中安装 OpenWrt

    在 PVE 中安装 OpenWrt 本文地址 xff1a blog lucien ink archives 525 最近在捣腾 x86 软路由 xff0c 入门方案一般是底层采用 ESXi 或 PVE xff0c 虚拟层使用 iKuai 4
  • ARM:系统移植1

    一 系统移植的概述 1 目的 xff1a 1 软硬件可裁剪 xff1a 硬件发生变化 xff0c 软件要进行裁剪 xff0c 适配硬件 2 学习linux驱动的开发 xff0c 前提开发板上需要运行linux系统 移植linux内核系统到开
  • hdu 3700 cat

    Cat Time Limit 2000 1000 MS Java Others Memory Limit 32768 32768 K Java Others Total Submission s 181 Accepted Submissio