二分
KEIke0
这个作者很懒,什么都没留下…
展开
-
Median POJ 3579
给你n个数,把这n个数互相相减的结果变成一个新数组(一定是大的减小的,结果可以重复,一定是正数),求这个新数组的中位数是多少。 因为是中位数,不是平均数或者中位数什么的,所以他的位置一定是数组正中的那个数字。而这个数组相减的结果应该是Cn2个,就是n*(n-1)/2。中位数的位置就是n*(n-1)/4。 #include<iostream> #include<algorithm> #include<cstring> using namespace std; co原创 2020-09-18 16:08:09 · 114 阅读 · 0 评论 -
Cow Acrobats POJ 3045
#include<iostream> #include<cstring> #include<cmath> #include<algorithm> using namespace std; const int MAXN=50005; const int INF=0x3f3f3f3f; int n; struct node { int w,s,sum; bool operator<(const node &c)const//.原创 2020-09-15 18:57:30 · 116 阅读 · 0 评论 -
Drying POJ 3104
每件衣服都有一定单位水分,在不使用烘干器的情况下,每件衣服每分钟自然流失1个单位水分,但如果使用了烘干机则每分钟流失K个单位水分,但是遗憾是只有1台烘干机,每台烘干机同时只能烘干1件衣服,请问要想烘干N件衣服最少需要多长时间? 输入 多组输入 第一行输入N,表示有N件衣服,第二行输入N件衣服的水分ai,第三行表示烘干机每分钟烘干水分K 其中 1 ≤ N ≤ 100 000,1 ≤ ai ≤ 10^9,1 ≤ K≤ 10^9输出 输出 烘干N件衣服所需要的最短时间 要注意的是,当你拿起一件..原创 2020-09-14 23:10:39 · 213 阅读 · 0 评论 -
Monthly Expense POJ 3273
一个用二分写的一个穷举法,给你一个n,m问你下面的n个数中分成m个区间,使每个区间的和尽量小,然后求这m个区间中最大的那个区间的和是多少 #include<iostream> #include<algorithm> using namespace std; const int MAXN=100050; int cnt; int n,m; int l,r,mid; int a[MAXN]; int flag(){ mid=(l+r)/2; int sum=0; in原创 2020-09-13 22:38:42 · 111 阅读 · 0 评论 -
Subsequence POJ 3061
尺取或者二分 给你n个数,问你这个数列里面加起来大于等于s的最短长度是多少 二分 #include<iostream> #include<algorithm> #include<cstring> using namespace std; int a[100500]; long long sum[100500]; int main() { int ...原创 2020-01-12 10:33:42 · 103 阅读 · 0 评论 -
Aggressive cows POJ 2456
有n个牛棚,m头牛,由于这些牛放一起会起冲突,所以要使每头牛之间的距离尽可能远,n行数据代表每个牛棚所在的距离(类似于x轴的x点)。问他们之中隔开的最大距离是多少 #include<iostream> #include<algorithm> #include<cstring> #include<cstdio> using namespace s...原创 2020-01-09 14:08:20 · 132 阅读 · 0 评论 -
Cable master POJ 1064
给你n条绳子,把这些绳子切割成k段相同的长度。问你能切割的最大长度是多少。保留小数点后两位并且记住要进位。 用二分写。 #include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #define MAX 11000 #define INF 100000000 ...原创 2020-01-09 13:18:47 · 133 阅读 · 0 评论