zoukankan      html  css  js  c++  java
  • Codeforces Round #662 (Div. 2) 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, 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): the number of grids of the games.

    Each of the next T lines contains a single integer n (1≤n≤109): 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
    inputCopy
    2
    3
    4
    outputCopy
    2
    3

    思路

    刚开始读错了,吐。用手画一下五的情况和四的情况,并且用聪明的小脑袋想一下,这个是个奇偶规律题。

    代码实现

    #include<cstdio>
    #include<algorithm>
    #include<vector>
    #include<queue>
    #include<map>
    #include<iostream>
    #include<cstring>
    #include<cmath>
    using namespace std;
    #define rep(i,f_start,f_end) for (int i=f_start;i<=f_end;++i)
    #define per(i,n,a) for (int i=n;i>=a;i--)
    #define MT(x,i) memset(x,i,sizeof(x) )
    #define rev(i,start,end) for (int i=0;i<end;i++)
    #define inf 0x3f3f3f3f
    #define mp(x,y) make_pair(x,y)
    #define lowbit(x) (x&-x)
    #define MOD 1000000007
    #define exp 1e-8
    #define N 1000005 
    #define fi first 
    #define se second
    #define pb push_back
    typedef long long ll;
    typedef pair<int ,int> PII;
    ll gcd (ll a,ll b) {return b?gcd (b,a%b):a; }
    inline int read() {
        char ch=getchar(); int x=0, f=1;
        while(ch<'0'||ch>'9') {
            if(ch=='-') f = -1;
            ch=getchar();
        } 
        while('0'<=ch&&ch<='9') {
            x=x*10+ch-'0';
            ch=getchar();
        }   return x*f;
    }
     
     
     
    int main () {
    //    freopen ("data.in","r",stdin);
       int t;
       cin>>t;
       while (t--) {
           int n;
           cin>>n;
           if (n%2==1) cout<<n-n/2<<endl;
           else cout<<n-n/2+1<<endl;
       }
    //    fclose (stdin);
       return 0;
    }
    
  • 相关阅读:
    js文字跳动效果
    js文字效果
    centos7安装Logwatch配合msmtp邮件客户端发送服务器监控分析日志
    子查询
    Hexo添加字数统计、阅读时长
    基于visual Studio2013解决C语言竞赛题之0523魔方阵
    基于visual Studio2013解决C语言竞赛题之0522和为素
    基于visual Studio2013解决C语言竞赛题之0521圆盘求和
    基于visual Studio2013解决C语言竞赛题之0520相邻元素
    基于visual Studio2013解决C语言竞赛题之0519最大值
  • 原文地址:https://www.cnblogs.com/hhlya/p/13457621.html
Copyright © 2011-2022 走看看