CF Round #730 (CF1543)
CF Round #730 (Div.2)
A:
给\(a,b\),求\(max\{gcd(a+t, b+t)\}(t \in Z)\)和取得此\(max\)值的\(|t|_{min}\)。当\(max = \infty\)时输出"0 0"。
if (a == b) cout<<"0 0"<<endl;
else
{
int g = max(a, b)-min(a, b);
cout<<g<<' ';
int m = a%g;
cout<<min(g-m, m)<<endl;
}
B:
数组和不变,求\(min\{\sum\limits_{i=1}^n\sum\limits_{j=i+1}^n|a_i-a_j|\}\)。
int m = sum%n;
cout<<m*(n-m)<<endl;
C:
描述不出来,去看原题吧(
思路:一个裸dfs,注意精度
void dfs(double fac, int e)
{
double ans = 0, cc = c, mm = m, pp = p;
if (c > eps)
{
if ((c-v) < eps)
{
if (m < eps) p += c;
else m += cc/2.0, p += cc/2.0;
c = -inf;
dfs(fac*cc, e+1);
c = cc; m = mm; p = pp;
}
else
{
c -= v;
if (m < eps) p += v;
else p += v/2.0, m += v/2.0;
dfs(fac*cc, e+1);
c = cc; m = mm; p = pp;
}
}
if (m > eps)
{
if ((m-v) < eps)
{
if (c < eps) p += m;
else c += mm/2.0, p += mm/2.0;
m = -inf;
dfs(fac*mm, e+1);
c = cc; m = mm; p = pp;
}
else
{
m -= v;
if (c < eps) p += v;
else c += v/2.0, p += v/2.0;
dfs(fac*mm, e+1);
c = cc; m = mm; p = pp;
}
}
res += fac*p*e;
}
int T = next();
while(T--)
{
res = 0;
cin>>c>>m>>p>>v;
dfs(1.0, 1);
printf("%.12llf\n", res);
}
D1:
H2O·Au,看错范围( [0, n) -> [1, n) )了。。。。。。。。。。。。。。。。。
int mask = 0;
rep(i, 0, n)
{
if (query(i^mask)) break;
mask ^= (i^mask);
}
\(\color{red}{困了,就先这样吧,没有fst}\)