B. Move and Turn
A robot is standing at the origin of the infinite two-dimensional plane. Each second the robot moves exactly 11 meter in one of the four cardinal directions: north, south, west, and east. For the first step the robot can choose any of the four directions, but then at the end of every second it has to turn 90 degrees left or right with respect to the direction it just moved in. For example, if the robot has just moved north or south, the next step it takes has to be either west or east, and vice versa.
The robot makes exactly nn steps from its starting position according to the rules above. How many different points can the robot arrive to at the end? The final orientation of the robot can be ignored.
Input
The only line contains a single integer nn (1≤n≤10001≤n≤1000) — the number of steps the robot makes.
Output
Print a single integer — the number of different possible locations after exactly nn steps.
Examples
input
Copy
1output
Copy
4input
Copy
2output
Copy
4input
Copy
3output
Copy
12Note
In the first sample case, the robot will end up 1 meter north, south, west, or east depending on its initial direction.
In the second sample case, the robot will always end up 2–√2 meters north-west, north-east, south-west, or south-east.
题目类型:结论规律题
解题思路:打表
分奇偶!
n = 1, cnt = 4 列上的点数 1 2 1
n = 3, cnt = 12 2 3 2 3 2
n = 5 , cnt = 24 3 4 3 4 3 4 3
n = 7 , cnt = 40 4 6 4 6 4 6 4 6 4
…… 较小数为1 2 3 4 -》(n+1)/2 * 较小数个数2 3 4 5-》(n/2+2)
…… 较大数为2 3 4 6 -》(n/2 + 2) *较大数个数1 2 3 4 -》(n+)/2
n = 2 , cnt = 4;
n = 4 , cnt = 9
n = 6 , cnt = 16
……容易知道2 2 3 3 4 4 -》(n/2+1)^2
AC代码:
#include <bits/stdc++.h>
#define rep(x, a, b) for(int x = a; x <= b; x++)
#define pre(x, a, b) for(int x = b; x >= a; x--)
#define ll long long
#define endl '\n'
#define PII pair<int, int>
using namespace std;
const int N = 1e3+10;
int n;
void solve()
{
cin>>n;
if(n % 2)
{
ll ans =((n+ 1)/2 )*(n / 2 + 2) + ((n+1)/2 *(n/2 + 2));
cout<<ans<<endl;
}else cout<<(n / 2 + 1)* (n / 2 + 1)<<endl;
}
int main()
{
int t = 1;
bool is = false;
if(is) cin>>t;
//getchar();
while(t -- )
{
solve();
}
return 0;
}