题目链接: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 二分,组合数的更多相关文章

  1. CodeForces 837F - Prefix Sums | Educational Codeforces Round 26

    按tutorial打的我血崩,死活挂第四组- - 思路来自FXXL /* CodeForces 837F - Prefix Sums [ 二分,组合数 ] | Educational Codeforc ...

  2. Educational Codeforces Round 26

    Educational Codeforces Round 26 困到不行的场,等着中午显示器到了就可以美滋滋了 A. Text Volume time limit per test 1 second ...

  3. CodeForces - 837E - Vasya's Function | Educational Codeforces Round 26

    /* CodeForces - 837E - Vasya's Function [ 数论 ] | Educational Codeforces Round 26 题意: f(a, 0) = 0; f( ...

  4. Educational Codeforces Round 40 F. Runner's Problem

    Educational Codeforces Round 40 F. Runner's Problem 题意: 给一个$ 3 * m \(的矩阵,问从\)(2,1)$ 出发 走到 \((2,m)\) ...

  5. CodeForces 837D - Round Subset | Educational Codeforces Round 26

    /* CodeForces 837D - Round Subset [ DP ] | Educational Codeforces Round 26 题意: 选k个数相乘让末尾0最多 分析: 第i个数 ...

  6. 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]代表已经选择 ...

  7. 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 ...

  8. Educational Codeforces Round 11 C. Hard Process 二分

    C. Hard Process 题目连接: http://www.codeforces.com/contest/660/problem/C Description You are given an a ...

  9. Educational Codeforces Round 61 F 思维 + 区间dp

    https://codeforces.com/contest/1132/problem/F 思维 + 区间dp 题意 给一个长度为n的字符串(<=500),每次选择消去字符,连续相同的字符可以同 ...

随机推荐

  1. 【bzoj2938】[Poi2000]病毒 AC自动机

    题目描述 二进制病毒审查委员会最近发现了如下的规律:某些确定的二进制串是病毒的代码.如果某段代码中不存在任何一段病毒代码,那么我们就称这段代码是安全的.现在委员会已经找出了所有的病毒代码段,试问,是否 ...

  2. BZOJ4241 历史研究(莫队)

    如果分块的话与区间众数没有本质区别.这里考虑莫队. 显然莫队时的删除可以用堆维护,但多了一个log不太跑得过. 有一种叫回滚莫队的trick,可以将问题变为只有加入操作.按莫队时分的块依次处理,一块中 ...

  3. BZOJ2151 种树(贪心+堆+链表/wqs二分+动态规划)

    dp容易想到,但没法进一步优化了. 考虑贪心,每次选出价值最大的物品.但这显然是不对的因为会影响其他物品的选择. 于是考虑加上反悔操作.每次选出一个物品后,将其相邻两物品删除,再将原物品价值变为相邻两 ...

  4. hdu 3191 How Many Paths Are There (次短路径数)

    How Many Paths Are There Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java ...

  5. Django+haystack实现全文搜索出现错误 ImportError: cannot import name signals

    原因是在你的settings.py或者其他地方使用了  "import haystack" 当我们使用django-haysatck库时,表面上会有haystack库,但实际上并不 ...

  6. Python文件传输模块ftplib

    ftplib是基于FTP协议实现的一个Python模块 from ftplib import FTP # 创建一个FTP连接对象 ftp = FTP() #[ 当带有参数时,即:ftp = FTP(h ...

  7. python中深copy,浅copy

    版权声明:本文为博主原创文章,未经博主允许不得转载. >>> mylist1 = [1, 2, 3, 4] >>> myl = mylist1 >>&g ...

  8. 【SPOJ - GSS2】Can you answer these queries II(线段树)

    区间连续不重复子段最大值,要维护历史的最大值和当前的最大值,打两个lazy,离线 #include<cstdio> #include<cstring> #include< ...

  9. [NOIP2010] 引水入城 贪心 + 记忆化搜索

    ---题面--- 题解: 本蒟蒻并没有想到bfs的做法,,,, 只会dfs了 首先我们需要知道一个性质. 我们设k[i].l 为在i点建立水库可以支援到的最左边的城市,k[i].r为最右边的. 那么点 ...

  10. 探索CAS无锁技术

    前言:关于同步,很多人都知道synchronized,Reentrantlock等加锁技术,这种方式也很好理解,是在线程访问的临界区资源上建立一个阻塞机制,需要线程等待 其它线程释放了锁,它才能运行. ...