按tutorial打的我血崩,死活挂第四组- -

思路来自FXXL

/*
CodeForces 837F - Prefix Sums [ 二分,组合数 ] | Educational Codeforces Round 26
题意:
设定数组 y = f(x) 使得 y[i] = sum(x[j]) (0 <= j < i)
求初始数组 A0 经过多少次 f(x) 后 会有一个元素 大于 k
分析:
考虑 A0 = {1, 0, 0, 0}
A1 = {1, 1, 1, 1} -> {C(0,0), C(1,0), C(2,0), C(3,0)}
A2 = {1, 2, 3, 4} -> {C(1,1), C(2,1), C(3,1), C(4,1)}
A3 = {1, 3, 6,10} -> {C(2,2), C(3,2), C(4,2), C(5,2)}
A4 = {1, 4,10,20} -> {C(3,3), C(4,3), C(5,3), C(6,3)}
可知任意某个元素的贡献次数可以用组合数来表示,然后二分判定
注意多个剪枝
*/
#include <bits/stdc++.h>
using namespace std;
#define LL long long
const int N = 200005;
LL k, n;
LL a[N];
bool check(LL t)
{
double sum = 0, s;
LL p, q;
for (LL i = 0; i < n; i++)
{
if (a[i] == 0) continue;
q = n-1-i + t-1;
p = t-1;
p = min(p, q-p);
s = a[i];
while(p)
{
s = s*q/p;
p--, q--;
if (s >= k) return 1;
}
sum += s;
if (sum >= k) return 1;
}
return 0;
}
LL BinaryFind(LL l, LL r)
{
LL mid;
while (l <= r) {
mid = (l+r)>>1;
if (check(mid)) r = mid-1;
else l = mid+1;
}
return l;
}
int main()
{
scanf("%lld%lld", &n, &k);
for (int i = 0; i < n; i++)
{
scanf("%lld", &a[i]);
if (a[i] >= k) {
puts("0"); return 0;
}
}
printf("%lld\n", BinaryFind(1, k));
}

  

CodeForces 837F - Prefix Sums | Educational Codeforces Round 26的更多相关文章

  1. Codeforces 837F Prefix Sums

    Prefix Sums 在 n >= 4时候直接暴力. n <= 4的时候二分加矩阵快速幂去check #include<bits/stdc++.h> #define LL l ...

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

  3. Educational Codeforces Round 26

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

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

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

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

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

  6. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...

  7. Educational Codeforces Round 60 (Rated for Div. 2) 题解

    Educational Codeforces Round 60 (Rated for Div. 2) 题目链接:https://codeforces.com/contest/1117 A. Best ...

  8. [Educational Codeforces Round 81 (Rated for Div. 2)]E. Permutation Separation(线段树,思维,前缀和)

    [Educational Codeforces Round 81 (Rated for Div. 2)]E. Permutation Separation(线段树,思维,前缀和) E. Permuta ...

  9. Educational Codeforces Round 30

    Educational Codeforces Round 30  A. Chores 把最大的换掉 view code #pragma GCC optimize("O3") #pr ...

随机推荐

  1. libtool

    [从网上摘录的,忘了从哪摘的了]   libtool常见于autoconf/automake,单独用的例子很少,所以我想仔细研究一下,为将来兄弟们看起来方便. 一.libtool的作用offer a ...

  2. nginx文件服务器搭建

    一.安装 (CentOS 7) yum install nginx -y 如果报错: [u3@L3 /]$ sudo yum install nginx -y Loaded plugins: fast ...

  3. 你除了在客户端上会使用Cookie,还能使用哪些可以作为数据缓存呢?

    问题如标题,直奔主题.介绍下另两种缓存. 1.sessionStorage.localStorage localStorage: 是一种你不主动清除它,它会一直将存储数据存储在客户端的存储方式,即使你 ...

  4. NIT校赛-- 雷顿女士与分队

    题意:https://ac.nowcoder.com/acm/contest/2995/D 思路: 和最大子串很像,dp[i]=max(dp[i-1]+a[i],a[i]),要不和前面连一起,要不就是 ...

  5. ~ android与ios的区别

    Oracle与Mysql的区别 项目类别 android ios 应用上 可以使用常用的android模拟器,来模拟各种android设备 只能直接使用iphone或ipad进行测试 开发语言 基于L ...

  6. Python 基础(十六)--随机数模块

    random随机数模块 random.randint(1,10):随机1-10包括10 random.randrange(1,10,2):在1.3.5.7.9中随机,类似切片,不包括10 random ...

  7. S02_CH15_ AXI_OLED 实验

    S02_CH15_ AXI_OLED 实验 在上一个例子中,主要是以软件功能为主,采用了软件模拟SPI时序进行控制OLED.这样做的好处是灵活,但是牺牲了效率.本章采用的方式是让SPI驱动由Veril ...

  8. 【IntelliJ IDEA】添加一个新的tomcat,tomcat启动无法访问欢迎页面,空白页,404

    ===================================第一部分,添加一个tomcat================================================== ...

  9. linux下mysql数据导入到redis

    自Redis 2.6以上版本起,Redis支持快速大批量导入数据,即Pipe传输.通过将要导入的命令转换为Resp格式,然后通过MySQL的concat()来整理出最终导入的命令集合,以达到快速导入的 ...

  10. BIOS将MBR读入0x7C00地址处(x86平台下)

    BIOS将MBR读入0x7C00地址处(x86平台下) https://www.cnblogs.com/jikebiancheng/p/6193953.html http://www.ruanyife ...