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 ...
随机推荐
- System memory 259522560 must be at least 4.718592
[学习笔记] /*没有下面的话, 会报一个错误,java.lang.IllegalArgumentException: System memory 259522560 must be at least ...
- 什么是DataV数据可视化
DataV数据可视化是使用可视化大屏的方式来分析并展示庞杂数据的产品.DataV旨让更多的人看到数据可视化的魅力,帮助非专业的工程师通过图形化的界面轻松搭建专业水准的可视化应用,满足您会议展览.业务监 ...
- QT 线程的使用(继承QThread)
对于多线程而言,要注意资源的同步和互斥问题,但对于单独的一个线程,则只需要对它的run方法进行重写. 下面实现了一个简单的线程 widget.h文件 #ifndef WIDGET_H #define ...
- operator模块和functools模块
operator模块 在函数式编程中,经常需要把算术运算符当作函数使用.例如,不使用 递归计算阶乘.求和可以使用 sum 函数,但是求积则没有这样的函数. 我们可以使用 reduce 函数(5.2.1 ...
- 【USB】struct usb_device_id 结构体详解
struct usb_device_id { /* which fields to match against? */ __u16 match_flags; //说明使用哪种匹配方式 /* Used ...
- QAbstractItemModel使用样例与解析(Model::index使用了createIndex,它会被销毁吗?被销毁了,因为栈对象出了括号就会被销毁)
参考:qt源码 qstandarditemmodel_p.h qstandarditemmodel.h qstandarditemmodel.cpp qabstractitemmodel.h qabs ...
- C# list to dictionary
示例: 新建一个类: public class Lang { public string En; public string Ch; } 实例化并转为字典: List<Lang> lang ...
- ReactNative 踩坑笔记
1.fatal error: 'React/RCTBridgeDelegate.h' file not found 这个问题是应为没有安装cocoaPods 所以无法安装ios需要的第三方库.安装co ...
- JavaWeb-用过滤器修改请求的返回状态码
问题: 客户SDK对接服务,默认只识别200和非200的请求状态码.需要修改当前应用的状态码(如将201转为200) 解决方案:通过扩展HttpServletResponseWrapper,获取到每个 ...
- Spring的启动流程
spring的启动是建筑在servlet容器之上的,所有web工程的初始位置就是web.xml,它配置了servlet的上下文(context)和监听器(Listener),下面就来看看web.xml ...