题解:P15050 [UOI 2023 II Stage] Pixel snail
P15050 题解
思路
这是一道数学题!
我们先数以下图里面阶像素蜗牛里 1、2、3 的个数:
-
1,4,8,12 -
1,1,1,1 -
9,13,17,21
再结合图来看,我们就可以推出公式了。数字 1 的在 1 阶蜗牛里有
代码
#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
*/