Educational Codeforces Round 26 F. Prefix Sums 二分,组合数
题目链接:http://codeforces.com/contest/837/problem/F
题意:如题QAQ
解法:参考题解博客:http://www.cnblogs.com/FxxL/p/7282909.html
由于新生成的m+1个数列第一个肯定为0,所以可以忽略掉,当作每次新生成的数列只拥有m个元素
来枚举一个例子,可以发现规律。
当a[] = {1,0,0,0,0}时,手动推出的矩阵如下:

可以发现对于这个矩阵显然是满足杨辉三角的,我们二分出一个值后可以直接利用组合数来计算出当前的答案,然后check
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
typedef long long LL;
LL n,k,a[maxn]; bool check(LL mid){
double sum=0;
LL x,y,p,q;
for(LL t=0; t<n; t++){
if(a[t]==0) continue;
x=mid; y=(n-1)-t;
p=x-1; q=p+y;
p = min(q-p, p);
double tmp = a[t];
for(LL i=q, j=p; j>=1; j--,i--){
tmp = tmp*i/j;
if(tmp>=k) return true;
}
sum += tmp;
if(sum>=k) return true;
}
return false;
}
int main()
{
cin>>n>>k;
for(int i=0; i<n; i++){
cin>>a[i];
if(a[i]>=k){
printf("0\n");
return 0;
}
}
LL l=0,r=k,ans;
while(l<=r){
LL mid=(l+r)/2;
if(check(mid)) ans=mid,r=mid-1;
else l=mid+1;
}
bool ok = check(2);
if(ans==0) ans++;
cout<<ans<<endl;
return 0;
}
Educational Codeforces Round 26 F. Prefix Sums 二分,组合数的更多相关文章
- CodeForces 837F - Prefix Sums | Educational Codeforces Round 26
按tutorial打的我血崩,死活挂第四组- - 思路来自FXXL /* CodeForces 837F - Prefix Sums [ 二分,组合数 ] | Educational Codeforc ...
- Educational Codeforces Round 26
Educational Codeforces Round 26 困到不行的场,等着中午显示器到了就可以美滋滋了 A. Text Volume time limit per test 1 second ...
- CodeForces - 837E - Vasya's Function | Educational Codeforces Round 26
/* CodeForces - 837E - Vasya's Function [ 数论 ] | Educational Codeforces Round 26 题意: f(a, 0) = 0; f( ...
- Educational Codeforces Round 40 F. Runner's Problem
Educational Codeforces Round 40 F. Runner's Problem 题意: 给一个$ 3 * m \(的矩阵,问从\)(2,1)$ 出发 走到 \((2,m)\) ...
- CodeForces 837D - Round Subset | Educational Codeforces Round 26
/* CodeForces 837D - Round Subset [ DP ] | Educational Codeforces Round 26 题意: 选k个数相乘让末尾0最多 分析: 第i个数 ...
- Educational Codeforces Round 26 [ D. Round Subset ] [ E. Vasya's Function ] [ F. Prefix Sums ]
PROBLEM D - Round Subset 题 OvO http://codeforces.com/contest/837/problem/D 837D 解 DP, dp[i][j]代表已经选择 ...
- Educational Codeforces Round 21 D.Array Division(二分)
D. Array Division time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...
- Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process 题目连接: http://www.codeforces.com/contest/660/problem/C Description You are given an a ...
- Educational Codeforces Round 61 F 思维 + 区间dp
https://codeforces.com/contest/1132/problem/F 思维 + 区间dp 题意 给一个长度为n的字符串(<=500),每次选择消去字符,连续相同的字符可以同 ...
随机推荐
- 【bzoj1614】[Usaco2007 Jan]Telephone Lines架设电话线 二分+SPFA
题目描述 Farmer John打算将电话线引到自己的农场,但电信公司并不打算为他提供免费服务.于是,FJ必须为此向电信公司支付一定的费用. FJ的农场周围分布着N(1 <= N <= 1 ...
- BZOJ5157 & 洛谷3970:[TJOI2014]上升子序列——题解
https://www.lydsy.com/JudgeOnline/problem.php?id=5157 https://www.luogu.org/problemnew/show/P3970 给定 ...
- BZOJ1031:[JSOI2007]字符加密——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=1031 喜欢钻研问题的JS同学,最近又迷上了对加密方法的思考.一天,他突然想出了一种他认为是终极的加密 ...
- Codeforces 854C Planning(贪心+堆)
贪心:让代价大的尽量移到靠前的位置. 做法:先让前k个数加进堆里,枚举k+1~n+k,每次把新元素加进堆后找到最大代价放在当前位置即可. #include<bits/stdc++.h> # ...
- NOIP系列
NOIP2015运输计划 唉 真是 这题 卡死我了 tarjan离线lca复杂度O(n) 最后各种卡常,多交几遍才A(洛谷104ms) %%%zk学长609ms 注意二分的时候左边界要定成0 根据题意 ...
- foo.prototype作为新对象的原型来使用
最近在研究js,疑惑也比较多.主要是被原型这个东西给弄迷糊了.疑惑出自于: function foo { this.name = 'foo'; } alert(foo.prototype === Fu ...
- 常州模拟赛d7t3 水管
分析:第一问还是很好做的,关键是怎么做第二问.我们可以每次删掉最小生成树上的一条边,然后再求一次最小生成树,看边权和大小和原来的是不是一样的,不过这个做法效率很低. 考虑Kruskal算法的原理,每次 ...
- 2017 济南综合班 Day 2
木棍(stick) Time Limit:1000ms Memory Limit:128MB 题目描述 LYK有很多木棍,具体的,总共有n根,且每根木棍都有一个长度.为了方便起见,我们可以用一个正 ...
- [Luogu 4092] HEOI/TJOI2016 树
[Luogu 4092] HEOI/TJOI2016 树 搜了树剖标签不知道怎么就跳出了个暴搜题啊! 管他既然做了就发上来吧- 有修改标签就向下搜并修改,遇到标签即停止. 这题是真的真的短. #inc ...
- No cached version of ..... available for offline mode.
I had same error...Please Uncheck the offline work in Settings. File => Settings => Build, Exe ...