EOJ Monthly 2021.9
比赛链接
EOJ Monthly 2021.9 Sponsored by TuSimple
A. Amazing Discovery
题目描述
Siyu recently made an amazing discovery. If are all positive integers, then
is also a positive integer.
To verify his discovery, please print modulo 998244353
.
输入格式
The only line contains three integers and .
输出格式
Print on a line modulo 998244353
.
样例
input
output
解题思路
分治,记忆化
我们可以推导出这样的式子:
为防止不必要的重复计算,我们可以记忆化
这里需要额外注意的一点是,快速幂的底数可能为负数,需要转换一下~
- 时间复杂度:
代码
B. Mine sweeper
题目描述
Now, little w is playing the game Mine-sweeper. The game is working on a grid field and each cell contains 0 or 1 mine.
For each cell, little w only know the total number of mines in itself and its 8 adjacent cells. He wants to know the total number of mines in this field, please help him.
输入格式
The first line contains two positive integers and .
In the following lines, each line contains integers. And each number represents the information little w knows of a cell, the total number of mines in itself and its 8 adjacent cells.
输出格式
One line with one integer represents the total number of mines.
input
output
input
output
提示
For example, suppose the number of mine in a field likes
011
010
000
Then little w will know
233
233
111
解题思路
题目只要求总的地雷数,我们可以根据周围地雷的总个数进行求解,即上下左右间隔3个格子,如:
我们发现:开始选择位置时需要保证不能出现单行,这样无法求解,所以需要分情况讨论(只用确定第一个位置 就行,甚至我们发现行列之间是相互独立的~):
- 时,;
时, - 时,;
时, - 时间复杂度:
代码
C. Connection
题目描述
Now, little W gets a 01 matrix of size . He wants to turn all elements in the matrix to 1. He can do the following operations:
-
Turning any one element to 1 from 0 costs 4.
-
If positions and are 1, turning to 1 from 0 will cost 3.
He wants to know the minimum cost, please help him.
输入格式
The first line contains two positive integers and .
The following lines represent the matrix with only 0 and 1.
输出格式
The answer.
input
output
input
output
解题思路
要使花费最少,即使得操作1的次数最少,不妨将行和列分开,即:
把行和列看作点,共 个点, 则把 和 连边,这样一个连通块内的点连边的话都可以通过操作2得到,我们要使整个不同连通块连成一个连通块才能使花费最少,操作1的目的就是使不同连通块连一起
- 时间复杂度:
代码
D. Divide and Merge
题目描述
Alice and Bob are playing a game about stones.
There are piles of stones, the -th pile of which initially contains stones.
They take turns to perform one of the following operations, starting from Alice.
- Split one pile of stones of odd number into two piles. Neither of the two split piles can be empty.
- Merge two piles of stones of even number into one pile.
The one who cannot perform any operation lose the game.
Suppose Alice and Bob play the game optimally, do you know who will win the game?
输入格式
The first line contains an integer .
The second line contains integers .
输出格式
Print Alice
or Bob
, the winner of the game.
样例
input
output
input
output
提示
The second line of the input of the first example is wrapped due to the limited space. All ten numbers are on a single line in the real input file.
解题思路
每次进行操作,某人偶数堆奇偶性不变,而最终偶数堆的数量肯定是要减少的,减少到1时必败,如果某人偶数堆为偶数,则不会到此必败点
- 时间复杂度:
代码
E. Effective Gradient
题目描述
Little W likes rational number very much. He has n points on the plane. You need to tell him the closest gradient to of the lines passing through at least two points.
Suppose a line passes through two points and . The gradient of it is exactly . Closest gradient means
as is the set of gradients of all availible lines.
输入格式
The first lines contain three integers
In the following lines, each line contains two integers represent the coordinate of a point.
输出格式
You should output a rational number represents the answer.
We ensure that the answer is unique and larger than 0.
You can use 1/0 to represent the gradient of infinity.
input
output
解题思路
与LCP 37. 最小矩形面积有类似的思路,即:
预处理:按点沿 方向上的投影排序,相当于重新确定点的位置
结论:答案一定出现在相邻点
反证法:我们假设紫色线为我们的答案,如果两根线中间还存在其他点的话,无论该点在紫色线上面还是下面,总存在一条包含该点的直线要比答案更优,有当前答案矛盾,故中间不可能存在其他点;答案斜率 时同理
注意:为求方便计算,我们可将整数类型转换为 double
,double
有效位 15
位足够了~
- 时间复杂度:
代码
F. Frog
题目描述
Mr Frog likes traveling, and once he came to a magical country. The country has cities, connected with bi-directional roads. Each city was assigned a level of beauty by Mr Frog. Mr Frog had planned several travels in the country. For each plan, there was a fixed departure city and a fixed destination city . He could choose several cities to explore in detail, but he would only choose the cities on the shortest path from to (including and ). He favored the number , so he wanted to choose some cities so that the sum of the level of beauty of those cities can be divided by .
Mr Frog asked you for helping him calculate the number of different choices satisfying his requirement. Two choices are different if Mr Frog would visit one city in one choice but would not visit that city in another choice. For sake of convenience, just output the answer modulo .
输入格式
The first line contains two integers and .
Each of the next lines contains two integers and , indicating there is a road connecting the city and .
The next line contains integers , where represents the level of beauty of city .
The next line contains an integer , indicating the number of travel plans.
Each of the next lines contains two integer and .
输出格式
For each plan, print on a line the number of different choices modulo .
input
output
解题思路
代码
__EOF__

本文链接:https://www.cnblogs.com/zyyun/p/15265419.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角【推荐】一下。您的鼓励是博主的最大动力!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!