打卡信奥刷题(510)用Scratch图形化工具信奥P1697[普及组/提高组] [USACO18JAN] Lifeguards B

[USACO18JAN] Lifeguards B

题面翻译

给定 n n n 个左闭右开区间,问在去掉任意一个区间的情况下,区间的覆盖长度最大是多少。

题目描述

Farmer John has opened a swimming pool for his cows, figuring it will help them relax and produce more milk.

To ensure safety, he hires N N N cows as lifeguards, each of which has a shift that covers some contiguous interval of time during the day. For simplicity, the pool is open from time t = 0 t=0 t=0 until time t = 1000 t=1000 t=1000 on a daily basis, so each shift can be described by two integers, giving the time at which a cow starts and ends her shift. For example, a lifeguard starting at time t = 4 t=4 t=4 and ending at time t = 7 t=7 t=7 covers three units of time (note that the endpoints are “points” in time).

Unfortunately, Farmer John hired 1 more lifeguard than he has the funds to support. Given that he must fire exactly one lifeguard, what is the maximum amount of time that can still be covered by the shifts of the remaining lifeguards? An interval of time is covered if at least one lifeguard is present.

输入格式

The first line of input contains N ( 1 ≤ N ≤ 100 ) N (1\le N\le 100) N(1N100). Each of the next N lines describes a lifeguard in terms of two integers in the range 0 … 1000 0\dots 1000 01000, giving the starting and ending point of a lifeguard’s shift. All such endpoints are distinct. Shifts of different lifeguards might overlap.

输出格式

Please write a single number, giving the maximum amount of time that can still be covered if Farmer John fires 1 lifeguard.

样例 #1

样例输入 #1

3
5 9
1 4
3 7

样例输出 #1

7

Scratch实现

在这里插入图片描述

后续

接下来我会不断用scratch来实现信奥比赛中的算法题、Scratch考级编程题实现、白名单赛事考题实现,感兴趣的请关注,我后续将继续分享相关内容

  • 29
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值