UVa 10148 Advertisement (贪心&标记法单个处理)

移花接木,玩转CANoe的几种扩展接口应用(五)——串口设备 近期看到粉丝朋友在CANoe自动化测试方面的关注度很大,今天就围绕这个做一个专题,总结一下以往项目上用过的几种CANoe扩展接口,分享出来希望对相关领域的网友有所帮助。本文是该专题的第五篇文章,主要讲解了串口设备的功能配置、连接方法、配置方法、调用方法,最后分析了这种扩展借口应用的特点和适用场景。 阅读详情

10148 - Advertisement

Time limit: 3.000 seconds 

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_problem&problem=1089

The Department of Recreation has decided that it must be more profitable, and it wants to sell advertising space along a popular jogging path at a local park. They have built a number of billboards (special signs for advertisements) along the path and have decided to sell advertising space on these billboards. Billboards are situated evenly along the jogging path, and they are given consecutive integer numbers corresponding to their order along the path. At most one advertisement can be placed on each billboard.

A particular client wishes to purchase advertising space on these billboards but needs guarantees that every jogger will see it's advertisement at leastK times while running along the path. However, different joggers run along different parts of the path.

Interviews with joggers revealed that each of them has chosen a section of the path which he/she likes to run along every day. Since advertisers care only about billboards seen by joggers, each jogger's personal path can be identified by the sequence of billboards viewed during a run. Taking into account that billboards are numbered consecutively, it is sufficient to record the first and the last billboard numbers seen by each jogger.

Unfortunately, interviews with joggers also showed that some joggers don't run far enough to seeK billboards. Some of them are in such bad shape that they get to see only one billboard (here, the first and last billboard numbers for their path will be identical). Since out-of-shape joggers won't get to seeK billboards, the client requires that they see an advertisement on every billboard along their section of the path. Although this is not as good as them seeingK advertisements, this is the best that can be done and it's enough to satisfy the client.

In order to reduce advertising costs, the client hires you to figure out how to minimize the number of billboards they need to pay for and, at the same time, satisfy stated requirements.

Input

The first line of the input consist of an integer indicating the number of test cases in theinput. Then there's a blank line and the test cases separated by a blank line.

The first line of each test case contains two integers K and N (1 ≤ K, N ≤ 1000) separated by a space.K is the minimal number of advertisements that every jogger must see, andN is the total number of joggers.

The following N lines describe the path of each jogger. Each line contains two integersAi and Bi (both numbers are not greater than 10000 by absolute value).Ai represents the first billboard number seen by jogger numberi and Bi gives the last billboard number seen by that jogger. During a run, joggeri will see billboards Ai, Bi and all billboards between them.

Output

On the first line of the output fof each test case, write a single integer M. This number gives the minimal number of advertisements that should be placed on billboards in order to fulfill the client's requirements. Then writeM lines with one number on each line. These numbers give (in ascending order) the billboard numbers on which the client's advertisements should be placed. Print a blank line between test cases.

Sample input

1

5 10
1 10
20 27
0 -3
15 15
8 2
7 30
-1 -10
27 20
2 9
14 21

Sample output for the sample input

19
-5
-4
-3
-2
-1
0
4
5
6
7
8
15
18
19
20
21
25
26
27

思路:对区间右端点排序,然后从右端点开始处理每个区间,按题意模拟即可。


完整代码:

/*0.086s*/

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 10000;

struct T
{
	int l, r;
	bool operator < (const T a) const
	{
		return r < a.r;///排右边
	}
} p[1005];
bool vis[N + N + 5];///这里放广告

int main()
{
	int cas, i, j, k, n, cnt, a, b, temp;
	scanf("%d", &cas);
	while (cas--)
	{
		scanf("%d%d", &k, &n);
		for (i = 0; i < n; ++i)
		{
			scanf("%d%d", &a, &b);
			if (a > b) swap(a, b);///注意
			p[i].l = N + a, p[i].r = N + b;
		}
		sort(p, p + n);
		memset(vis, 0, sizeof(vis));
		cnt = 0;
		for (i = 0; i < n; ++i)
		{
			if (p[i].r - p[i].l + 1 <= k)
			{
				for (j = p[i].l; j <= p[i].r; ++j)
					if (!vis[j]) ++cnt, vis[j] = true;///采用标记法要比直接输出更方便(因为处理多个区间很复杂,一次只研究一个区间更简单)
			}
			else
			{
				temp = k;
				for (j = p[i].l; j <= p[i].r; ++j)
					if (vis[j]) --temp;///统计广告牌数,注意可能统计成负值
				for (j = p[i].r; temp > 0; --j)
					if (!vis[j]) ++cnt, vis[j] = true, --temp;
			}
		}
		printf("%d\n", cnt);
		for (i = 0; i < N + N + 5; ++i)
			if (vis[i]) printf("%d\n", i - N);
		if (cas) putchar(10);
	}
	return 0;
}

Feature ‘alsa‘ was enabled, but the pre-condition ‘config.unix && !config.qnx && libs.alsa‘ failed解决 这个问题主要是Qt多媒体插件中缺少了ALSA音频库,所以我们需要自行先编译ALSA 在执行./configure的时候,配置项中ALSA为no Qt Multimedia: ALSA ................................... no GStreamer 1.0 .......................... no GStreamer 0.10 ......................... no Video for Linux ............. 阅读详情

相关推荐

从DRV8825升级到TMC5160:老司机教你避坑电机驱动替换(含模式2快速上手)

本文详细指导了如何从DRV8825步进驱动升级到更先进的TMC5160智能驱动芯片。文章重点剖析了硬件替换的核心差异、PCB布局的关键细节,并提供了模式2(STEP/DIR兼容模式)的快速上手配置与调试指南,帮助开发者有效避开升级过程中的常见陷阱,实现静音、高效、可靠的电机控制。

weixin_29163797的博客 450

UVa 10148 Advertisement

本文提出了一种贪心算法来解决广告牌投放问题,目标是确保每位慢跑者在其跑步路径上看到至少K个广告。算法首先规范化并排序所有慢跑路径区间,然后从右往左在每个区间内放置广告,最大化广告牌的共享效果。通过使用集合存储广告牌位置,确保高效查找和自动排序。该方案在合理时间复杂度内实现了最少广告投放量,满足题目要求。样例测试验证了算法的正确性和效率。

寂静山林 509

AURIX-TC3xx-GTM详解六-DPLL(Digital PLL Module)-寄存器1-DPLL寄存器

主要有下图这些寄存器2、

m0_69929716的博客 445

uva 10148 Advertisement (贪心-区间选点)

uva 10148  Advertisement The Department of Recreation has decided that it must be more profitable, and it wants to sell advertising space along a popular jogging path at a local park. They have

总有那么一群人喜欢盯着我的博客看,估计这是他们见过最长的博客名,我必须得告诉他们博客名最长可以写多长 717

关于光耦隔离与SP3485E芯片一起使用无法拉高485使能引脚问题

最近在做的一个项目,定制了一块STM32F407ZG的工控板,工控板载4个485接口全部都是只能接收数据,不能对外发送数据。1.接线不正确:接线不正确导致485收发出现问题。 2.程序端口初始化问题:控制光耦隔离的输入脚IO的初始化和置位状态有问题。 3.GPIO复用问题:控制对应串口的GPIO不是正点原子默认的GPIO,而是经过复用的其他IO,复用问题。 4.程序设置与485E芯片收发模式不对应:对于使能引脚的电平要根据光耦的输出情况确定输入IO与RE的关系,可能模式没有对应。 5.光耦隔离或者SP485

weixin_45862642的博客 2985

五.卡尔曼滤波器(EKF)开发实践之五: 编写自己的EKF替换robot_pose_ekf中EKF滤波器

本系列文章主要介绍如何在工程实践中使用卡尔曼滤波器,分五个小节介绍: 一.卡尔曼滤波器开发实践之一: 五大公式 二.卡尔曼滤波器开发实践之二: 一个简单的位置估计卡尔曼滤波器 三.卡尔曼滤波器(EKF)开发实践之三: 基于三个传感器的海拔高度数据融合 四.卡尔曼滤波器(EKF)开发实践之四: ROS系统位姿估计包robot_pose_ekf详解 五.卡尔曼滤波器(EKF)开发实践之五: 编写自己的EKF替换robot_pose_ekf中EKF滤波器 也就是本文 ...

okgwf的博客 4142

UVA 10148 Advertisement 贴广告的艺术 贪心 区间选点

题意:一段路上,给出n个慢跑者跑步的区间,给出k,要求让每个慢跑者都能看到k个广告,区间都是整数操作,也就是说一个广告只能放在一个整数上,求最小贴的广告数。 分析:贴小广告的也好辛苦啊(大雾)。 注意如果区间长度小于k的话贴满了就行。 这就是区间选点问题的变形题。排序后从每个区间后面选起就行了。 代码: /* * Author: illuz * Blog:

水果君の日常 1947

图相似度模型(论文篇)

图相似度模型

weixin_43702653的博客 5753

uva 10148 - Advertisement(区间选点问题)

题目连接:10148 - Advertisement 题目大意:给出目标数和n个行人, 让后给出n个人的移动方向(从某一站移动到另外一站), 现在要粘贴广告在一些站台上,要使得每个行人看到的广告数尽量接近目标。 解题思路:典型的区间选点问题,见算法入门经典P153. #include #include #include using namespace std;

不慌不忙、不急不躁 1242

【Linux】U盘配置Ubuntu系统 ——(Win10+Ubuntu20.04)双系统安装教程

Ubuntu系统安装

WS_Change的博客 4352

交叉编译Qt6.5.3(RK3568开发板)

注意,如果使用其它版本的交叉编译器的话,请确保你的交叉编译器能够支持 C++17标准。为确保后续交叉编译没问题,需要确保开发板使用的GLIBC版本不小于2.34版本。到 linaro 网站上下载交叉编译工具,我下载的是 gcc-linaro-11.3.1-2022.06-x86_64_aarch64-linux-gnu.tar.xz。安装 CMake ,最低要求3.16版本,如果要静态编译,需要3.21及以上版本。我使用的3.27版本。:指定为最后交叉编译后的Qt6.5.3库的安装目录。

m0_46309425的博客 5110

UVa 10148 - Advertisement

题意:  在一个街道上有很多广告位,现在一家公司需要投放广告,要针对具体情况投放。给定一个K值,假如慢跑者经历K以上个路段,至少要看到K个广告位,经历少于等于K个,则需要让慢跑者看到全部广告位,求投放的最少的广告位。 思路:贪心+排序    对于慢跑者经历的路段区间,按区间右端点升序排序,从区间最右端向左遍历每一个慢跑者的区间,对需要设置的广告位进行标记,最后输出标记的点。   注意:输入

苹果苹果一只梨 398

Centos 7 Linux 安装单机 Hadoop(HDFS):下载、安装、配置、测试

本文详细介绍了在 CentOS 7 系统上安装与配置单机 Hadoop(HDFS)的完整流程,涵盖 JDK 环境准备、Hadoop 安装包下载与部署、核心配置文件(core-site.xml、hdfs-site.xml 等)修改、SSH 免密登录设置、HDFS 格式化及服务启动,并通过命令行与 Web 界面验证 HDFS 和 YARN 功能,适合 Hadoop 初学者快速搭建本地测试环境。

寒水馨 · 轻量级技术文档 · hanshuixin.org 3246

UVa 10148 - Advertisement

【链接】 http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_problem&problem=1089 【原题】 The Department of Recreation has decided that it must be more profit

D_Double's Journey 2333

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

UVa:10148 Advertisement(贪心)

贪心。要求每个区间至少有k个点覆盖,如果区间长度不足k则全部有点覆盖。 根据区间右端点从小到大排序,如果右端点相同则根据左从小到大排序。对于每个区间选取右边k个端点。这里有个问题就是,如果该段区间已经选过一部分点了,那需要统计一下已经选过多少点,我这里用了最笨的办法,直接数(由于区间有负数,所以都加了10005来消掉负数),这样再把剩下的点选够即可。 这样最坏的情况是1000*20000,居然

Fighting 662

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

uva 10148 - Advertisement

点击打开链接uva 101148 题目意思: 公园里有一个广告牌,由于公园里经常有很多人在慢跑锻炼身体,现在有一个客户想在这个广告牌上面贴广告,他想让每一个慢跑的人都能够看到至少k个广告,由于每一个人跑步的路径不同,不同人看到的广告是不同的,可能只看到一个广告。现在规定广告是一序列连续的整数表示,有n个人,每一个能够看到的第一个广告和最后一个广告是已知的,现在要求满足这个客户的要求下(客户...

我是传奇 260

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain&#39;s apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = &quot;R. B. Palm&quot;, title = &quot;Prediction as a candidate for learning deep hierarchical models of data&quot;, year = &quot;2012&quot;,}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath(&#39;DeepLearnToolbox&#39;));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand(&#39;state&#39;,0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = &#39;sigm&#39;;%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er &lt; 0.10, &#39;Too big error&#39;);```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er &lt; 0.16, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er&lt;0.12, &#39;Too big error&#39;);```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er &lt; 0.08, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er &lt; 0.1, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er &lt; 0.1, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er &lt; 0.1, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er &lt; 0.1, &#39;Too big error&#39;);%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er &lt; 0.1, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free &quot;Bitdeli Badge&quot;)

【ICPC-105】uva 10148 - Advertisement

点击打开链接uva 101148 题目意思: 公园里有一个广告牌,由于公园里经常有很多人在慢跑锻炼身体,现在有一个客户想在这个广告牌上面贴广告,他想让每一个慢跑的人都能够看到至少k个广告,由于每一个人跑步的路径不同,不同人看到的广告是不同的,可能只看到一个广告。现在规定广告是一序列连续的整数表示,有n个人,每一个能够看到的第一个广告和最后一个广告是已知的,现在要求满足这个客户的要求下(客...

藏经阁 | 玄苦 1548

UVA - 10148 Advertisement

贪心,用类似刘汝佳书上的办法就能解决。

cgjiayou 303

UVA10148- Advertisement(区间选点)

题意:一段路上,给出n个慢跑者跑步的区间,给出k,要求让每个慢跑者都能看到k个广告,区间都是整数操作,也就是说一个广告只能放在一个整数上,求最小贴的广告数 思路:关于区间选点的问题。把所有区间按B从小到大排序(B相同时A从大到小排序),则如果出现区间包含的情况,小区间一定排在前面。所以贪心的策略就是,从后往前取k个点。因为只有从后面开始取点,满足的区间才最会最多,这样就能达到使用最少的点

懒人一枚。 1069

UVA 10148 Advertisement (贪心 + 区间选点问题)

Problem F "Advertisement" The Department of Recreation has decided that it must be more profitable, and it wants to sell advertising space along a popular jogging path at a local park. They have

Remilia's 1208

uva 10148 Advertisement

原题: The Department of Recreation has decided that it must be more profitable, and it wants to sell advertising space along a popular jogging path at a local park. They have built a number of billboar

@fei 486

UVA - 10148 Advertisement(贪心 区间选点)

题目大意:一条路上有若干广告位, 给出 N 个跑者跑步的区间,要求每个跑者至少能看到 K 个广告,若跑步范围不到 K 则区间内都要投放,问最少要投放多少个广告,并输出坐标。 解题思路:区间选点问题,先根据区间右端排升序,从右端开始选 k 个点标记,因为下一个区间很可能会覆盖到之前区间的右端,这样就能重复利用。对于下一个区间,先统计已经被标记过的点,不足 k 个的再从当前区间的右端开始选点补足。之后

life kicks in right now 382

uva10148 - Advertisement(区间选点)

题意: 贴广告牌,n个人,会分别在一个区间内跑步,区间点为整数,在这些整数里,你负责选点贴广告,让他们每个人都至少能看见K个广告,若区间范围小于k,则该区间都要贴广告 思路: 贪心题。参考了《算法经典入门》中做法,首先区间左小右大,然后按右边界排序,尽量多得在右边放广告牌,因为这样的话重叠部分小,所需放置的广告牌亦随之变小。代码如下:#include <iostream> #include <

不要皱眉 420
上一篇: HDU 2045 不容易系列之(3)—— LELE的RPG难题 (组合数学)
下一篇: POJ 2229 Sumsets (递推&整数划分变形)
synapse7
博客等级 码龄14年 432粉丝 701原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值