Codeforces Gym 100341I Hungry Queen 2 Set水题

题目大意:

就是给出平面中n个点, 然后给出行走路径问最多走多少步不会出现不能到达以及碰撞的情况


大致思路:

首先如果只考虑上下左右走的话很明显用Set来存坐标然后用upper_bound查询两个点之间是否有被拦截即可

那么斜着走的话, 只需要将坐标轴旋转, 例如逆时针旋转45度于是(x, y)在新坐标系中映射的位置是(x - y, x + y)(放大了sqrt(2)倍

于是就和上下左右一样了


代码如下:

Result  :  Accepted     Memory  :  13576 KB     Time  :  590 ms

#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;

#define mp make_pair
#define x first
#define y second

#define maxn 100010

int n;
pair<int, int > p[maxn];
set<pair<int, int> > Sx;
set<pair<int, int> > Sy;
set<pair<int, int> > Gx;
set<pair<int, int> > Gy;
set<pair<int, int>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值