codeforces1459 B. Move and Turn

time limit per test2 seconds memory limit per test512 megabytes inputstandard input outputstandard output A robot is standing at the
origin of the infinite two-dimensional plane. Each second the robot
moves exactly 1 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 n 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 n (1≤n≤1000) — the
number of steps the robot makes.

Output Print a single integer — the number of different possible
locations after exactly n steps.

Examples inputCopy 1 outputCopy 4 inputCopy 2 outputCopy 4 inputCopy 3
outputCopy 12 Note 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–√ meters
north-west, north-east, south-west, or south-east.

盲猜是和奇偶有关,所以先试着打个表 发现果然有迹可循
奇数时[(n-3)/2+3]*(n+1)
偶数时(n/2+1)^2
具体证明?可能用数学归纳法可以整出来

//cyc
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define int long long
#define vector<int> VI
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mst(a) memset(a,0,sizeof a)
 
using namespace std;
typedef pair<int,int> pii;
int rec[35];
bool vis[31][31][31];
void dfs(int x,int y,int flag,int step)
{
    if(x>8||x<0||y>8||y<0||step>8)return;
 
    if(vis[x][y][step]!=1)rec[step]++;
    vis[x][y][step]=1;
    if(flag&1){
        dfs(x+1,y,flag^1,step+1);
        dfs(x-1,y,flag^1,step+1);
    }
    else{
        dfs(x,y+1,flag^1,step+1);
        dfs(x,y-1,flag^1,step+1);
    }
}
signed main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
   // dfs(4,3,1,1);
   // dfs(4,5,1,1);
   // dfs(3,4,0,1);
   // dfs(5,4,0,1);
   /* for(int i=1;i<=8;i++){
        cout<<i<<" "<<rec[i]<<endl;
    }*/
    int n;
    while(cin>>n){
    if(n==1||n==2){
        cout<<4<<endl;
    }
    else {
        if(n&1){
            int p,q;
            p=(n-3)/2+3;
            q=(n-3)+4;
            p=p*q;
            cout<<p<<endl;
        }
        else{
            int p=n/2;
            p++;
            p=p*p;
            cout<<p<<endl;
        }
    }
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值