25-1-12-Codeforces-Round-996-Div-2
3. Codeforces Round 996 (Div. 2)
A. Two Frogs(800)
(constructive algorithms)(games)(greedy)(math)
Ques
题意
| Roaming through the alligator-infested Everglades, Florida Man encounters a most peculiar showdown. |
|---|
There are
During a frog’s turn, it can jump either one space to the left or one space to the right, as long as the destination lilypad exists. For example, on Alice’s first turn, she can jump to either lilypad
However, there are some restrictions:
- The two frogs cannot occupy the same lilypad. This means that Alice cannot jump to a lilypad that Bob is currently occupying, and vice versa.
- If a frog cannot make a valid jump on its turn, it loses the game. As a result, the other frog wins.
Determine whether Alice can guarantee a win, assuming that both players play optimally. It can be proven that the game will end after a finite number of moves if both players play optimally.
Input
Each test contains multiple test cases. The first line contains the number of test cases
The first and only line of each test case contains three integers
Note that there are no constraints on the sum of
Output
For each test case, print a single line containing either “YES” or “NO”, representing whether or not Alice has a winning strategy.
You can output the answer in any case (upper or lower). For example, the strings “yEs”, “yes”, “Yes”, and “YES” will be recognized as positive responses.
Example
1 | 5 |
1 | NO |
Note
In the first test case, Alice has no legal moves. Therefore, Alice loses on the first turn.
In the second test case, Alice can only move to lilypad
In the third test case, Alice can only move to lilypad
Ans
画图不断模拟下,很快就能发现这个跟ab之间的距离有关:
- 如果是奇数 输出YES
- 如果是偶数 输出NO
1 | void solve(){ |
B. Crafting(1000)
(constructive algorithms)(greedy)(sortings)
Ques
题意
| As you’d expect, Florida is home to many bizarre magical forces, and Florida Man seeks to tame them. |
|---|
There are
- Select a material
(where ). Then, spend unit of every other material (in other words, ) to gain unit of material . More formally, after selecting material , update array as follows: , and for all where and . Note that all must remain non-negative, i.e. you cannot spend resources you do not have.
You are trying to craft an artifact using these materials. To successfully craft the artifact, you must have at least
Input
Each test contains multiple test cases. The first line contains the number of test cases
The first line of each test case contains a single integer
The second line of each test case contains
The third line of each test case contains
It is guaranteed that the sum of
Output
For each test case, print a single line containing either “YES” or “NO”, representing whether or not the artifact can be crafted.
You can output the answer in any case (upper or lower). For example, the strings “yEs”, “yes”, “Yes”, and “YES” will be recognized as positive responses.
Example
1 | 3 |
1 | YES |
Note
In the first test case, perform an operation on material
In the second test case, it can be shown that no matter how the operations are performed, it is impossible to craft the artifact.
In the third test case, we can perform the operation on material
Ans
先创建新数组,存一下a-b的值,然后跑样例的时候突然意识到:
- 当存在两个及以上的负数时,那肯定输出NO的,这个你自己想一想也会发现
- 当只有一个负数时,那就是这个数不断+1,剩下的数不断-1。还可以再优化下,我们可以只比较前两个元素,也就是如果这两个元素之和大于等于0,那就输出YES。因为既然最小的正数都满足条件了,那后面那些更大的正数肯定也是可以的
- 当没有负数,直接输出YES,并return掉
1 | void solve(){ |
C. The Trail(1400)
(brute force)(constructive algorithms)(greedy)(math)(two pointers)
Ques
题意
| There are no mountains in Florida, and Florida Man cannot comprehend their existence. As such, he really needs your help with this one. |
|---|
In the wilderness lies a region of mountainous terrain represented as a rectangular grid with
However, this region has been tampered with. A path consisting of
To restore the terrain to its original state, it is known that the region possessed a magical property before it was tampered with: all rows and all columns shared the same sum of altitudes. More formally, there exists an integer
Your task is to assign new altitudes to the cells on the path such that the above magical property is restored. It can be proven that a solution always exists. If there are multiple solutions that satisfy the property, any one of them may be provided.
Input
Each test contains multiple test cases. The first line contains the number of test cases
The first line of each test case contains two integers
The second line of each test case contains a string
The
It is guaranteed that the sum of
Output
For each test case, output
Example
1 | 4 |
1 | 1 2 3 |
Note
In the first test case, the grid has been filled such that every row and column contains the numbers
In the second test case, the grid has been filled such that all rows and columns sum to
Ans
初始思路
写到后面发现方向就错了,无奈只能放弃
题解
我们可以让所有的行列和都为0可惜了,刚开始就是这么想的
设:
row[i] = 第 i 行当前总和
col[j] = 第 j 列当前总和
因为路径上的格子是0,所以row[i]和col[i]只统计非路径格子的贡献
如果当前位置是(i,j):
下一步是D
以后不会再碰到第i行的格子
但我们要保证每一行总和是0,而当前第x行的总和是row[x],且当前格子是第x行里最后一个还能修改的路径格子,所以我们这个格子要填
a[x][y] -= row[x],同时更新下row[x] += a[x][y]。而同时,这个格子也属于第y列,所以第y列的总和也要更新col[y] += a[x][y]1
2
3a[i][j] -= row[i];
row[i] += a[i][j];
col[j] += a[i][j];下一步是R
以后不会再碰第j行的格子
同理
1
2
3a[i][j] -= col[i];
col[j] += a[i][j];
row[i] += a[i][j];最后到达(n,m),只剩下最后一行和最后一列没有处理
此时填
a[n][m] -= row[n];或者a[n][m] -= col[m];
1 | void solve(){ |

