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 的相关文章

  • HDU 6298(数学)

    题意是给出一个数 xff0c 找出这个数的三个因子且这三个因子的和等于这个数 xff0c 输出满足条件的乘积最大的一组因子的乘积 xff0c 如果不存在这样的因子 xff0c 就输出 1 第一次 wa 了 xff0c 因为把题目中的 x n
  • HDU 1880 魔咒词典(Hash+二分)

    题目链接 哈利波特在魔法学校的必修课之一就是学习魔咒 据说魔法世界有100000种不同的魔咒 xff0c 哈利很难全部记住 xff0c 但是为了对抗强敌 xff0c 他必须在危急时刻能够调用任何一个需要的魔咒 xff0c 所以他需要你的帮助
  • HDU 1025最长递增子序列(二分法)

    最长递增子序列 xff08 二分 xff09 HDU1025 https www felix021 com blog read php 1587 找最长递增子序列 xff0c 以前一般用DP的方法找 xff0c 因为理解简单 xff0c 实
  • hdu - 4642 - Fliping game(博弈)

    题意 xff1a Alice和Bob玩游戏 xff0c 一个N M的矩阵 xff0c 里面是1或0 xff0c 每人每次选择一个1的位置 xff0c 然后将这个位置到右下角的整个矩形元素全部取反 xff08 1变0 xff0c 0变1 xf
  • hdu 5119(dp题)

    题目链接 xff1a http acm hdu edu cn showproblem php pid 61 5119 题目 xff1a Matt has N friends They are playing a game together
  • hdu 3700 cat

    Cat Time Limit 2000 1000 MS Java Others Memory Limit 32768 32768 K Java Others Total Submission s 181 Accepted Submissio
  • HDU 1085 Holding Bin-Laden Captive!(母函数)

    HDU 1085 Holding Bin Laden Captive xff08 母函数 xff09 题目地址 题意 xff1a 给你cnt1个一元硬币 xff0c cnt2个两元硬币 xff0c cnt3个五元硬币 xff0c 问不能凑出
  • Cat-Tree-Select 基于Vue+Element的树选择器

    Cat Tree Select 基于Vue 43 Element的树选择器 基于 Element 的Vue 组件 Vue js 2 x cat tree select Github 地址 前言 本人在最近的开发工作中常需要用到树选择器 目前
  • 示例:Linux设备属性节点驱动,以及cat, echo操作

    在写Linux字符驱动的时候 xff0c 经常涉及到一些驱动需要在 sys目录或子目录下创建 xff0c 一个属性节点 xff0c 以便与 xff0c 不用查看驱动的版本信息 xff0c 时间等等一些属性信息 xff0c 以判断驱动程序加载
  • HDU-2121(朱刘算法优化版+虚根处理无根树形图)

    hdu2121 span class token macro property span class token directive keyword include span span class token string lt bits
  • hdu 1059 Dividing

    Problem acm hdu edu cn showproblem php pid 1059 题意 6 种宝石 价值分别是 1 到 6 分别给出 6 种宝石的数量 问能不能分成等价值的两堆 分析 多重背包 主要是记录下多重背包的写法 对每
  • hdu 1058 Humble Numbers

    Problem acm hdu edu cn showproblem php pid 1058 题意 找出从小到大第 n 个因子 除了 1 和本身 只有 2 3 5 7 的数 即第 n 个 num 2 a 3 b 5 c 7 d 的数 据说
  • find 命令查找文件并将它们连接起来

    我正在尝试查找所有类型的文件 gz and cat他们到total gz我想我已经很接近这一点了 这是我用来列出所有的命令 gzfiles find home downloaded maxdepth 3 type d name exec b
  • 我可以使用 unix utils 以编程方式将 ANSI 控制代码“烧入”文件吗?

    示例 我开始录音script 并尝试输入echo test但省略了 o 所以我退格来纠正它 When I cat typescript一切看起来都很正常 因为代码被解释了 但如果我使用less or vim I see ech test H
  • 使用cat函数写入csv文件

    我需要使用 cat 函数向 CSV 添加新行 请你们帮帮我好吗 我对 R 的了解有限 这是文件 name1 csv 系统要求我将我的姓名和学生 ID 添加到前几行 homework1 lt data frame homework1 Tota
  • 将列表(如 R 控制台输出中所示)写入文本文件

    我在 r 中将列表写入文本文件时遇到问题 这是我的代码 library e1071 mydata read table TRAIN txt sep header FALSE model lt naiveBayes as factor V1
  • java执行linux命令

    我试图从 java 代码执行 linux 命令 cat 但它不起作用 Runtime getRuntime exec cat home roman logs 它对于单文件的猫效果很好 Runtime getRuntime exec cat
  • 卷曲:(3)URL中发现非法字符

    我要批量查找IP 详细信息请访问 ipinfo io http ipinfo io developers bulk lookup这是我的代码 cat ips txt xargs I curl http ipinfo io region 文件
  • 在 R 中结合 head 和 tail 方法

    我经常使用 R 包 utils 中的 head d 和 tail d 方法 经常一个接一个 所以我为这两个函数编写了一个简单的包装器 ht lt function d m 5 n m print the head and tail toge
  • Linux >2.6.33:可以使用 sendfile() 来实现更快的“猫”吗?

    必须将大量大文件连接成一个更大的单个文件 我们目前使用 cat file1 file2 output file but are wondering whether it could be done faster than with that

随机推荐

  • 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