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 ...
随机推荐
- HanLP-基于HMM-Viterbi的人名识别原理介绍
Hanlp自然语言处理包中的基于HMM-Viterbi处理人名识别的内容大概在年初的有分享过这类的文章,时间稍微久了一点,有点忘记了.看了 baiziyu 分享的这篇比我之前分享的要简单明了的多.下面 ...
- PHP的四种运行方式
一丶cgi协议模式 cgi模式通用网关接口(Common Gateway Interface),它允许web服务器通过特定的协议与应用程序通信,调用原理大概为:用户请求->Web服务器接收请求- ...
- lxml and 代理ip
pip install lxml 导包From lxml import etree 1. 注意这个是本地html就直接使用etree.parse即可 2. html_etree=etree.parse ...
- 关于@service、@controller和@transactional 在spring中的位置说明
Spring容器优先加载由ServletContextListener(对应applicationContext.xml)产生的父容器,而SpringMVC(对应mvc_dispatcher_serv ...
- 论文阅读:《Bag of Tricks for Efficient Text Classification》
论文阅读:<Bag of Tricks for Efficient Text Classification> 2018-04-25 11:22:29 卓寿杰_SoulJoy 阅读数 954 ...
- 怎样查看或修改元素节点的id属性
使用 el.id; el表示获取到的元素节点, 如下所示: // HTML 代码 // <div id="app" class="c1">hello ...
- vue 通过 name 和 params 进行调整页面传参刷新参数丢失问题&vue路由可选参数
vue 通过 name 和 params 进行调整页面传参刷新参数丢失问题 router.js: export default new Router({ routes: [ { path: '/', ...
- BMP RGB888转RGB565 +上下翻转+缩放
典型的BMP图像文件由四部分组成: (1) 位图头文件数据结构,它包含BMP图像文件的类型.文件大小和位图起始位置等信息: typedef struct tagBITMAPFILEHEADER { ...
- gzip: stdin: not in gzip format 解决办法
# sudo tar zxvf ./jdk-7ull-linux-i586.tar.gz -C /usr/lib/jvm gzip: stdin: not in gzip format tar: Ch ...
- 搞懂String、StringBuffer、StringBuilder的区别
String.StringBuffer.StringBuilder有什么区别呢? 1.String: 首先String是不可变的这是家喻户晓的,它的底层是用一个final修饰的char数组来保存数据的 ...