题解:P15050 [UOI 2023 II Stage] Pixel snail

· · 题解

第一个步涂了一个边长为 k 的正方形,如果 k=1,则涂了一个格子。否则一共涂了 4 \times n - 4 个格子。

第二步涂了一个格子。

第三步涂了一个边长为 k + 2 的正方形,但少涂了 7 个,所以共涂了 4 \times (n+2) - 3 个格子。

把上面的答案加起来即可。

代码

#include<bits/stdc++.h>
#define int long long
using namespace std;
int n;
inline int read(){
    int x=0,f=1;char ch=getchar();
    for(;ch>'9'||ch<'0';ch=getchar())if(ch=='-')f=-1;
    for(;ch>='0'&&ch<='9';ch=getchar())x=(x<<1)+(x<<3)+(ch^48);
    return x*f;
}
signed main(){
    n=read();
    if(n==1)cout<<11,exit(0);
    cout<<(n+2)*4-3+1+n*4-4;
    return 0;
}