Codeforces round 691(div.2)B.Move and Turn

可以通过找规律的方式求解。
当n为奇数时
当n为偶数时

#include<bits/stdc++.h>
using namespace std;
int main()
{
    
    
	int n;
	scanf("%d",&n);
	if(n%2==1&&n!=1)
	{
    
    
		int res=0;
		for(int i=1;i<=n;i+=2)
		{
    
    
			res+=8+4*(i/2-1);
		}
		printf("%d\n",res);
	}
	else if(n==1)
	{
    
    
		printf("4\n");
	}
	else
	{
    
    
		printf("%d\n",(n/2+1)*(n/2+1));
	}
}

猜你喜欢

转载自blog.csdn.net/p15008340649/article/details/111411611