bzoj2969矩形粉刷

题解:

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

容斥之后变成求不覆盖的

然后再像差分的矩形那样

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

代码:

#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=1;
  while (y)
  {
    if (y&1) ans*=x;
    y>>=1; 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(0);
  return(js((x2-x1+1)*(y2-y1+1))); 
}
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=0;
  rep(i,1,n)
    rep(j,1,m)
    {
      double now=qq(1,n,1,j-1)+qq(1,i-1,1,m)+qq(1,n,j+1,m)+qq(i+1,n,1,m);
      now-=qq(1,i-1,1,j-1)+qq(i+1,n,1,j-1)+qq(1,i-1,j+1,m)+qq(i+1,n,j+1,m);
      now/=num;
      now=ee-fsp(now,k);
      ans+=now;
    } 
  printf("%.0f",ans);
  return 0; 
}

 

posted @ 2018-08-07 15:50  尹吴潇  阅读(178)  评论(0编辑  收藏  举报