poj 1957 二分搜索】的更多相关文章

题意:N个灯泡离地H_i,满足H1 = A ,Hi = (Hi-1 + Hi+1)/2 – 1,HN = B ,求最小B. 思路: 只要二分第二个灯泡的高度就可以推出全部灯泡的高度 如果hi<0说明第二个灯泡的高度太高了 一直缩小精度,就可以得到想要的答案 解决问题的代码: #include <iostream> #include <stdio.h> #include <algorithm> #include <math.h> #include <…
传送门:Problem 2976 参考资料: [1]:http://www.hankcs.com/program/cpp/poj-2976-dropping-tests-problem-solution-challenge-programming-contest.html [2]:http://www.cnblogs.com/demian/p/7498407.html 有感而发: 太晚了,身心疲惫,如果明天有空的话,再写上自己对于此题的理解吧,真是个充实愉快的一天啊. 对了,今天是我们学校70周…
Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 17324   Accepted: 5835   Special Judge Description My 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 vari…
题意:N个等差数列,初项X_i,末项Y_i,公差Z_i,求出现奇数次的数? 思路: 因为只有一个数出现的次数为奇数个 假设 第二个数字的个数为 奇数个,其余全部都是偶数个 ,累计出现的次数 a1偶数 a1+a2 奇数 a1+a2+a3 奇数 ................... 会出现这种情况:偶偶偶...偶奇 第一个出现奇的就是我们想要的 解决问题的代码: #include <iostream> #include <stdio.h> #include <algorithm…
Description Given N numbers, X1, X2, ... , XN, let us calculate the difference of every pair of numbers: ∣Xi - Xj∣ ( ≤ i < j ≤ N). We can ) differences through this work, and now your task is to find the median of the differences as quickly as you ca…
题目:http://poj.org/problem?id=3273 思路:通过定义一个函数bool can(int mid):=划分后最大段和小于等于mid(即划分后所有段和都小于等于mid) 这样我们转化为求 满足该函数的 最小mid.即最小化最大值,可以通过二分搜索来做,要注意二分的边界.WR了好几次. 代码: #include<iostream> #include<string> #include<cstdlib> #include<cstdio> u…
POJ 2456 题意 农夫约翰有N间牛舍排在一条直线上,第i号牛舍在xi的位置,其中有C头牛对牛舍不满意,因此经常相互攻击.需要将这C头牛放在离其他牛尽可能远的牛舍,也就是求最大化最近两头牛之间的距离. 思路 二分搜索,现将牛舍排序,然后定义C(d),表示可安排的C头牛最近距离不小于d. #include <iostream> #include <algorithm> #include <cstdio> using namespace std; int N, C; /…
POJ 1064 题意 有N条绳子,它们长度分别为Li.如果从它们中切割出K条长度相同的绳子的话,这K条绳子每条最长能有多长?答案保留小数点后2位. 思路 二分搜索.这里要注意精度问题,代码中有详细说明:还有printf的%.2f会四舍五入的,需要*100再取整以截取小数点后两位. #include<stdio.h> #include<string.h> #include<string> #include<iostream> #include<math…
题目传送门 /* 二分搜索:搜索安排最近牛的距离不小于d */ #include <cstdio> #include <algorithm> #include <cmath> using namespace std; ; const int INF = 0x3f3f3f3f; int x[MAXN]; int n, m; bool check(int d) { ; ; i<=m-; ++i) { ; while (cur <= n && x[…
题目传送门 /* 题意:分成m个集合,使最大的集合值(求和)最小 二分搜索:二分集合大小,判断能否有m个集合. */ #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> using namespace std; ; const int INF = 0x3f3f3f3f; int a[MAXN]; int n, m; bool check(int tot) { ,…
题目传送门 /* 题意:n条绳子问切割k条长度相等的最长长度 二分搜索:搜索长度,判断能否有k条长度相等的绳子 */ #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> using namespace std; ; const int INF = 0x3f3f3f3f; double w[MAXN]; int n, k; int check(double len…
Description In a certain course, you take n tests. If you get ai out of bi questions correct on test i, your cumulative average is defined to be . . Given your test scores and a positive integer k, determine how high you can make your cumulative aver…
Description Farmer John wants to set up a telephone line at his farm. Unfortunately, the phone company is uncooperative, so he needs to pay for some of the cables required to connect his farm to the phone system. There are N ( ≤ N ≤ ,) forlorn teleph…
Description Given a N × N matrix A, whose element × i + j2 - × j + i × j, you are to find the M-th smallest element in the matrix. Input The first line of input is the number of test case. For each test ≤ N ≤ ,) and M( ≤ M ≤ N × N). There is a blank…
传送门 https://www.cnblogs.com/violet-acmer/p/9793209.html 题意: 有 N 天,第 i 天会有 a[ i ] 的花费: 将这 N 天分成 M 份,每份包含 1 天或连续的多天: 每份的花费为包含的天数花费的加和,求最大花费的最小值. 题解: 二分搜索答案. AC代码: #include<iostream> #include<cstdio> using namespace std; ; int N,M; int totMoney;…
Description Farmer 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 ≤ moneyi ≤ 10,000) that he will need to spend each day over the…
Description Inhabitants of the Wonderland have decided to hold a regional programming contest. The Judging Committee has volunteered and has promised to organize the most honest contest ever. It was decided to connect computers for the contestants us…
题意:牛要到河对岸,在与河岸垂直的一条线上,河中有N块石头,给定河岸宽度L,以及每一块石头离牛所在河岸的距离, 现在去掉M块石头,要求去掉M块石头后,剩下的石头之间以及石头与河岸的最小距离的最大值. 首先去理解题意,去除一些石头之后,使得跳跃的最短距离是最大的,这个跳跃的距离一定是一个值而且一定小于总距离,同时我们可以知道的是,如果移除某几块石头,以某一最短距离跳跃都满足的话,小于这个最短距离的话一定都满足,大于这个最短距离便不一定,所以二分搜索的好处在于可以精准地通过之前的判断对下一次的范围进…
题目传送门 /* 二分:搜索距离,判断时距离小于d的石头拿掉 */ #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> using namespace std; typedef long long ll; ; const int INF = 0x3f3f3f3f; ll a[MAXN]; int n, m; bool check(ll d) { ; ; ; i&…
链接:传送门 题意:一个小朋友开生日派对邀请了 F 个朋友,排队上有 N 个 底面半径为 ri ,高度为 1 的派,这 F 个朋友非常不友好,非得"平分"这些派,每个人都不想拿到若干快小派,只想拿到一整块切好的派,当然形状可以不同,但是体积必须相同他们才能友好的玩下去......,现在求每个人能拿到的最大的派的体积是多少. 思路: 1.若N > F + 1 ,则从 N 个派中选出 F + 1 个比较大的,"平分"情况自然是这 F + 1 个最小的派 2.若N…
Telephone Lines Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5696   Accepted: 2071 Description Farmer John wants to set up a telephone line at his farm. Unfortunately, the phone company is uncooperative, so he needs to pay for some of…
题意:有K太挤奶机,C头奶牛,每个挤奶机每天只能为M头奶牛服务,下面给的K+C的矩阵,是形容相互之间的距离,求出来走最远的那头奶牛要走多远 分析:应该先使用floyd求出来点之间的最短路??(不晓得给的图是不是最短路的),二分出来最短的路径.先做做看吧. 注意:分析的没有错误,确实是这么做的,矩阵的前K行是机械到机械和奶牛的距离,后C行是奶牛到机械和奶牛的距离,0代表两点间没有路,应该置为INF,二分的时候R应该值为INF,最短的200是直接距离,有些地方是直接到达不了的.ps:二分匹配确实很快…
Description It 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 make drying faster. But the radiator is small, so it can hold…
Description Farmer John ≤ moneyi ≤ ,) that he will need to spend each day over the next N ( ≤ N ≤ ,) days. FJ wants to create a budget ≤ M ≤ N) fiscal periods called or more consecutive days. Every day is contained in exactly one fajomonth. FJ's goal…
Description Farmer John has built a <= N <= ,) stalls. The stalls are located along a straight line at positions x1,...,xN ( <= xi <= ,,,). His C ( <= C <= N) cows don't like this barn layout and become aggressive towards each other once…
Description Every year the cows hold an ≤ L ≤ ,,,). Along the river between the starting and ending rocks, N ( ≤ N ≤ ,) more rocks appear, each at an integral distance Di < Di < L). To play the game, each cow in turn starts at the starting rock and…
Description The New Year garland consists of N lamps attached to a common wire that hangs down on the ends to which outermost lamps are affixed. The wire sags under the weight of lamp millimeter lower than the average height of the two adjacent lamps…
Description Farmer John's N (1 <= N <= 50,000) cows (numbered 1..N) are planning to run away and join the circus. Their hoofed feet prevent them from tightrope walking and swinging from the trapeze (and their last attempt at firing a cow out of a ca…
Description Demy has n jewels. Each of her jewels has some value vi and weight wi. Since her husband John got broke after recent financial crises, Demy has decided to sell some jewels. She has decided that she would keep k best jewels for herself. Sh…
传送门 https://www.cnblogs.com/violet-acmer/p/9793209.html 题意: 有 N 块岩石,从中去掉任意 M 块后,求相邻两块岩石最小距离最大是多少? 题解: 二分答案(假设答案为res) 定义 l = 0 , r = L ; mid = (l+r)/2 ; 判断当前答案 mid 至少需要去除多少块岩石,如果去除的岩石个数 > M,说明当前答案mid > res,r=mid;反之,说明当前答案 mid <= res , l =mid; AC代码…