bzoj2969矩形粉刷

时间:2022-05-25 06:25:56

题解:

和前面那个序列的几乎一样

容斥之后变成求不覆盖的

然后再像差分的矩形那样

由于是随便取的所以这里不用处理前缀和直接求也可以

代码:

#include <bits/stdc++.h>
using namespace std;
#define rint register ll
#define IL inline
#define ll long long
#define rep(i,h,t) for (rint i=h;i<=t;i++)
#define dep(i,t,h) for (rint i=t;i>=h;i--)
const double ee=1.0000000000000000;
ll n,m,k;
IL double fsp(double x,ll y)
{
double ans=;
while (y)
{
if (y&) ans*=x;
y>>=; x*=x;
}
return(ans);
}
IL ll js(ll x)
{
return(1LL*x*x);
}
IL ll qq(ll x1,ll x2,ll y1,ll y2)
{
if (x1>x2||y1>y2) return();
return(js((x2-x1+)*(y2-y1+)));
}
int main()
{
freopen("1.in","r",stdin);
freopen("1.out","w",stdout);
ios::sync_with_stdio(false);
cin>>k>>n>>m;
ll num=js(n*m);
double ans=;
rep(i,,n)
rep(j,,m)
{
double now=qq(,n,,j-)+qq(,i-,,m)+qq(,n,j+,m)+qq(i+,n,,m);
now-=qq(,i-,,j-)+qq(i+,n,,j-)+qq(,i-,j+,m)+qq(i+,n,j+,m);
now/=num;
now=ee-fsp(now,k);
ans+=now;
}
printf("%.0f",ans);
return ;
}