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

· · 题解

P15050 题解

思路

这是一道数学题!

我们先数以下图里面阶像素蜗牛里 1、2、3 的个数:

再结合图来看,我们就可以推出公式了。数字 1 的在 1 阶蜗牛里有 1 个,k(k > 1) 阶有 4 \times (k-1) 个;数字 2 在任何阶都只有 1 个;数字 3 在第 k 阶有 (k+2) \times 4-3 个。

代码

#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int k;
    cin>>k;
    cout<<(k==1?1:4*(k-1))+1+(k+2)*4-3;
    return 0;
}
/*
1 1 9
4 1 13
8 1 17
12 1 21
*/