1393A(a).Rainbow Dash, Fluttershy and Chess Coloring(规律)

Rainbow Dash, Fluttershy and Chess Coloring

http://codeforces.com/contest/1393/problem/A

题面:

One evening Rainbow Dash and Fluttershy have come up with a game. Since the ponies are friends, they have decided not to compete in the game but to pursue a common goal.

The game starts on a square flat grid, which initially has the outline borders built up. Rainbow Dash and Fluttershy have flat square blocks with size 1 × 1 1\times1 1×1, Rainbow Dash has an infinite amount of light blue blocks, Fluttershy has an infinite amount of yellow blocks.

The blocks are placed according to the following rule: each newly placed block must touch the built on the previous turns figure by a side (note that the outline borders of the grid are built initially). At each turn, one pony can place any number of blocks of her color according to the game rules.

Rainbow and Fluttershy have found out that they can build patterns on the grid of the game that way. They have decided to start with something simple, so they made up their mind to place the blocks to form a chess coloring. Rainbow Dash is well-known for her speed, so she is interested in the minimum number of turns she and Fluttershy need to do to get a chess coloring, covering the whole grid with blocks. Please help her find that number!

Since the ponies can play many times on different boards, Rainbow Dash asks you to find the minimum numbers of turns for several grids of the games.

The chess coloring in two colors is the one in which each square is neighbor by side only with squares of different colors.

Input

The first line contains a single integer T ( 1 ≤ T ≤ 100 ) T (1 \le T \le 100) T(1T100): the number of grids of the games.

Each of the next T T T lines contains a single integer n ( 1 ≤ n ≤ 1 0 9 ) : n (1 \le n \le 10^9): n(1n109): the size of the side of the grid of the game.

Output

For each grid of the game print the minimum number of turns required to build a chess coloring pattern out of blocks on it.

Example

input
2
3
4
output
2
3
Note

For 3 × 3 3\times3 3×3 grid ponies can make two following moves:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-loGvzD8z-1597238485682)(D:\Code\Typroa__Code\Code force\000_专用图库CF\CF1393A.png)]

翻译:

一天晚上,Dash和 Flu 提出了(have come up with)一个游戏。因为小马们(ponies)是朋友,他们决定不竞争(compete)游戏而是(but to)追求一个共同的目标。

这个游戏开始在一个平面正方形(square flat)的格子,最初这个格子的建立的轮廓outline borders 边框。R和F具有平面正方形的格子,面积是 1 × 1 1\times1 1×1 ,R有无限数量的浅蓝的格子,F有无限数量的红色的格子。

这个块被放置按照以下following 的规则:每一个新放置的块必须接触建立于先前的回合图形的侧面by a side(注意,网格边缘的格子最初被建立了)。在每个回个中,一匹小马能放置任意infinite 数量的块 他自己的颜色 根据规则。

R和F发现他们可以建立图形patterns 在网格从这个游戏用过这种方式。他们决定开始于一些简单的事,因此他们下定决心放置块以形成 棋盘的着色。R闻名以她的速度speed,所以她感兴趣于极少数的回合 她和F需要去做得到一个棋盘着色,覆盖整个格子用块。请帮他找到整个数字。

因为小马能玩许多次在不同的板子上,R要求你找到极小化数的回合对于几个网格这个游戏。

这个棋盘着色在两种颜色,其中每一个正方形仅并排正方形的不同的颜色。

题意:

填空,将正方形填成国际象棋的颜色,规则是在之前填过的颜色的旁边填。

题解:

找规律,发现 5 填完最外层是 3 层,填完最外面一层是次数是1,然后填 3 层, 所以是每多两层是加一次。同理发现偶数也是这样。但是由于向下取整,所以偶数和奇数的式子是一样的。

代码:

#include <bits/stdc++.h>
using namespace std;

#define ll long long

const int MAXN = 1000010;
const int mod = 1e9 + 7;

int main (void)
{   
    int T;
    cin>>T;

    while(T--)
    {
        ll n;
        cin>>n;

        if(n % 2 == 0)
        {
            cout<< n / 2 + 1 << endl;
        }
    }


    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值