POJ 2376 Cleaning Shifts 区间覆盖问题】的更多相关文章

http://poj.org/problem?id=2376 题目大意: 给你一些区间的起点和终点,让你用最小的区间覆盖一个大的区间. 思路: 贪心,按区间的起点找满足条件的并且终点尽量大的. 一开始排序还考虑了起点一样终点要大的,想了想没必要,因为只后都是直接扫描满足条件的.. 注意的是比如[4.5]下一次可以直接[6,10]这样...这一步坑了我好久... 后来一直WA,改了老半天...发现是大于等于少写了个等号,,,我去面壁...我要蹲墙角... #include<cstdio> #in…
POJ 2376 Cleaning Shifts(轮班打扫) Time Limit: 1000MS   Memory Limit: 65536K [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 clean…
http://poj.org/problem?id=2376 Cleaning Shifts Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12604   Accepted: 3263 Description Farmer John is assigning some of his N (1 <= N <= 25,000) cows to do some cleaning chores around the barn.…
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 shifts (1 <= T <= 1,000,000…
Cleaning Shifts Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 40751   Accepted: 9871 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 co…
题意:给定1-m的区间,然后给定n个小区间,用最少的小区间去覆盖1-m的区间,覆盖不了,输出-1. 析:一看就知道是贪心算法的区间覆盖,主要贪心策略是把左端点排序,如果左端点大于1无解,然后, 忽略小于1的部分(如果有的话),再找最长的区间,然后把这个区间的右端点作为下次寻找的起点, 再找最大区间,直到覆盖到最后. 注意:首先要判断好能不能覆盖,不能覆盖就结束,有可能会提前结束,也要做好判断,我就在这WA了好几次, 悲剧...其他的就比较简单了,不用说了. 代码如下: #include <ios…
<pre name="code" class="html"> Cleaning Shifts Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14425   Accepted: 3700 Description Farmer John is assigning some of his N (1 <= N <= 25,000) cows to do some cleani…
Cleaning Shifts 题目连接: 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 cleaning things up and has divided…
题目地址: http://poj.org/problem?id=2376 题目内容: Cleaning Shifts Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12226   Accepted: 3187 Description Farmer John is assigning some of his N (1 <= N <= 25,000) cows to do some cleaning chores arou…
Cleaning Shifts Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2743   Accepted: 955 Description Farmer John's cows, pampered since birth, have reached new heights of fastidiousness. They now require their barn to be immaculate. Farmer J…
Description Farmer John <= N <= ,) cows to <= T <= ,,), the first being shift 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…
POJ 2376 题意: 给出一给大区间和n各小区间,问最少可以用多少小区间覆盖整个大区间. 分析: 贪心法.设t为当前所有已确定区间的最右端,那我们可以每次都取所有可选的小区间(左端点<=t+1)中右端点最大的值,然后更新最右端点ans++.初始时t=0 注:所谓衔接不是[0,1][1,2]这样首尾相接,而是[0,1][2,3]即可,故为 t+1 #include<iostream> #include<algorithm> #include<string.h>…
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), t…
题目大意:给你很多条线段,开头结尾是$[l,r]$,让你覆盖整个区间$[1,T]$,求最少的线段数 题目传送门 线段树优化$DP$裸题.. 先去掉所有能被其他线段包含的线段,这种线段一定不在最优解里 排序,让所有线段构成左右端点位置都递增的排列 定义$f[i]$表示第$i$条线段,覆盖到第$i$条线段右端点时,需要的最少的线段数 $f[i]=min(f[j]+1)\;(j<i,r[j]>=l[i])$ 朴素是$n^2$转移的 开一棵最小值线段树,记录从$1$覆盖到位置$x$的最少线段数 每次求…
Cleaning Shifts Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4721   Accepted: 1593 Description Farmer John's cows, pampered since birth, have reached new heights of fastidiousness. They now require their barn to be immaculate. Farmer…
//线段树区间覆盖 #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; ; int flag; struct node{ int l,r; //vis 是这块区域是否完全被覆盖 bool vis; }tr[N<<]; struct point { int id; int x; }post[N<<];…
题目:http://poj.org/problem?id=2376 题意:就是 N 个区间, 输入 N 个区间的 [begin, end],求能用它们覆盖区间[1,T]的最小组合. 题解: 1. 首先对所有奶牛的排序,按照开始时间升序排序. 2. 更新 起点 为 上一次的终点 + 1,并寻找覆盖起点,且终点最远的区间 #include <iostream> #include <cstdlib> #include <cstdio> #include <algorit…
[题目链接] http://poj.org/problem?id=3171 [题目大意] 给出一些区间和他们的价值,求覆盖一整条线段的最小代价 [题解] 我们发现对区间右端点排序后有dp[r]=min(dp[l-1~r-1])+s 而对于求最小值我们可以用线段树优化 [代码] #include <cstdio> #include <algorithm> #include <cstring> #include <climits> using namespace…
Description Farmer John's cows, pampered since birth, have reached new heights of fastidiousness. They now require their barn to be immaculate. Farmer John, the most obliging of farmers, has no choice but hire some of the cows to clean the barn. Farm…
题意:给一些工作区间,如何选取最小的工作数量,覆盖[1,T]的工作时长 一开始的思路,当然也是错误的思路: 我想着,最小工作数量是吧?那肯定就是选择结束时间最晚的,给结束时间来一个排序.哎这个思路错误的离谱... 解题思路: 标记起点,当然对提供的工作区间,按开始的时间从小到大排序. 对能够覆盖起点(即可选的工作区域),选择结束时间最晚的(即工作时长最长的) 更新起点 代码中的小技巧 主要针对第二个解题思路: 可选区域:i<n&&node[i].start<=T+1  --i表…
题目大意: (不说牛了) 给出n个区间,选出个数最少的区间来覆盖区间[1,t].n,t都是给出的. 题目中默认情况是[1,x],[x+1,t]也是可以的.也就是两个相邻的区间之间可以是小区间的右端与大区间的左端相差1.这个是看题解才知道的. 解题思路: 贪心题的关键是找到贪心策略.但是这题的贪心策略没那么明显.并且贪心策略没有特定地去选择某一区间.这一题最重要的是要知道在什么情况下才需要增加一个区间. 首先是进行排序,按照区间的左端从小到大排序,左端相同的按照右端从小到大排. 从头开始遍历(只能…
应该还是蛮简单的一题,但是因为模拟太差,一直没调出来....... \(显而易见的应该按照左区间从小到大排序,相等按照右区间大到小排序\). \(那么第一个区间的l一定要是1,而且必拿(否则没有区间能包括1)\) \(往后找一个R尽可能大的区间,前提是L被我们上一个选的区间的R+1包括\) \(重复\) 细节还比较多,我还是太菜了啊 #include <bits/stdc++.h> using namespace std; struct p{ int l,r; }b[25009],a[2500…
Cleaning Shifts Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15143   Accepted: 3875 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 co…
Cleaning Shifts Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 31194   Accepted: 7677 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 co…
Cleaning Shifts Descriptions: 原文是English,我这就直接上Chinese了,想看原文的点一下链接哦 大表哥分配 N (1 <= N <= 25,000) 只中的一些奶牛在牛棚附近做些清洁. 他总是要让至少一只牛做清洁.他把一天分成T段(1 <= T <= 1,000,000), 第一段是1,最后一段是T 每只奶牛只在一些时间段有空.奶牛如果选择某一段时间,则必须完成整段时间的工作 你的任务是帮助FJ安排一些奶牛,使每段时间至少有一只奶牛被安排来做…
/* http://acm.hdu.edu.cn/webcontest/contest_showproblem.php?pid=1019&ojid=1&cid=10 题目: 给定一个时间T和N个时间区间,求最少需要多少个区间覆盖总区间[1,T],无法覆盖区域[1,T]时输出-1. 例如T=10,有3个区间[1,7],[3,6],[8,10],则最少需要两个区间来覆盖,选择区间1和区间3. 解题思路: 使用贪心法.首先将区间按开始时间从小到大排序,开始时间相等按结束时间从小到大排序. 1 如…
题目大意.N个区间覆盖[T1,T2]及相应的代价S,求从区间M到E的所有覆盖的最小代价是多少. (1 <= N <= 10,000).(0 <= M <= E <= 86,399). 思路是DP,首先将每一个区间依照T2从小到大排序,设dp(k)为从m覆盖到k所需最小代价,则有 dp(T2[i]) = min(dp(T2[i]), {dp(j) + Si,  T1[i] - 1<=j <= T2[i]}),对于 {dp(j) + Si,  T1[i] - 1<…
Cleaning Shifts Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4715   Accepted: 1590 Description Farmer John's cows, pampered since birth, have reached new heights of fastidiousness. They now require their barn to be immaculate. Farmer…
题目:http://poj.org/problem?id=1328 题意:给定海岛个数,雷达半径,输入各个海岛坐标,求能覆盖所有海岛的最少雷达数 题解: 1. 贪心的区间覆盖问题,尽量让每个雷达覆盖更多岛屿数. 2. 需要将题目转换一下,将海岛坐标,转换为,能够覆盖他的所有雷达圆心的区间, 然后对区间按照起点位置升序排序. 3. 定义一个最右点 end,依次判断所有区间,如果 end < sec[i].start,更新雷达位置,雷达数++:否则如果 end > sec[i].end,更新雷达位…
题意: 一共有n张海报, 按次序贴在墙上, 后贴的海报可以覆盖先贴的海报, 问一共有多少种海报出现过. 题解: 因为长度最大可以达到1e7, 但是最多只有2e4的区间个数,并且最后只是统计能看见的不同海报的数目,所以可以先对区间进行离散化再进行区间覆盖的操作. 由于墙上不贴东西的时候对后面没有影响, 所以可以不建树, 直接memset一下就好了. 因为是区域覆盖的问题, 树上原来的点并不会对后面的结果产生影响, 所以可以只修改lazy标记而不对树进行修改. 最后再用建树的操作访问一下lazy标记…