The 2021 ICPC Asia Regionals Online Contest

本文主要介绍了两道算法题目,第一题是关于处理漏水屋顶的水流分配问题,使用优先队列和宽度优先搜索来解决。第二题是模拟路由器路径选择问题,涉及到网络路由和包损失的概念。

J Leaking Roof

这道题的题意就是一个n*n漏水的屋顶,问你每个漏水的地方会楼下多少的水。漏水的规则,每个平面都有相同数量的水,是从高往低,并且严格流向最低且低于当前的位置,当产生多个可能性时就平分该处的水。

这道题的思路就是把屋顶从高到低排序,可以用优先队列存储每个屋顶,然后利用宽搜处理最高出流向低处的水。

Grandpa Are lives in an old house. Now it is the heavy rain that occurs only once in a hundred years, but the roof of Grandpa Are’s house leaks. His roof can be viewed as a n×n grid, and each square has a height. Denote the height of the square with coordinate (i,j) by h
i,j

meters. Now the rainfall is m millimeters, meaning that the incoming rain on every square is m millimeters.

Since the roof is not flat, the water flows, and the water on a square can only flow to an adjacent square with a strictly smaller height. Two squares are adjacent when they share a common edge. Also, since the water level is subtle compared with the difference in heights of the squares, water will NOT flow to adjacent squares with the same height due to surface tension. Furthermore, the water equally divides among all possible directions. Besides, the roof leaks. To be specific, if a square has a height of 0, it leaks.

Grandpa Are wants to know how much water flows to each leaking square after a long time. The water flows to a square includes the one from the incoming rain and the one from the adjacent squares. He asks you to calculate for him.

Input
The first line contains two integers n and m.

The next n lines contains n integers in each line. The i-th line contains integer h
i,1

,…,h
i,n

, separated by a space, meaning the height of the squares in the i-th row. There is a space in the end of each line, and there is an eoln in the end of the n-th line.

It is guaranteed that 1≤n≤500 and 0≤m,h
i,j

≤10000.

Output
There are n lines in the output, and each line contains n real numbers. The i-th line contains a
i,1

,…,a
i,n

, separated by a space, meaning the height of water flows to the corresponding square at last, or 0 if the square is not leaking.

Your answer will be considered correct if and only if the absolute or relative error of your answer to the correct answer is less than or equal to 10
−6
. Also, there is a space in the end of each line, and there is an eoln in the end of the n-th line.

Sample Input 1
3 1
0 1 2
1 2 3
2 3 4
Sample Output 1
9.000000 0 0
0 0 0
0 0 0
Sample Input 2
3 1
0 1 0
1 1 1
0 1 0
Sample Output 2
2.000000 0 2.000000
0 0 0
2.000000 0 2.000000
Notes
In the first sample, all water flows to the leaking square (1,1).

In the second sample, notice that the water in the square (2,2) will NOT flow. Although it is not intuitive, it is the case in this problem due to the imaginary surface tension.

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>

#define x first
#define y second

using namespace std;

typedef long long LL;
typedef pair<int, int>PII;

const int N = 510;

int n, m;
int H[N][N]
<think>根据用户请求,用户需要查找2024年ICPC亚洲区域赛在线赛(1)的I题相关内容。由于提供的引用中没有直接关于2024年比赛的信息(引用[1]-[4]分别是2023、2021和2022年的比赛),因此无法直接从引用中获取该题的具体内容。 但是,考虑到ICPC比赛题目的常见类型和结构,我们可以推测I题可能涉及算法或数学问题。根据引用[3]和[4]中提到的解题思路(如打表、二分搜索、泰勒展开等),以及引用[1]中关于图论(公交路线问题)的描述,我们可以合理猜测2024年的I题也可能涉及类似算法。 由于缺乏具体题目信息,建议用户提供更多细节或尝试搜索最新比赛资料。同时,我们可以根据ICPC常见题型给出一般性解题建议: 1. **理解题目**:仔细阅读题目描述,明确输入输出格式和约束条件。 2. **设计算法**:根据问题类型(如动态规划、图论、数学等)选择合适算法。 3. **优化效率**:注意数据规模,选择时间复杂度和空间复杂度符合要求的算法。 若用户需要进一步帮助,建议提供题目具体描述。 §§相关问题§§ 1. 2024年ICPC亚洲区域赛在线赛(1)的其他题目有哪些? 2. 如何获取ICPC比赛的题目和题解? 3. 解决算法竞赛问题的一般步骤是什么? </think> 基于您的查询,我未能找到**2024年ICPC亚洲区域赛在线赛(1)I题**的直接内容。现有引用([1]-[4])涉及2021-2023年的赛事,但未覆盖2024年赛题。以下是结合ICPC题型特点的通用解题框架,供参考: --- ### **ICPC图论问题通用解法框架(以公交路线类问题为例)** 此类问题通常基于树或图结构(如引用[1]的公交路线),需处理路径查询或动态更新。核心步骤: 1. **建图与预处理** - 根据输入构建树/图,存储节点关系(如邻接表)。 - 预处理关键信息(如LCA、DFS序),优化查询效率。 ```python # 示例:构建无向图(邻接表) graph = [[] for _ in range(n+1)] for i in range(1, n): p = int(input()) # 父节点 graph[p].append(i+1) graph[i+1].append(p) ``` 2. **问题转化** - 将原问题转化为已知模型(如最近公共祖先、树上差分)。例如: > 若I题涉及多站点路径查询,可转化为LCA求两点距离[^1]。 3. **算法选择** - **静态查询**:LCA(倍增/Tarjan)、树链剖分。 - **动态更新**:DFS序+线段树、树上差分。 - **数学优化**:若含公式计算(如引用[4]),结合泰勒展开或极限分析。 4. **复杂度优化** - 避免暴力搜索(引用[3]提到打表不可行时改用二分)。 - 利用约束条件(如引用[1]中 $p_i \leq i$ 的单调性)。 --- ### **建议的解题方向** 若I题涉及: - **树结构查询**:LCA模板([参考代码](https://cp-algorithms.com/graph/lca_binary_lifting.html))。 - **数学计算**:极限/级数处理(引用[4]方法)。 - **路径统计**:树上差分或DP。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值