CodeForces 837F - Prefix Sums | Educational Codeforces Round 26
按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的更多相关文章
- Codeforces 837F Prefix Sums
Prefix Sums 在 n >= 4时候直接暴力. n <= 4的时候二分加矩阵快速幂去check #include<bits/stdc++.h> #define LL l ...
- 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 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( ...
- CodeForces 837D - Round Subset | Educational Codeforces Round 26
/* CodeForces 837D - Round Subset [ DP ] | Educational Codeforces Round 26 题意: 选k个数相乘让末尾0最多 分析: 第i个数 ...
- 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 ...
- Educational Codeforces Round 60 (Rated for Div. 2) 题解
Educational Codeforces Round 60 (Rated for Div. 2) 题目链接:https://codeforces.com/contest/1117 A. Best ...
- [Educational Codeforces Round 81 (Rated for Div. 2)]E. Permutation Separation(线段树,思维,前缀和)
[Educational Codeforces Round 81 (Rated for Div. 2)]E. Permutation Separation(线段树,思维,前缀和) E. Permuta ...
- Educational Codeforces Round 30
Educational Codeforces Round 30 A. Chores 把最大的换掉 view code #pragma GCC optimize("O3") #pr ...
随机推荐
- LeetCode 第 15 场双周赛
1287.有序数组中出现次数超过25%的元素 1288.删除被覆盖区间 1286.字母组合迭代器 1289.下降路径最小和 II 下降和不能只保留原数组中最小的两个,hacked. 1287.有序数组 ...
- 聊聊BIO、NIO与AIO的区别
题目:说一下BIO/AIO/NIO 有什么区别?及异步模式的用途和意义? 1F 说一说I/O首先来说一下什么是I/O? 在计算机系统中I/O就是输入(Input)和输出(Output)的意思,针对不同 ...
- Java静态代理与动态代理实现
一.什么是代理 代理是一种设计模式,它提供了一种通过代理访问目标对象的方式.在应用代理之前,我们调用对象的过程如下: 客户端直接调用对象并获取返回值.而应用了代理之后,我们调用对象的过程变成如下: 客 ...
- Iedis - Redis 在IDEA中的可视化工具破解
2.如何破解 // 如果你没有改动IDEA的话,IDEA的插件库在这个目录下C:\Users\Administrator\.IntelliJIdea2017.3\config\plugins\Iedi ...
- hdu 6140 思维
题解:这道题中的数能组成的数构成了一个连续区间. 一开始只有 a1 的时候能够构成 [-1, 1][−1,1] 中的所有整数. 如果一堆数能够构成 [-a, b][−a,b] 中的所有整数, 这时 ...
- JS 编程艺术
JS艺术片段剪贴 getFullDate: function (date) { //返回 YYYY年MM月DD日 var year = month = day = ' '; if (isNaN(dat ...
- PHP 手机短信发送验证码
点击链接加入群[php/web 学习课堂]:https://jq.qq.com/?_wv=1027&k=5645xiw 欢迎大家加入,一起讨论学习 本篇设计的知识点有点多,我会分类将,同学们可 ...
- WinPE基础知识之导入表
// 导入表 (结构体数组,以一个全零元素为结尾,每一个数组元素,代表一个PE文件导入信息) // 导入表存储的是从其它PE文件导入过来的函数名.序号,加载到内存之后,还存储这些函数的地址 typed ...
- 转载:Web安全X-FRAME-OPTIONS 出现两个或多个的原因
转载:https://blog.csdn.net/Teemo_2016/article/details/82051523 在配置文件中配置了 <httpProtocol> < ...
- DX使用随笔--NavBarControl
1. Item图标大小显示 需要先设置此Item所在Group的属性GroupStyle的值为LargeImageText.