2023广东省大学生程序设计竞赛 I. Path Planning

题目

Problem - I - Codeforces

对于一个n*m的有值矩阵,只能往下和往右走,求(1,1)到(n,m)路径经过值集合的Mex

思路

2023广东ICPC省赛 I-路径规划(set) - 知乎 (zhihu.com)学习了Resot佬的题解,听说他在准备升学考试,祝他取得好成绩!

我们可以枚举从0,1,...,n * m - 1这些值所在的位置(x,y),在当前位置有机会经过的两个矩形区域,分别是左上角为(1,1)右下角为(x,y)的矩形和左上角为(x,y)右下角为(n,m)的矩形。

那么我们取下一个点的时候,用multiset的二分找到下一个点所在的区域,并把所在区域删掉,然后再往multiset中加入两个可达的矩阵区域。当遍历到的值所在位置不在所有有效区域中时,输出当前这个值。

这种每找到一个区间区间删掉,再加入两个有效区间的方法,可以保证路径经过的值的无序性。

代码

#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> PII;
const int mod = 1e9 + 7, N = 1e5 + 10;
struct node 
{
    int x, y, dx, dy;
    node() {}
    node(int a, int b, int c, int d): x(a), y(b), dx(c), dy(d) {}
    bool operator < (const node &W) const 
	{
        if (x == W.x) return y < W.y;
        return x < W.x;
    }
};
void solve() 
{
    int n, m; cin >> n >> m;
	vector<PII>a(n * m);
	for(int i = 1; i <= n; i ++)
	    for(int j = 1; j <= m; j ++)
	    {
			int x; cin >> x;
			a[x] = {i, j};
		}  
	multiset<node>s;
	s.insert(node(1, 1, n, m));
	int mex = 0;
	for(int k = 0; k < n * m; k ++)
	{
		auto [x, y] = a[k];
        auto p = prev(s.upper_bound(node(x, y, n, m)));
		auto it = *p;
		if(x >= it.x && x <= it.dx && y >= it.y && y <= it.dy)
		{
			mex ++;
			s.erase(p);
			s.insert({it.x, it.y, x, y});
			s.insert({x, y, it.dx, it.dy});
		}
		else break;
	}	
	cout << mex << '\n';
}
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int t = 1; cin >> t;
	while(t --)
	{
		solve();
	}

}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
# CRP Open source C++ Implementation of Customizable Route Planning (CRP) by Delling et al. This project was part of a practical course at Karlsruhe Institute of Technology (KIT). Requirements ============ In order to build CRP you need to have the following software installed: - Boost C++ Library (http://www.boost.org), more specifically Boost Iostreams. - Scons (http://scons.org) - g++ >= 4.8 (https://gcc.gnu.org) Building CRP ============ If the Boost Library is not in your PATH, make sure to edit the *SConstruct* file in the root directory to point the build script to the correct location of Boost. There is a section *Libraries* in the *SConstruct* file where you can specify the paths. Once you have installed all the software packages listed above, you can build the CRP programs by typing ``` scons --target=CRP --optimize=Opt -jX ``` into your terminal where `X` is the number of cores you want to use for building the project. If you want to use a specific g++ compiler version you can add `--compiler=g++-Version`. We also support a debug and profiling build that you can call with `--optimize=Dbg` and `--optimize=Pro` respectively. This command will build three programs in the folder *deploy*: - *osmparser*: Used to parse an OpenStreetMap (OSM) bz2-compressed map file. Call it with `./deploy/osmparser path_to_osm.bz2 path_to_output.graph.bz2` - *precalculation*: Used to build an overlay graph based on a given partition. Call it with `./deploy/precalculation path_to_graph path_to_mlp output_directory`. Here, *path_to_mlp* is the path to a *MultiLevelPartition* file for the graph that you need to provide. For more details, take a look into our project documentation. - *customization*: Used to precompute the metric weights for the overlay graph. Call it with `./deploy/customization path_to_graph path_to_overlay_graph metric_output_directory metric_type`. We currently support the following metric types: *hop* (number of edges traversed), *time* and *dist*.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值