Codeforces Round #662 (Div. 2) [ A , B ] 题解报告


[contest link]

A. Rainbow Dash, Fluttershy and Chess Coloring

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×1 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≤T≤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≤n≤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×3 3×3 grid ponies can make two following moves:
在这里插入图片描述

思路

最佳方案即如图从最外层可填涂的方格开始向中心处理,通过模拟可以发现答案即为
f l o o r ( n 2 + 1 ) floor(\frac{n}{2}+1) floor(2n+1)

在这里插入图片描述

my Accepted code

/*
 * @Autor: CofDoria
 * @Date: 2020-08-07 22:22:00
 * @LastEditTime: 2020-08-07 22:48:12
 */
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>

#define ll long long
#define db double
#define inf 0x3f3f3f3f
#define s(a, n) memset(a, n, sizeof(a))
#define rep(l, a, b) for (ll l = a; l < b; ++l)
#define per(l, a, b) for (ll l = a; l >= b; --l)
#define debug(a) cout << '#' << a << '#' << endl

using namespace std;
bool fi = true;
const unsigned long long MOD = 1e9 + 7;

ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); }

int main() {
    int t;
    scanf("%d", &t);
    while (t--) {
        int n;
        scanf("%d", &n);
        printf("%d\n", n / 2 + 1);
    }
}

B. Applejack and Storages

This year in Equestria was a year of plenty, so Applejack has decided to build some new apple storages. According to the advice of the farm designers, she chose to build two storages with non-zero area: one in the shape of a square and another one in the shape of a rectangle (which possibly can be a square as well).

Applejack will build the storages using planks, she is going to spend exactly one plank on each side of the storage. She can get planks from her friend’s company. Initially, the company storehouse has n n n planks, Applejack knows their lengths. The company keeps working so it receives orders and orders the planks itself. Applejack’s friend can provide her with information about each operation. For convenience, he will give her information according to the following format:

  • + + + x x x: the storehouse received a plank with length x x x
  • − − x x x: one plank with length xx was removed from the storehouse (it is guaranteed that the storehouse had some planks with length x x x).

Applejack is still unsure about when she is going to order the planks so she wants to know if she can order the planks to build rectangular and square storages out of them after every event at the storehouse. Applejack is busy collecting apples and she has completely no time to do the calculations so she asked you for help!

We remind you that all four sides of a square are equal, and a rectangle has two pairs of equal sides.

Input

The first line contains a single integer n ( 1 ≤ n ≤ 1 0 5 ) n (1≤n≤10^5) n(1n105): the initial amount of planks at the company’s storehouse, the second line contains n n n integers a 1 , a 2 , … , a n ( 1 ≤ a i ≤ 1 0 5 ) a_1,a_2,…,a_n (1≤a_i≤10^5) a1,a2,,an(1ai105): the lengths of the planks.

The third line contains a single integer q ( 1 ≤ q ≤ 1 0 5 ) q (1≤q≤10^5) q(1q105): the number of events in the company. Each of the next q q q lines contains a description of the events in a given format: the type of the event (a symbol + + + or − − ) is given first, then goes the integer x ( 1 ≤ x ≤ 1 0 5 ) x (1≤x≤10^5) x(1x105).

Output

After every event in the company, print “YES” if two storages of the required shape can be built from the planks of that company’s set, and print “NO” otherwise. You can print each letter in any case (upper or lower).

Example

input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
output
NO
YES
NO
NO
NO
YES

Note

After the second event Applejack can build a rectangular storage using planks with lengths 1 , 2 , 1 , 2 1, 2, 1, 2 1,2,1,2 and a square storage using planks with lengths 1 , 1 , 1 , 1 1, 1, 1, 1 1,1,1,1.

After the sixth event Applejack can build a rectangular storage using planks with lengths 2 , 2 , 2 , 2 2, 2, 2, 2 2,2,2,2 and a square storage using planks with lengths 1 , 1 , 1 , 1 1, 1, 1, 1 1,1,1,1.

思路

用一个 c o co co数组来记录数量超过 2 , 4 , 6 , 8 2,4,6,8 2,4,6,8的数字的个数,在录入数据后初始化一遍 c o co co数组,并在每次 + + + − - 操作后检查 c o co co数组是否需要更新。维护 c o co co数组后,根据所需的数量关系,判断当前 c o co co数组记录的情况是否符合题目要求,符合输出”YES“,不符合输出“NO”。

在这里插入图片描述

my Accepted code

/*
 * @Autor: CofDoria
 * @Date: 2020-08-07 22:22:05
 * @LastEditTime: 2020-08-08 11:10:58
 */
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>

#define ll long long
#define db double
#define inf 0x3f3f3f3f
#define s(a, n) memset(a, n, sizeof(a))
#define rep(l, a, b) for (ll l = a; l < b; ++l)
#define per(l, a, b) for (ll l = a; l >= b; --l)
#define debug(a) cout << '#' << a << '#' << endl

using namespace std;
bool fi = true;
const unsigned long long MOD = 1e9 + 7;

ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); }

int main() {
    int a[100005];
    int co[10];
    int n, aa;
    char s[10], ch = '\n';
    s(co, 0);
    s(a, 0);
    scanf("%d", &n);
    rep(tt, 0, n) {
        scanf("%d", &aa);
        a[aa]++;
    }
    rep(tt, 1, 100000 + 1) {
        for (int i = 2; i <= 8; i += 2)
            if (a[tt] >= i) co[i]++;
    }
    scanf("%d", &n);
    rep(tt, 0, n) {
        scanf("%s", s);
        ch = s[0];
        scanf("%d", &aa);
        if (ch == '+') {
            a[aa]++;
            for (int i = 2; i <= 8; i += 2)
                if (a[aa] == i) co[i]++;
        } else {
            a[aa]--;
            for (int i = 2; i <= 8; i += 2)
                if (a[aa] + 1 == i) co[i]--;
        }
        if (co[8] >= 1)
            printf("YES\n");
        else if (co[6] >= 1 && co[2] >= 2)
            printf("YES\n");
        else if (co[4] >= 2)
            printf("YES\n");
        else if (co[4] >= 1 && co[2] >= 3)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值