二分贪心
文章平均质量分 68
闻道-问道
这个作者很懒,什么都没留下…
展开
-
二分贪心--02
题目大概:输入一个一对一的字典,每行两个字符串,然后输入一个单词,输出翻译后的单词,如果字典中没有该单词,输出eh。思路:输入字典用sscanf()函数,分别放在一个结构体中,对结构体排序,然后运用二分查找寻找要翻译的单词。代码:#include #include #include #include #include using namespace std原创 2017-04-27 10:45:50 · 274 阅读 · 0 评论 -
nlogn的最长上升子序列的算法(LIS)
Problem DescriptionJGShining's kingdom consists of 2n(n is no more than 500,000) small cities which are located in two parallel lines.Half of these cities are rich in resource (we call them rich原创 2017-10-08 21:44:29 · 256 阅读 · 0 评论 -
问题 H: 周老师的区间问题
题目描述周老师无聊时乱写了 n 个区间,但处女座的他随后又想将 n 个区间整理合并,但他发现区间太多了,于是他想请你帮帮他输入每次测试输入多组数据(小于100组),对于每组输入数据:第一行为 n ,代表 n 个区间接下来 n 行,每行两个数 s , t 代表区间 [s,t]0 0 输出第一行输出一个数字 q原创 2017-12-28 20:05:16 · 600 阅读 · 0 评论 -
#1133 : 二分·二分查找之k小数
描述在上一回里我们知道Nettle在玩《艦これ》,Nettle的镇守府有很多船位,但船位再多也是有限的。Nettle通过捞船又出了一艘稀有的船,但是已有的N(1≤N≤1,000,000)个船位都已经有船了。所以Nettle不得不把其中一艘船拆掉来让位给新的船。Nettle思考了很久,决定随机选择一个k,然后拆掉稀有度第k小的船。 已知每一艘船都有自己的稀有度,Nettle现在把所有船的稀有度值告诉...原创 2018-03-15 23:35:00 · 219 阅读 · 0 评论 -
#1142 : 三分·三分求极值
描述这一次我们就简单一点了,题目在此:在直角坐标系中有一条抛物线y=ax^2+bx+c和一个点P(x,y),求点P到抛物线的最短距离d。提示:三分法输入第1行:5个整数a,b,c,x,y。前三个数构成抛物线的参数,后两个数x,y表示P点坐标。-200≤a,b,c,x,y≤200输出第1行:1个实数d,保留3位小数(四舍五入)样例输入2 8 2 -2 6样例输出2.437三分的模板。留下做个纪念。代...原创 2018-03-18 10:43:15 · 284 阅读 · 0 评论 -
#1684 : 车队(最长下降子序列)
描述在一条单车道的公路上有N辆汽车行驶,从前向后第i辆车的最高速度是Vi。所有车辆都会尽量保持最高速度行驶。不过由于只有单车道,所以当后方快车追上前方慢车后,无法超车,只能降速跟在慢车后面。 于是经过足够长时间(足够后方快车追上前方慢车)的行驶后,某些车辆会聚成一队以相同的速度向前行驶。我们把这些聚成一队的车辆称为一个"车队"。不同车队之间的距离会越来越大。 例如假设有5辆车,速度依次是[3,...原创 2018-04-01 20:14:59 · 270 阅读 · 0 评论 -
周中练习1 C
A friend of yours has written a program that compares every pair of a list of items. With n items,it works as follows. First, it prints a 1, and it compares item 1 to items 2, 3, 4, . . . , n. It then...原创 2018-05-24 20:05:58 · 268 阅读 · 0 评论 -
C. Liebig's Barrels (贪心)
C. Liebig's Barrelstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have m = n·k wooden staves. The i-th stave has length ai. You have to assem...原创 2018-05-24 20:16:16 · 420 阅读 · 0 评论 -
D. Bookshelves(贪心+dp)
D. Bookshelvestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMr Keks is a typical white-collar in Byteland.He has a bookshelf in his office with s...原创 2018-05-30 20:58:16 · 392 阅读 · 0 评论 -
Swordsman(快速输入挂模板)
Problem DescriptionLawson is a magic swordsman with k kinds of magic attributes v1,v2,v3,…,vk. Now Lawson is faced with n monsters and the i-th monster also has k kinds of defensive attributes ai,1,...原创 2018-08-14 21:08:12 · 269 阅读 · 0 评论 -
A、gpa (01分数规划)
Kanade selected n courses in the university. The academic credit of the i-th course is s[i] and the score of the i-th course is c[i]. At the university where she attended, the final score of her is ...原创 2018-08-02 22:02:45 · 365 阅读 · 0 评论 -
p1m2(二分)
Problem Description度度熊很喜欢数组!!我们称一个整数数组为稳定的,若且唯若其同时符合以下两个条件:数组里面的元素都是非负整数。 数组里面最大的元素跟最小的元素的差值不超过 11。举例而言,[1, 2, 1, 2][1,2,1,2] 是稳定的,而 [-1, 0, -1][−1,0,−1] 跟 [1, 2, 3][1,2,3] 都不是。现在,定义一个在整数数组进...原创 2018-08-12 21:12:15 · 291 阅读 · 0 评论 -
C. Elections(枚举+贪心)
As you know, majority of students and teachers of Summer Informatics School live in Berland for the most part of the year. Since corruption there is quite widespread, the following story is not uncomm...原创 2018-08-20 20:08:29 · 914 阅读 · 0 评论 -
1017(二分+树状数组)
Problem DescriptionN (2 <= N <= 8,000) cows have unique brands in the range 1..N. In a spectacular display of poor judgment, they visited the neighborhood 'watering hole' and drank a few too many be原创 2017-08-21 18:47:22 · 348 阅读 · 0 评论 -
Drying (二分)
Problem DescriptionIt is very hard to wash and especially to dry clothes in winter. But Jane is a very smart girl. She is not afraid of this boring process. Jane has decided to use a radiator to m原创 2017-08-12 20:09:27 · 344 阅读 · 0 评论 -
Monthly Expense (二分)
Problem DescriptionFarmer John is an astounding accounting wizard and has realized he might run out of money to run the farm. He has already calculated and recorded the exact amount of money (1 ≤原创 2017-08-11 21:34:06 · 410 阅读 · 0 评论 -
二分贪心--04
题目大概:输入n行数据,每行数据有四个数,共四组数,从四组数中挑出一个,组成一列数,找出四组数中相加为零的数列的个数。思路:前两列数相加,有n*n个和,后两列数相加,有n*n个和,找出两组和相加为零的个数,可以把一组和排序,然后用upper_bound()和lower_bound()函数,求每一个和为零的个数。代码:#include #include #incl原创 2017-04-27 10:53:52 · 241 阅读 · 0 评论 -
二分贪心--05
题目大概:输出n个数,找出其中的m个数,并且使得这m个数中,没个数的差值最小的最大值。思路:最小值的最大值,用二分做。开始时,l=0,r=最大的数,mid=(l+r)/2。从这n个数中寻找差值小于mid的数,当达到m个数时,,说明mid是这m个数的最小值。不断重复这个过程。如果找到最小值mid,并把mid赋值给 l 。使得mid趋向最大,最后输出 l 。那这个 l 就是最原创 2017-04-27 11:12:58 · 239 阅读 · 0 评论 -
二分贪心--21
题目大概:有n堆积木,积木高度不同,每个小方块高度相同。问,最少移动多少小方块,使得这些积木堆高度相等。思路:先求这些积木的平均数,在把所有的高度与平均数的差值加起来,最后除2,就是最少移动的方块数。感想:这个题有一点很坑人,最后输出的时候有一个小点,不注意看看不到。代码:#include #include #include using namesp原创 2017-04-27 11:21:59 · 285 阅读 · 0 评论 -
二分贪心--24
题目大概:输出n组数据,m个参赛者,找出这m个参赛者中 在这n组数据中 出现的次数 第二多的人。思路:结构体,里面有参赛者的编号和出现次数,并建立一个数组q[n]。对这个数组按出现次数由大到小排序,若一样大则按照编号从小到大排序。然后找出其中的最大的,在寻找出第二多的数量,由于排序已经排好,第二多出现次数的参赛者是挨着的,直接输出就可以了。感想:容易超时。代码原创 2017-04-27 11:32:09 · 244 阅读 · 0 评论 -
二分贪心--07
题目大概:两个木板之间有个笔直的细杆,当加热时,细杆会变弯,细杆的中心惠偏离原来的位置,求偏移的大小。思路:这个题主要运用了数学上的三个公式,1。。直角三角形边两边平方和等于斜边。2.。。弧长等于半径乘弧度。3.。。直角三角形中角和边的关系。第一个推出半径,第二个第三个得出弧长的一半。因为原来的方程解不出来,就用二分法不断逼近。感想:这个题其实精度比较重要,思路很好想,原创 2017-04-28 22:29:43 · 275 阅读 · 0 评论 -
二分贪心--06
题目大概:给出n根长度不同的木棒,让我们切成长度相同的m根木棒,问切的木棒的最长长度是多少。思路:每根木棒的长度和根数成反比。长度 l =0,,r为木棒总长度除m。mid=(l+r)/2.。用二分法不断逼近最大的长度即可。最后取右端点。代码:#include #include #include #include using namespace std;原创 2017-05-04 09:57:13 · 260 阅读 · 0 评论 -
二分贪心--20
题目大概:每个箱子能放6*6的大小的东西,分别有六种大小的物品,1*1..2*2..3*3...4*4。5*5 .6*6,问最少许雅io多少箱子。思路:高度不考虑了,只算大小。1。。。6*6 一个占一个箱子。2。。。5*5,占一个箱子在用1*1的补上空位。3。。。4*4,占一个箱子,用2*2 1*1补位。4。。。3*3,四个刚好一个箱子,当少于四个时,用2*2原创 2017-05-04 10:12:25 · 232 阅读 · 0 评论 -
二分贪心总结
二分二分指的是一种搜索的方法,主要有三个数,left,rest,mid,先判断mid这个值符合不符合。诺符合,则使得left=mid,否则rest=mid。上面说的是一般的二分方法。但我们用的时候,一般都不是这么用。如果是二分题,一般会有两个成反比的变量a,b,一般会知道一个确定的值a,然后b就是要二分的值,这就需要使得b不但逼近可能的值,使得a等于已知的值。这是一般的二分题的原创 2017-05-08 18:55:46 · 413 阅读 · 0 评论 -
CodeForces - 834C
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.The game consists of multiple rounds. Its rules are very simple: in each round, a natural number k i原创 2017-08-01 21:37:43 · 253 阅读 · 0 评论 -
Pie (二分)
Problem DescriptionMy birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a number N of them, of various tastes and of various sizes. F of my friends are coming t原创 2017-08-10 20:44:14 · 283 阅读 · 0 评论 -
Aggressive cows (二分)
Problem DescriptionFarmer John has built a new long barn, with N (2 <= N <= 100,000) stalls. The stalls are located along a straight line at positions x1,...,xN (0 <= xi <= 1,000,000,000).His原创 2017-08-11 21:29:53 · 303 阅读 · 0 评论 -
Copying Books (二分)
Problem DescriptionBefore the invention of book-printing, it was very hard to make a copy of a book. All the contents had to be re-written by hand by so called scribers. The scriber had been given a原创 2017-08-11 21:31:42 · 347 阅读 · 0 评论 -
处女座的训练(贪心)
链接:https://ac.nowcoder.com/acm/contest/329/D来源:牛客网 题目描述处女座靠着自己的家教本领赚够了去比赛的钱,于是开启了疯狂训练。在每个夜深人静第二天不收作业的夜晚,他都会开始刷题。"今日又是一个刷题的夜晚。"他挑选了n道题开始刷,而题太多,刷不掉,理还乱(呜呜)、自己没有解决的题目每分钟都会给他带来bibi的疲倦值,而解决每一道题目都需要花...原创 2019-01-26 22:37:11 · 217 阅读 · 0 评论