poj 2376 Cleaning Shifts——贪心

【题解】POJ 2376 Cleaning Shifts(贪心) POJ 2376 Cleaning Shifts 原题 https://vjudge.net/problem/POJ-2376 农夫约翰指派他的N (1 <= N <= 25,000)头牛在谷仓周围做一些清洁杂务。他总是希望有一头牛来打扫卫生,他把一天分成了T班(1 <= T <= 1,000,000),第一个班是1班,最后一个班是T班。 每头牛只能在一天的某些时段进行清洁工作。任何被选来做清洁工作的牛都会在整个休息期间一直工作。 你的工作是帮助农民约翰分配一些奶牛轮班,这样( 阅读详情
Cleaning Shifts

Description

Farmer John is assigning some of his N (1 <= N <= 25,000) cows to do some cleaning chores around the barn. He always wants to have one cow working on cleaning things up and has divided the day into T shifts (1 <= T <= 1,000,000), the first being shift 1 and the last being shift T.

Each cow is only available at some interval of times during the day for work on cleaning. Any cow that is selected for cleaning duty will work for the entirety of her interval.

Your job is to help Farmer John assign some cows to shifts so that (i) every shift has at least one cow assigned to it, and (ii) as few cows as possible are involved in cleaning. If it is not possible to assign a cow to each shift, print -1.
Input

  • Line 1: Two space-separated integers: N and T

  • Lines 2…N+1: Each line contains the start and end times of the interval during which a cow can work. A cow starts work at the start time and finishes after the end time.
    Output

  • Line 1: The minimum number of cows Farmer John needs to hire or -1 if it is not possible to assign a cow to each shift.
    Sample Input

    3 10
    1 7
    3 6
    6 10
    Sample Output

    2
    Hint

This problem has huge input data,use scanf() instead of cin to read data to avoid time limit exceed.

INPUT DETAILS:

There are 3 cows and 10 shifts. Cow #1 can work shifts 1…7, cow #2 can work shifts 3…6, and cow #3 can work shifts 6…10.

OUTPUT DETAILS:

By selecting cows #1 and #3, all shifts are covered. There is no way to cover all the shifts using fewer than 2 cows.

 

c++ AC 代码

#include<map>
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N = 25010, T = 100005;

pair <int,int> tme[N];

bool cmp(pair<int,int> a,pair<int,int> b)
{
    return a.first < b.first;
}

int main()
{
    int n,t1;
    scanf("%d%d",&n,&t1);
    for (int i = 1; i <= n; i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        tme[i].first = a;
        tme[i].second = b;
    }
    
    sort(tme+1,tme+1+n,cmp);
    
    int temp=0,ans=0,i=1;
    while(i <= n && temp < t1)
    {
        ans++;
        int top = temp;
        if(tme[i].first > temp+1) break;
        while(tme[i].first <= temp+1 && i <= n)
        {
            top = max(top,tme[i].second);
            i++;
        }
        temp = top;
    }
    if(temp < t1) printf("-1\n");
    else printf("%d\n",ans);
    
    return 0;
}
汇川H5U搭配步进伺服电机使用CANopen通讯控制电机案例 摘要:本文介绍了基于汇川H5U PLC和STM4260B-CANopen-M步进伺服电机的控制系统搭建流程。主要内容包括:硬件准备(PLC、伺服电机、24V电源)、电机参数默认设置(地址1号、1M波特率)、使用AutoShop软件编写程序(配置CANopen参数、导入电机描述文件、设置PDO参数)以及功能块编程(使能控制、速度控制、绝对位置控制等)。通过查阅通讯手册完成各功能块参数配置,最终在主程序中调用功能块实现控制系统开发。该方案适用于需要精确运动控制的工业自动化场景。 阅读详情

相关推荐

手势控制 Python !Leap Motion Python 开发教程 (二)

手势控制 Python !Leap Motion Python 开发教程 (二) 现在进入正题,我来给大家总结一下我在使用 Leap Motion 开发过程中的经验以及学到的东西,其中我会概括以及翻译官方给出的注释,为了让这些注释更加通俗易懂,让大家更好理解。 回顾 在上一篇文章中我们讲了如何配置 Leap Motion 的 Python 2.7 的开发环境,如果您还没有配置好您的开发环境,可以参...

成畅的博客 3200

AYITACM2016省赛第二周E - Cleaning Shifts(区间覆盖)

Description Farmer John is assigning some of his N (1 <= N <= 25,000) cows to do some cleaning chores around the barn. He always wants to have one cow working on cleaning things up and has divide

linyuxilu的博客 1774

树莓派用网线连着电脑,但是找不到它的ip 以及设置静态IP

第一次的话,树莓派默认是没有ssh的。需要把内存卡取出来,新建一个ssh文件,这个简单,新建一个txt文件重命名就好了。 如果前面配置了连接wifi的conf文件,它是会自动去连接wifi的,wifi连不上,它才会去尝试有线连接。所以把它的wifi关了,才会自动用网线连接。 另外,建议设置静态ip连接,这样避免网络连接突然中断。具体在etc/dhcpcd.conf文件中,把这几行前面的#去掉,然后后面的信息改成自己的就好了。 具体改法: 第一行是ip地址,这个找到自己电脑的ip段,然后改后面两个数字就好了

wander_ing的博客 1万+

POJ--2376--Cleaning Shifts

题目描述: Farmer John is assigning some of his N (1 <= N <= 25,000) cows to do some cleaning chores around the barn. He always wants to have one cow working on cleaning things up and has divided the...

猩猩是个好程序员的博客 171

UE5.6使用ndisplay,单窗口多画面(单机部署),配置、打包流程,无需switchboard

摘要:本文介绍了在UE5.6中使用ndisplay插件的完整流程。首先需要开启ndisplay和launch插件,创建ndisplay配置文件并设置本地单窗口多画面模式。随后通过Process Explorer获取启动命令用于制作bat文件。打包项目时需删除场景中的ndisplay文件,但保留内容浏览器中的配置,并设置为开发版打包。最后将ndisplay文件导出为.ndisplay格式,与bat文件一起放置在打包目录下,通过bat启动程序。注意修改路径和窗口大小时需保持纯英文路径,且bat代码需保持单行格式

weixin_43912248的博客 986

广告推荐算法 - 学习笔记(持续更新中)

本篇博客,是我用来记录学习广告推荐算法的一些笔记和总结。王喆:"深度"学习计算广告计算广告系统的核心目标是通过数据、算法和技术,在合适的场景下,将最相关的广告精准推送给目标用户,同时实现广告主媒体平台和用户之间的多方利益最大化。广告主:需求方核心目标:通过精准投放广告,最大化转化(如点击、购买)并控制成本,提升投资回报率(ROI)。关键行为:广告创建,定向设置,预算与出价策略,效果监控媒体平台:供给方核心目标:最大化广告收入,同时保持用户体验以避免用户流失。

qq_39748832的博客 2207

[POJ2376]Cleaning Shifts

Farmer John is assigning some of his N (1 <= N <= 25,000) cows to do some cleaning chores around the barn. He always wants to have one cow working on cleaning things up and has divided the day into T

UISG103的博客 990

AWD线下攻防赛总结

在本地组策略编辑器里面,依次展开计算机配置—>管理模板—>Windows组件—>远程桌面服务—>远程桌面会话主机—>连接—>限制连接的数量。8.Web目录环境查找相关可疑文件:jpg/png/rar,属性、解压。进程线程:netstat / ps -aux/netstat -apt。4.查看/etc/init.d/rc.local中启动服务有无异常。1.不使用默认口令,修改成复杂的,并确保和web环境连接。5.使用脚本开启进程监控、目录监控、流量监控。文件操作监控.exe/御剑文件监控.exe。

XuJL89的博客 638

Cleaning Shifts POJ - 2376(贪心)

Cleaning Shifts POJ - 2376 Farmer John is assigning some of his N (1 <= N <= 25,000) cows to do some cleaning chores around the barn. He always wants to have one cow working on cleaning things u...

rainbowsea_1的博客 297

c++ webrtc基础(1) :webrtc源码下载与编译、项目模块介绍、学习资料推荐

本篇博客介绍webrtc源码的下载与编译,以及推荐webrtc学习资料。 源码下载 电脑环境:win10/win11 64bit,合理的上网环境,没有合理的网络环境无法拉取、下载webrtc代码和工具,宽带速度要快,尽量50M. 主要步骤如下: (1) 安装git (2) 打开cmd控制台,下载google开发工具depot_tools: git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git (3) 新建一个目

琅嬛福地 3305

Virtual Hard Disk version 2 (VHDX) 文件格式详解

VHDX 镜像格式详解 0. References windows github 1. Overview Microsoft 虚拟化产品中常用的映像格式是虚拟硬盘版本 2 (VHDX) 映像格式。该规范基于可用文档,并通过分析测试数据进行了增强。 VHDX 镜像格式种类 固定硬盘镜像 动态硬盘镜像 差异硬盘镜像 VHDX 镜像文件由以下元素构成: file (type) identifier 2x image headers 2x region tables log or metadata journ

圣三一 2705

poj 2376 最小区间覆盖问题

http://poj.org/problem?id=2376 Description Farmer John is assigning some of his N (1 <= N <= 25,000) cows to do some cleaning chores around the barn. He always wants to have one cow working on c

ACM,再见! 4434

get_ccopt系列命令介绍

get_ccopt_property:用来获取cts阶段,clock tree上所有的参数信息,可以通过get_ccopt_property –help *获取所有参数。get_ccopt_skew_group_delay:用来获取skew group的相关信息,可以通过筛选出特定条件下skew_group的参数,如skew_group下latency最长是多少;get_ccopt_clock_tree_source_groups:获取clock tree的source group名字;

芯冰乐 291

POJ 2376 Cleaning Shifts 贪心

来源:http://poj.org/problem?id=2376 题意:有一些奶牛,每只奶牛负责一个时间段。问覆盖完全部的时间段最少需要多少只奶牛。若不能全部覆盖,输出-1. 思路:类似于区间覆盖的问题,明知道用贪心求解,但是还是wa了好几次。首先这道题有一个需要注意的就是每次不需要从上一只的结束点开始,可以从上一只结束的下一个点开始。比如说第一只的时间段是1 3,则第二只可是是4 7。首先

5238

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

POJ 2376 Cleaning Shifts 简单的贪心

题目链接: 【POJ—2376 Cleaning Shifts】 题目大意:一堆区间,用最少的区间覆盖整个区间。好吧其实我本来打算用动态规划的,但是区间太长了(10^6)。so。。。老老实实用贪心。 这次总算长记性了,自己多试了几组数据,没有起点的,没有终点的,不过注意一点:(1,5)(6,10)这样的区间是连续的。

ChenyangDu的博客 475

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

POJ2376 Cleaning Shifts 贪心

这题贪心法,首先按照每头牛

LoveKobe_的专栏 539

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

贪心——POJ2376 Cleaning Shifts

题目描述: http://poj.org/problem?id=2376 Cleaning Shifts Time

点滴 556

POJ2376贪心Cleaning Shifts

Cleaning Shifts Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Description Farmer John is assigning some of his N (1 <= N <= 25,000) cow

逝水流年轻染尘 757

POJ 2376 Cleaning Shifts【题解】贪心

题面:http://poj.org/problem?id=2376 和luogu的题面有不同,并不是询问最小的代价。 而是询问最小点数。 那么就可以用贪心解决了。 代码如下: #include<cstdio> #include<algorithm> #define int long long #define ll long long usin...

dazhishu2366的博客 112

POJ 2376 Cleaning Shifts(贪心)

题目地址:http://poj.org/problem?id=2376 思路:起点为1的选一个最大的,剩下的放到结构体中,排序一下贪心就行 AC代码: #include #include #include #include #include #include #include #include #include #include #include const int i

Java识堂,一个有干货的微信公众号 383

POJ - 2376 Cleaning Shifts(贪心)

题目链接:http://poj.org/problem?id=2376点击打开链接 Cleaning Shifts Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 23408   Accepted: 5853 Description Farmer Jo

xuejye的博客 347

[贪心] poj 2376 Cleaning Shifts

题意: 给n个线段,问你覆盖满[1,T]内的每个点,最少需要多少条线段。 思路: 贪心,按照x坐标升序,y坐标降序排。 默认先放入第一条。 然后根据从属关系继续放线段。 注意的一点是 [1,2]和[3,4]就可以覆盖满[1,4]了。 然后注意因为默认放入了第一条,所第一条的状态要特判。 包括 第一条如果是[1,T]的话 输出1. 代码: #include"cstdlib" #i

Enmity_Dark 688

POJ_2376_Cleaning Shifts(贪心)

题意:农夫有N头牛。现在他想让一些牛去做家务。然后他把一天分成T个时间点,也就是一天的时间点是区间[1,T]。他想要任何一个时间点都有牛在做家务。现在给出每头牛的工作时间,问你能否用最少的牛满足他的要求,即用最少的时间段覆盖掉这一天([1,T])。如果不能满足则输出-1,否则输出最少的牛数量。

一点也不二 4878

POJ 2376 Cleaning Shifts 【贪心 区间】

Cleaning Shifts Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14669   Accepted: 3730 Description Farmer John is assigning some of his N (1 <= N <= 25,000

wyjwyl的专栏 1277

POJ 2376 Cleaning Shifts [贪心]

POJ 2376 Cleaning Shifts题目大意给一个1..T的区间,然后N个子区间,取最少的把这个区间填满,求这个最小值算法以区间开始为关键字升序排序,如果左边不能覆盖,那肯定就不行。这样就选好了最开始的一块。那当然是选所以1开头的右边区间最大的一块。第二块就是在这1..y+1中再找个右边最大的一块,然后不断更新。如果找不到,那就不能填满,当全部找完以后,再判断能不能填满code#incl

more time 589

POJ - 2376 Cleaning Shifts【贪心】

Farmer John is assigning some of his N (1 <= N <= 25,000) cows to do some cleaning chores around the barn. He always wants to have one cow working on cleaning things up and has divided the day i...

zertow的博客 225
上一篇: poj 2336 Ferry Loading II—— 过河问题 贪心
下一篇: poj 2393 Yogurt factory——贪心
five_east_west
博客等级 码龄7年 74粉丝 127原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值