贪心算法习题

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

喷水装置(一)

时间限制:3000 ms | 内存限制:65535 KB

难度:3

描述

现有一块草坪,长为20米,宽为2米,要在横中心线上放置半径为Ri的喷水装置,每个喷水装置的效果都会让以它为中心的半径为实数Ri(0

输入

第一行m表示有m组测试数据

每一组测试数据的第一行有一个整数数n,n表示共有n个喷水装置,随后的一行,有n个实数ri,ri表示该喷水装置能覆盖的圆的半径。

输出

输出所用装置的个数

输入

第一行输入一个正整数N表示共有n次测试数据。

每一组测试数据的第一行有三个整数n,w,h,n表示共有n个喷水装置,w表示草坪

的横向长度,h表示草坪的纵向长度。

随后的n行,都有两个整数xi和ri,xi表示第i个喷水装置的的横坐标(最左边为0),ri表示该喷水装置能覆盖的圆的半径。

输出

每组测试数据输出一个正整数,表示共需要多少个喷水装置,每个输出单独占一行。

如果不存在一种能够把整个草坪湿润的方案,请输出0。

输入

第一行是一个整型数m(m<100)表示共有m组测试数据。

每组测试数据的第一行是一个整数n(1

随后的n行,每行有两个正整数Bi,Ei(0<=Bi,Ei<10000),分别表示第i个活动的起始与结束时间(Bi<=Ei)

输出

对于每一组输入,输出最多能够安排的活动数量。

每组的输出占一行

样例输入

样例输出

1

2

Gone Fishing

时间限制:3000 ms | 内存限制:65535 KB

难度:5

描述

John is going on a fishing trip. He has h hours available (1 <= h <= 16), and there are n lakes in the area (2 <= n <= 25) all reachable along a single, one-way road.

John starts at lake 1, but he can finish at any lake he wants. He can only travel

from one lake to the next one, but he does not have to stop at any lake unless he wishes to. For each i = 1,...,n - 1, the number of 5-minute intervals it takes to

travel from lake i to lake i + 1 is denoted ti (0

means that it takes 20 minutes to travel from lake 3 to lake 4. To help plan his

fishing trip, John has gathered some information about the lakes. For each lake i, the number of fish expected to be caught in the initial 5 minutes, denoted fi( fi >=

0 ), is known. Each 5 minutes of fishing decreases the number of fish expected to

be caught in the next 5-minute interval by a constant rate of di (di >= 0). If the

number of fish expected to be caught in an interval is less than or equal to di ,

there will be no more fish left in the lake in the next interval. To simplify the

planning, John assumes that no one else will be fishing at the lakes to affect the

number of fish he expects to catch.

Write a program to help John plan his fishing trip to maximize the number of fish expected to be caught. The number of minutes spent at each lake must be a

multiple of 5.

输入

You will be given a number of cases in the input. Each case starts with a line

containing n. This is followed by a line containing h. Next, there is a line of n

integers specifying fi (1 <= i <=n), then a line of n integers di (1 <=i <=n), and

相关文档
最新文档