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) ((int)x.size())
#define ull unsigned long long using namespace std; const int N = + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;
const double PI = acos(-); LL n, k, a[N], b[], tar, tot; int main() {
scanf("%lld%lld", &n, &k);
for(int i = ; i <= n; i++) {
scanf("%lld", &a[i]);
tar += a[i];
a[i]--;
}
tar += k;
for(int i = ; i <= n; i++) {
for(int j = , k; j < a[i]; j = k + ) {
k = a[i] / (a[i] / j);
b[tot++] = j;
}
b[tot++] = a[i] + ;
}
sort(b, b + tot);
tot = unique(b, b + tot) - b;
for(int i = tot - ; i >= ; i--) {
LL d = b[i], val = ;
for(int i = ; i <= n; i++)
val += d * (a[i] / d);
if(n * d + val <= tar) {
val = ;
for(int i = ; i <= n; i++) val += a[i] / d;
printf("%lld\n", tar / (val + n));
return ;
}
}
return ;
} /*
*/
上一篇:2018.12.15 poj3415 Common Substrings(后缀自动机)


下一篇:Spark机器学习(3):保序回归算法