题解:P10703 [SNCPC2024] 窗花

· · 题解

1.思路

考虑使用一个变量 ans 维护被覆盖的面积。(注意要开成 double 类型)

一张窗花的中心在 (x,y),此时再贴一张窗花,窗花的中心在 (a,b),那么有一下三种情况:(后面统一省略单位)

2.代码

#include<bits/stdc++.h>
using namespace std;
int n,mp[114][514];
double cnt;
signed main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n;
    while(n--)
    {
        int x,y;
        cin>>x>>y;
        if(mp[x][y]) continue;
        cnt += 2.0000000000000000;
        mp[x][y]++;
        cnt -= 0.500000000 * (double)(mp[x - 1][y] + mp[x + 1][y] + mp[x][y - 1] + mp[x][y + 1]);
    }
    cout<<cnt;

    return 0;

}