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 , 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 : the number of grids of the games.
Each of the next lines contains a single integer : 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 grid ponies can make two following moves:
思路
最佳方案即如图从最外层可填涂的方格开始向中心处理,通过模拟可以发现答案即为
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 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:
- : the storehouse received a plank with length
- : one plank with length xx was removed from the storehouse (it is guaranteed that the storehouse had some planks with length ).
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 : the initial amount of planks at the company’s storehouse, the second line contains integers : the lengths of the planks.
The third line contains a single integer : the number of events in the company. Each of the next 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 .
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 and a square storage using planks with lengths .
After the sixth event Applejack can build a rectangular storage using planks with lengths and a square storage using planks with lengths .
思路
用一个数组来记录数量超过的数字的个数,在录入数据后初始化一遍数组,并在每次和操作后检查数组是否需要更新。维护数组后,根据所需的数量关系,判断当前数组记录的情况是否符合题目要求,符合输出”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;
}
上一篇: HDU 1695 GCD
下一篇: 树的同构
推荐阅读
-
Codeforces Round #649 (Div. 2)-B. Most socially-distanced subsequence(思维)
-
Codeforces Round #461 (Div. 2) B. Magic Forest(异或的性质)
-
【解题报告】Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2)
-
Codeforces Round #659 (Div. 2) 题解
-
Codeforces Round #654 (Div. 2) - 题解
-
Codeforces Round #663 (Div. 2) B. Fix You
-
Educational Codeforces Round 98 (Rated for Div. 2) A-E 题解
-
Codeforces Round #658 (Div. 2) B. Sequential Nim
-
B. Power Sequence(数学+枚举)Codeforces Round #666 (Div. 2)
-
Codeforces Round #666 (Div. 2)B. Power Sequence(等比数列)