UVaLive 6834 Shopping (贪心)】的更多相关文章

题意:给定 n 个商店,然后有 m个限制,去 c 之前必须先去d,问你从0到n+1,最短路程是多少. 析:我们我们要到c,必须要先到d,那么举个例子,2 5, 3 7,如果我们先到5再到2,再到7再到3,那么3-5这个区间我们走了4次,如果我们先到7再到2, 那么就只走了3次,这很明显是最优的,所以我们把能合并的区间都合并起来,然后再一块计算. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include…
题目传送门 /* 题意:有n个商店排成一条直线,有一些商店有先后顺序,问从0出发走到n+1最少的步数 贪心:对于区间被覆盖的点只进行一次计算,还有那些要往回走的区间步数*2,再加上原来最少要走n+1步就是答案了 详细解释:http://blog.csdn.net/u013625492/article/details/45640735 */ #include <cstdio> #include <algorithm> #include <cstring> #include…
Shopping 题目连接: http://codeforces.com/gym/100803/attachments Description Your friend will enjoy shopping. She will walk through a mall along a straight street, where N individual shops (numbered from 1 to N) are aligned at regular intervals. Each shop…
题目链接: http://acm.hust.edu.cn/vjudge/problem/48416 Shopping Malls Time Limit: 3000MS 问题描述 We want to create a smartphone application to help visitors of a shopping mall and you have to calculate the shortest path between pairs of locations in the mall…
Let x1, x2,..., xm be real numbers satisfying the following conditions: a) -xi ; b) x1 + x2 +...+ xm = b *  for some integers  a and  b  (a > 0). Determine the maximum value of xp1 + xp2 +...+ xpm for some even positive integer p. Input Each input li…
题目连接:2911 - Maximum 题目大意:给出m, p, a, b,然后xi满足题目中的两个公式, 要求求的 xp1 + xp2 +...+ xpm 的最大值. 解题思路:可以将x1 + x2 +...+ xm = b *  两端同时乘以根号a去计算.然后按照贪心的思想去计算. #include <stdio.h> #include <math.h> int l, r; double m, p, a, b, tmp, sum; int main() { while (sca…
题目链接:https://vjudge.net/contest/244167#problem/F 题目: Given any integer base b ≥ 2, it is well known that every positive integer n can be uniquely represented in base b. That is, we can write n = a0 + a1 ∗b + a2 ∗b∗b + a3 ∗b∗b∗b + ... where the coeffi…
题目链接  题意 工程师要安装n个服务,其中服务Ji需要si单位的安装时间,截止时间为di.超时会有惩罚值,若实际完成时间为ci,则惩罚值为max{0,ci-di}.从0时刻开始执行任务,问惩罚值最大的两个服务的惩罚值之和的最小是多少? 分析 乍一看似乎要二分,但实际上并不是.贪心来做,按di从小到大安排任务,当di相等时,让完成时间短的排前,这样安排任务一定时更优的,但是并不能满足题目的要求.于是需要从两个最大惩罚值的前面挑选一个任务,并将它放置在后面,然后更新答案即可. #include<c…
There will be several test cases in the input. Each test case will begin with a line with three integers: N A B Where N is the number of teams (1N1, 000), and A and B are the number of balloons in rooms A and B, respectively (0A, B10, 000). On each o…
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1538 很奇妙的一个题,开始没有思路.问了别人才知道. 题目的意思可以理解成上图中,从0点开始向右走,走到n+1点需要最少步数.思路是:因为走某些点时,必须先走另外一点,所以可以用贪心算法,将限制条件可以看成区间,求出它们的并集,如下图: #include<iostream> #include<algorithm> #include<cstring> #include&l…