ACM_二分法
文章平均质量分 52
深海沧澜夜未央
这个作者很懒,什么都没留下…
展开
-
HDU 1969 高精度
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 various sizes. F of my friends are coming to my party and each原创 2017-02-06 22:22:38 · 450 阅读 · 0 评论 -
Codeforces Round #307 (Div. 2) C. GukiZ hates Boxes 二分
Professor GukiZ is concerned about making his way to school, because massive piles of boxes are blocking his way.In total there are n piles of boxes, arranged in a line, from left to right, i-th pile ...原创 2018-04-24 09:02:57 · 176 阅读 · 0 评论 -
二分法 总结
1、二分查找(BinarySearch) 二分查找又称折半查找,它是一种效率较高的查找方法。 二分查找要求:线性表是有序表,即表中结点按关键字有序,并且要用向量作为表的存储结构。不妨设有序表是递增有序的。2、二分查找的基本思想 二分查找的基本思想是:(设R[low..high]是当前的查找区间) (1)首先确定该区间的中点位置:转载 2017-02-05 11:07:57 · 567 阅读 · 0 评论 -
HDU 1025 最长不下降子序列nlogn算法
题意:最长不下降子序列思路:n*n的算法肯定超时,所以nlogn的写法(dp+二分)dp数组存的是当前最长的最长不下降子序列,数组内保证递增,因此可以二分找下一个数字需要插入的位置注意输出格式,road和roads区别,还有要输出两个换行#include #include #include #include using namespace std;#define N 5001原创 2017-12-26 15:46:28 · 345 阅读 · 0 评论 -
HDU 4004 The Frog's Games (二分 + 贪心 青蛙跳石头)
题意:河长L,n个石头,青蛙最多跳m次,给出n个石头在数轴上的位置,求出青蛙通过石头可以跳过河的最小跳跃能力(跳跃距离)。思路:二分石头间的距离。#include #include #include #include #include #include #include using namespace std;typedef long long ll;int str[50原创 2017-12-24 09:43:56 · 948 阅读 · 0 评论 -
POJ 3579 Median(2次二分)
Given N numbers, X1,X2, ... , XN, let us calculate the difference of every pair of numbers: ∣Xi- Xj∣ (1 ≤ i < j ≤ N). We can get C(N,2) differences through this work, and now your task is to fin原创 2017-02-08 13:25:05 · 434 阅读 · 0 评论 -
HDU 4282 A very hard mathematic problem (涉及3个数字 用 枚举+二分)
Problem Description Haoren is very good at solving mathematic problems. Today he is working a problem like this: Find three positive integers X, Y and Z (X 1) that holds X^Z + Y^Z +原创 2017-01-31 11:24:10 · 446 阅读 · 0 评论 -
POJ 2456 Aggressive cows(二分+贪心 计算个数)
Farmer 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 C (2 <= C <= N) cows原创 2017-02-05 16:40:42 · 373 阅读 · 0 评论 -
HDU 2199 Can you solve this equation(二分水题)
Problem DescriptionNow,given the equation 8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y,can you find its solution between 0 and 100;Now please try your lucky. InputThe first line of the inp原创 2017-01-18 10:55:11 · 341 阅读 · 0 评论 -
POJ - 1064 Cable master(二分+贪心 计算个数)
题意:给出n,m,给出n个电缆,求出满足电缆分割后满足m个的电缆的最大长度思路:二分分割后的电缆长度,二分时 计算出在当前分割电缆长度下可以有多少个电缆include #include #include #include #include #include #include using namespace std;typedef long long ll;int n,k;原创 2017-12-24 09:27:16 · 242 阅读 · 0 评论 -
POJ - 3122 Pie (二分+贪心 计算个数)
题意:给出n个朋友,m个苹果派,再给出m个苹果派的半径,求出可以分给n个朋友一摸一样的苹果派的最大面积(不可以拼凑,只可以是一整块)。思路:贪心+二分#include #include #include #include #include #include #include using namespace std;#define pi acos(-1.0)#define原创 2017-12-24 09:37:14 · 282 阅读 · 0 评论 -
HDU - 2511 汉诺塔 X
1,2,...,n表示n个盘子.数字大盘子就大.n个盘子放在第1根柱子上.大盘不能放在小盘上.在第1根柱子上的盘子是a[1],a[2],...,a[n]. a[1]=n,a[2]=n-1,...,a[n]=1.即a[1]是最下面的盘子.把n个盘子移动到第3根柱子.每次只能移动1个盘子,且大盘不能放在小盘上.问第m次移动的是哪一个盘子,从哪根柱子移到哪根柱子.例如:n=3,m=2. 回答是 :2 1原创 2017-12-24 09:17:14 · 537 阅读 · 0 评论 -
ADA Ⅱ型数 (二分模板)
题目描述 ADA Ⅱ型数是指能表达成p^2与q^3两者之乘积的整数,p和q均大于1且不相等。72=2^3*3^2, 是最小的ADA Ⅱ型数。给定一个整数n,判定其是否为ADA Ⅱ型数。输入少于4000行数据组成,每行一个整数n(0<n<2^31)。输出 每个整数n对应一行输出,如果是ADA Ⅱ型数,则输出一行YES,否则输出一行NO。样例输入172样例输出NOYES思路:是p的2次方*...原创 2017-04-29 16:22:01 · 590 阅读 · 0 评论 -
Coprime (二分+容斥原理)
1014起是容斥部分,同学们可以先不做Coprime Time Limit : 4000/2000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)Total Submission(s) : 24 Accepted Submission(s) : 7Font: Times New Roman | Verdan原创 2017-08-03 18:49:09 · 367 阅读 · 0 评论 -
Building Fences Kattis - fence2
题目链接:https://vjudge.net/contest/173017#problem/G题意:给定k根木棍,和需要分成的份数n,可以无限次切割各个木棍,使得切割而成的n份尽量长,且长度相等,各个木棍剩余的部分不能比它长,求切割的最小次数。思路: 可知关键点在于组成这n份的木棍长度,因为最长的长度确定了,次数也随之确定,所以我们二分切割的长度,贪心处理,每根木棍能切多少切多少,如果是原创 2017-07-25 14:59:10 · 628 阅读 · 0 评论 -
POJ - 2018 Best Cow Fences (二分 连续数的平均和+前缀和)
Farmer John’s farm consists of a long row of N (1 <= N <= 100,000)fields. Each field contains a certain number of cows, 1 <= ncows <= 2000.FJ wants to build a fence around a contiguous g...原创 2018-07-24 10:54:43 · 1095 阅读 · 1 评论