【CF830C】Bamboo Partition 分块

【CF830C】Bamboo Partition

题解:给你n个数a1,a2...an和k,求最大的d使得$\sum\limits_{i=1}^n((d-a[i] \% d) \% d) \le k$

n<=100,a[i]<=10^9,k<=10^11

题解:$\sum\limits_{i=1}^n((d-a[i] \% d) \% d)=d\sum\limits_{i=1}^n{\lceil {a[i]\over d}\rceil }-\sum\limits_{i=1}^na[i]$

显然,${\lceil {a[i]\over d}\rceil}$最多只有n*sqrt(maxd)种取值,那么分块处理即可。但是你会发现,$last=\lceil{a \over {\lceil {a\over i} \rceil}}\rceil$得到的是最小的last使得$\lceil{a\over i}\rceil=\lceil{a\over last} \rceil$,所以倒着做即可。

PS:前几天考试中出了这道题,全场感人的无人AC,有人说这是CFdiv2的F题,感觉莫名其妙~

如果你熟悉如何用正着分块来处理底的和式,那么想到用倒着分块来处理顶的和式也是自然的~

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
int n;
ll m,ans,a[110],k;
ll Div(ll x,ll y)
{
	return (x+y-1)/y;
}
int main()
{
	ll i,last,sum,cnt;
	int j;
	scanf("%d%I64d",&n,&k);
	for(j=1;j<=n;j++)	scanf("%I64d",&a[j]),m=max(m,a[j]+k);
	for(i=m;i;i=last-1)
	{
		for(last=1,j=1;j<=n;j++)	last=max(last,Div(a[j],Div(a[j],i)));
		for(sum=cnt=0,j=1;j<=n;j++)	sum+=(last-a[j]%last)%last,cnt+=Div(a[j],last);
		if(sum<=k)
		{
			printf("%I64d\n",last+(k-sum)/cnt);
			return 0;
		}
	}
	return 0;
}
时间: 2024-12-26 09:01:01

【CF830C】Bamboo Partition 分块的相关文章

Codeforces 830C Bamboo Partition (看题解)

Bamboo Partition 列公式, 整除分块, 想不到, 好菜啊. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PLL pair<LL, LL> #define PLI pair<LL, int> #define PII pair<int, int> #define SZ(x)

Codeforces VK Cup Finals #424 Div.1 C. Bamboo Partition(数论)

题目要求符合以下条件的最大的d 化简得 注意到 最多只有2*sqrt(a[i]-1)种取值,也就是一共最多有n*sqrt(10^19)种取值,于是枚举一下d,计算出符合上上式的最大的d更新答案,然后d跳跃到下一个取值 效率O(n²sqrt(10^9)) #include<bits/stdc++.h> #define ll long long using namespace std; const int maxn=110,inf=1e9; ll n,k,ans,r; ll a[maxn]; vo

Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals)

D题fst了,生无可恋.第二场rated的CF,打得精神恍惚 A. Unimodal Array 题意:判断数列是否是单峰的. 像题意那样分为三个阶段随便判一判就好了 #include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> using namespace std; int n,x[105],part=1; bool f=1; int main() { scanf(&quo

cf 424

Office Keys 首先显然有随人位置的递增,钥匙的位置也要递增,这样考虑两张做法: 1.$f(i,j)$ 表示前i个人,钥匙到第j个最少用的最大时间,然后$O(nK)$ dp 2.二分时间,对于每一个人选择当前能选择的最左面的钥匙 $O((n+K) logn)$ #include <bits/stdc++.h> #define LL long long const int N = 2010; using namespace std; int n,m,pre[N],a[N],b[N]; i

【转】基于内容可变长度分块(CDC)

基于内容可变长度分块 1,简介重复数据块检测技术分为,固定分块检测技术(Fixed-Sized Partition, FSP),可变分块检测技术(Variable-Sized Partition, VSP),滑动块技术(Sliding Block).固定分块将数据流按固定的长度分块,实现很简单,但某一处数据的变化将导致之后的所有分块都发生变化,从而无法进行匹配.因此,固定分块技术在实际中应用较少.可变分块技术则可弥补固定分块技术的这一局限性,能更加灵活的找出重复数据.基于内容可变长度分块(Con

[LeetCode]Partition List

题目描述:(链接) Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve the original relative order of the nodes in each of the two partitions. For example,Given 1->4

doesn&#39;t contain a valid partition table 解决方法

输入 fdisk -l 可以看到 输入 fdisk /dev/xvdb 跟着向导一步步做下去(如果不知道该输入什么,就输入“m”并回车,可以打印出菜单): Command (m for help): m Command action a   toggle a bootable flag b   edit bsd disklabel c   toggle the dos compatibility flag d   delete a partition l   list known partiti

LeetCode --- 86. Partition List

题目链接:Partition List Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve the original relative order of the nodes in each of the two partitions. For example,

Leetcode:Partition List 链表快速排序划分

Partition List Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve the original relative order of the nodes in each of the two partitions. For example,Given