UVA-10020 Minimal coverage(贪心)】的更多相关文章

 Minimal coverage  The Problem Given several segments of line (int the X axis) with coordinates [Li,Ri]. You are to choose the minimal amount of them, such they would completely cover the segment [0,M]. The Input The first line is the number of test…
10020 Given several segments of line (int the X axis) with coordinates [Li, Ri]. You are to choose the minimalamount of them, such they would completely cover the segment [0, M].InputThe first line is the number of test cases, followed by a blank lin…
Minimal coverage The Problem Given several segments of line (int the X axis) with coordinates [Li,Ri]. You are to choose the minimal amount of them, such they would completely cover the segment [0,M]. The Input The first line is the number of test ca…
可以说是区间覆盖问题的例题... Note: 区间包含+排序扫描: 要求覆盖区间[s, t]; 1.把各区间按照Left从小到大排序,如果区间1的起点大于s,则无解(因为其他区间的左起点更大):否则选择起点在s的最长区间; 2.选择区间[li, ri]后,新的起点应更新为ri,并且忽略所有区间在ri之前的部分:  Minimal coverage  The Problem Given several segments of line (int the X axis) with coordinat…
Given several segments of line (int the X axis) with coordinates [Li, Ri]. You are to choose the minimal amount of them, such they would completely cover the segment [0, M].InputThe first line is the number of test cases, followed by a blank line.Eac…
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=961 贪心,排序,对左端点贪,找最大右端点. #include <cstdio> #include <cstring> #include <algorithm> #define maxn 6000000 using namespace std; int t,…
链接: http://acm.timus.ru/problem.aspx?space=1&num=1303 按照贪心的思想,每次找到覆盖要求区间左端点时,右端点最大的线段,然后把要求覆盖的区间改为这个右端点到M这个区间.依次类推下去,这样的话就只需要扫一遍就可以找去来. 要做的预备工作就是将线段按照左端点的升序排序就可以了. 它的时间复杂度就是O(n) 代码一直WA,望大神指教 #include<iostream> #include<stdio.h> #include<…
题目大意:先确定一个M, 然后输入多组线段的左端和右端的端点坐标,然后让你求出来在所给的线段中能够 把[0, M] 区域完全覆盖完的最少需要的线段数,并输出这些线段的左右端点坐标. 思路分析: 线段区间的起点是0,那么找出所有区间起点小于0中的最合适的区间. 因为需要尽量少的区间,所以选择右端点更大的区间,它包含所选线段更大. 如果在所有区间中找到了解,且右端点小于M,则把找到的区间的右端点定为新的线段区间的起点. #include <iostream> #include <stdio.…
题目传送门 /* 题意:最少需要多少条线段能覆盖[0, m]的长度 贪心:首先忽略被其他线段完全覆盖的线段,因为选取更长的更优 接着就是从p=0开始,以p点为标志,选取 (node[i].l <= p && p < node[i+1].l) 详细解释:http://www.cnblogs.com/freezhan/p/3219046.html */ #include <cstdio> #include <iostream> #include <al…
链接: http://acm.timus.ru/problem.aspx?space=1&num=1303 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26733#problem/D D - Minimal Coverage Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice UR…
题目大意:在x轴上,给一些区间,求出能把[0,m]完全覆盖的最少区间个数及该情形下的各个区间. 题目分析:简单的区间覆盖问题.可以按这样一种策略进行下去:在所有区间起点.长度有序的前提下,对于当前起点,找到可以覆盖下去的最长区间进行覆盖,并不断更新起点,直到覆盖完所有区间. 代码如下: # include<iostream> # include<cstdio> # include<vector> # include<cstring> # include<…
uva 1615 高速公路(贪心,区间问题) 给定平面上n个点和一个值D,要求在x轴上选出尽量少的点,使得对于给定的每个点,都有一个选出的点离它的欧几里得距离不超过D.(n<=1e5) 对于每个点,可以找出在x轴上的对应线段,于是这道题就被转换成了一个区间选点问题.将所有线段都按右端点排好序,然后每次将点取在线段的最右端,如果覆盖不到最新线段就再创造一个新点,这样一直贪心的取下去即可. #include <cmath> #include <cctype> #include &…
题意: 数轴上有n个闭区间[ai, bi],选择尽量少的区间覆盖一条指定线段[0, m] 算法: [start, end]为已经覆盖到的区间 这是一道贪心 把各个区间先按照左端点从小到大排序,更新start为end,如果区间1在start的右端,则无解,因为其他区间更不可能覆盖到 然后在剩下的能覆盖到start的区间里面选择能覆盖到最右端的区间并更新end,然后记录在path里面.如果end的已经将m覆盖则退出循环 如果遍历完所有的区间后end依然没能覆盖到start,则无解 最后按照parh里…
题目地址:Ural 1303 先按每一个线段的左端点排序,然后设置一个起点s.每次都从起点小于等于s的线段中找到一个右端点最大的. 并将该右端点作为新的起点s,然后继续找. 从左到右扫描一遍就可以. 代码例如以下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #include <math.h>…
题意:蚂蚁在木棍上爬,速度1cm/s,给出木棍长度和每只蚂蚁的位置,问蚂蚁全部下木棍的最长时间和最短时间. 模拟一下,发现其实灰常水的贪心... 不能直接求最大和最小的= =.只要求出每只蚂蚁都走长路下木棍时的最大值,和走短路时的就行了. 代码: /* * Author: illuz <iilluzen@gmail.com> * Blog: http://blog.csdn.net/hcbbt * File: uva10714.cpp * Lauguage: C/C++ * Create Da…
"Waiting for orders we held in the wood, word from the front never came By evening the sound of the gunfire was miles away Ah softly we moved through the shadows, slip away through the trees Crossing their lines in the mists in the fields on our hand…
题意:给出一个数N,下限L上限U,在[L,U]里面找一个整数,使得N|M最大,且让M最小. 很明显用贪心,用位运算搞了半天,样例过了后还是WA,没考虑清楚... 然后网上翻到了一个人家位运算一句话解决了 = =....ORZ... 人家的分析:(by天然呆大神) 儘量讓 N 中為 0 的位元,M 為 1:N 為 1 的位元, M 為 0. 因此從高位往低位檢查, 如果 N 為 1(M 儘量為 0),若 M 不能為 0,則必是因為 M 為 1 仍小於 L: 如果 N 為 0(M 儘量為 1),若…
UVA11039-Building designing Time limit: 3.000 seconds An architect wants to design a very high building. The building will consist of some floors, and each floor has a certain size. The size of a floor must be greater than the size of the floor immediate…
UVA 12130 - Summits 题目链接 题意:给定一个h * w的图,每一个位置有一个值.如今要求出这个图上的峰顶有多少个.峰顶是这样定义的.有一个d值,假设一个位置是峰顶.那么它不能走到不大于该峰顶高度 - d的位置.假设满足这个条件下.而且无法走到更高的山峰,那么它就是峰顶 思路:利用贪心的策略.把全部点丢到优先队列,每次取出最高的峰值開始找,进行广搜.搜的过程中记录下最大值的点的个数.假设这个是峰顶.就加上这个数. 推断是不是峰顶的方法为,假设广搜过程中.不会找到一个点的能到的最…
UVA - 11134 Fabled Rooks We would like to place n rooks, 1 ≤ n ≤ 5000, on a n × n board subject to the following restrictions The i-th rook can only be placed within the rectan- gle given by its left-upper corner (xli,yli) and its right- lower corner…
题目链接: 题目 Graph Construction Time limit: 3.000 seconds 问题描述 Graph is a collection of edges E and vertices V. Graph has a wide variety of applications in computer. There are different ways to represent graph in computer. It can be represented by adjace…
We would like to place  n  rooks, 1 ≤  n  ≤ 5000, on a  n×n  board subject to the following restrictions The i-th rook can only be placed within the rectangle given by its left-upper corner (xli, yli) and its right-lower corner (xri, yri), where 1 ≤ …
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1323 题意 长方形l * w,给出长方形中间那条线上n个圆的圆心c和半径r,选取最少数目的圆覆盖长方形,选不了输出-1 思路 明显,算出圆在边上的坐标,然后尽量从左向右扩展就行 感想: 卡题的原因是反射性以为r和w很小,但其实可以很大,所以用double存r 代码 #include…
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1980 题意 n个数,要求正负相间,绝对值增长,问n个数能组成的这样数列最长多长 思路 明显,分成正负两组,挨个在两组内取最小,直到不能取就行 代码 #include <algorithm> #include <cassert> #include <cma…
https://vjudge.net/problem/UVA-10382 题意: 有一个长为l,宽为w的草坪,在其中心线不同位置有n个点状的喷水装置,喷水坐标为p,喷水半径为r.求喷到所有草坪的最少喷水装置数量. 思路: 喷水装置的有效面积是图中的矩形部分,由此就把喷水区域变成了区间区域,之后利用贪心就可以了. #include<iostream> #include<string> #include<cstring> #include<cmath> #inc…
https://vjudge.net/problem/UVA-714 题意:把一个包含m个正整数的序列划分成k个非空的连续子序列,使得每个正整数恰好属于一个序列.设第i个序列的各数之和为S(i),你的任务是让所有S(i)的最大值尽量小. 思路:“最大值尽量小”问题. 区间的范围肯定是所有数中最大的一个至所有数之和,我们可以使用二分法来确定这样的一个值x,x尽量小并且每个区间都不大它. 题目要求的是前面的区间尽量小,那我们就需要贪心一下,从右边的数开始分配区间.需要注意的是,如果当前剩下来的待分配…
URAL 1303 思路: dp+贪心,然后记录路径 mx[i]表示从i开始最大可以到的位置 sufmx[i]表从1-i的某个位置开始最大可以到达的位置 比普通的贪心效率要高很多 代码: #include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mp make_pair #define pii pair<int,int> #define mem(a,b…
题目连接:10670 - Work Reduction 题目大意:有tol的工作量,和要求达到的工作剩余量sur,然后是公司总数,对应每个公司提供两种服务,1.完成一个工作量,2.完成当前未完成工作量的一半(注意这里是tol的一半,不是tol - sur的一半), 当剩余工作量为奇数, 对模2四舍五入.现在给出每个公司的两种服务所需费用, 要求计算出每个公司单独完成工作量所花费的最少金额(剩余工作量必须为sur,输出按照金额大小,相同按照公司名字的字典序大小. 解题思路:贪心, 对于每个公司,比…
题意:给定一个数 n 个点,和一个d,要求在x轴上选出尽量少的点,使得对于给定的每个点,都有一个选出的点离它的欧几里德距离不超过d. 析:首先这是一个贪心的题目,并且是区间选点问题,什么是区间选点呢,就是说在数轴上有 n 个闭区间,取尽量少的点,使得每个区间都至少有一个点. 一看是不是和这个题很相似,是的,那么区间哪里来呢?自己造呗,既然说是距离不超过d,意思就是在给定的点为圆心,以 d 为半径画圆,在x轴上的区间, 那么区间不就有了么,然后这个怎么贪心呢,是这样的,把所有的区间的右端点从小到大…
题目: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=68990#problem/M 题目需求:数轴上有n个闭区间[ai,bi],选择尽量少的区间覆盖一条指定的线段[0,m]. 题目解析:没什么好说的,就是贪心,具体看代码. #include <iostream> #include <string.h> #include <stdio.h> #include <algorithm> #includ…