一、题面

题目链接

二、分析

这题的关键是要确定一个点是从三个点出发的交汇点,其他的只要结合曼哈顿距离的定义即可明白。因为是三个点,这个交汇点的坐标分别对应的就是x,y值的中值。然后一个小技巧就是曼哈顿距离的输出,两种情况对应两种while循环,等于的情况刚好退出循环。

三、AC代码

 #include <bits/stdc++.h>

 using namespace std;

 int X[], Y[];
set<pair<int, int> > Ans; void Print(int x, int y, int xt, int yt)
{
while(x < xt)
{
x++;
Ans.insert(make_pair(x, y));
}
while(x > xt)
{
x--;
Ans.insert(make_pair(x, y));
}
while(y > yt)
{
y--;
Ans.insert(make_pair(xt, y));
}
while(y < yt)
{
y++;
Ans.insert(make_pair(xt, y));
}
} int main()
{
//freopen("input.txt", "r", stdin);
while(scanf("%d %d", &X[], &Y[])!=EOF)
{
int ans;
int dx[], dy[];
for(int i = ; i < ; i++)
{
scanf("%d %d", &X[i], &Y[i]);
}
memcpy(dx, X, sizeof(X));
memcpy(dy, Y, sizeof(Y));
sort(dx, dx+);
sort(dy, dy+);
for(int i = ; i < ; i++)
{
Ans.insert(make_pair(X[i], Y[i]));
Print(X[i], Y[i], dx[], dy[]);
}
printf("%d\n", Ans.size());
for(auto itr = Ans.begin(); itr != Ans.end(); itr++)
{
printf("%d %d\n", itr->first, itr->second);
}
}
return ;
}

C. Connect Three Round #528 (Div. 2)【曼哈顿距离】的更多相关文章

  1. Codeforces Round #528 (Div. 2)题解

    Codeforces Round #528 (Div. 2)题解 A. Right-Left Cipher 很明显这道题按题意逆序解码即可 Code: # include <bits/stdc+ ...

  2. Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round 4) C. Connect Three 【模拟】

    传送门:http://codeforces.com/contest/1087/problem/C C. Connect Three time limit per test 1 second memor ...

  3. (AB)Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round

    A. Right-Left Cipher time limit per test 1 second memory limit per test 256 megabytes input standard ...

  4. Codeforces Round #528 Div. 1 自闭记

    整天自闭. A:有各种讨论方式.我按横坐标排了下然后讨论了下纵坐标单调和不单调两种情况.写了15min也就算了,谁能告诉我printf和cout输出不一样是咋回事啊?又调了10min啊?upd:突然想 ...

  5. D. Minimum Diameter Tree Round #528 (Div. 2)【树】

    一.题面 题目链接 二.分析 该题注意读题的时候有强调边的权值为非负(即可以为0),此题就是求树两个叶子节点之间的最短距离.为了使两个叶子节点之间的距离最短,那么其实就是让每个最后到叶子的那条路径尽量 ...

  6. A. Right-Left Cipher Round #528 (Div. 2)【字符串】

    一.题面 题目链接 二.分析 该题就是一个字符串的还原.长度为奇数时从左边开始,长度为偶数时从右边开始. 三.AC代码 #include <bits/stdc++.h> using nam ...

  7. B. Div Times Mod Round #528 (Div. 2)【简单数学】

    一.题面 题目链接 二.分析 一个简单的数学题目,这里首先要把x分解了看 $x = kd + c$ 这样原问题中的n就变成了 $n = dc$ 上面这个式子中,c因为是x除k取余得到的,那么可以肯定 ...

  8. Codeforces Round #296 (Div. 1) C. Data Center Drama 欧拉回路

    Codeforces Round #296 (Div. 1)C. Data Center Drama Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xx ...

  9. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

随机推荐

  1. Java 基于web service 暴露接口 供外部调用

    package cn.zr.out.outinterface; import java.text.SimpleDateFormat; import java.util.Date; import jav ...

  2. algorithm notes

    1.算法可视化 https://visualgo.net/en

  3. ssh -X前设置DISPLAY=localhost:0

    如果是在windows上用XMing做XServer,前面的localhost不能省,否则会被当作一个unix domain socket,而XMing没有实现这个功能,所以会出错 connect / ...

  4. Luogu 3723 [AH2017/HNOI2017]礼物

    BZOJ 4827 $$\sum_{i = 1}^{n}(x_i - y_i + c)^2 = \sum_{i = 1}^{n}(x_i^2 + y_i^2 + c^2 - 2 * x_iy_i + ...

  5. Python基础 之列表、字典、元组、集合

    基础数据类型汇总 一.列表(list) 例如:删除索引为奇数的元素 lis=[11,22,33,44,55] #第一种: for i in range(len(lis)): if i%2==1: de ...

  6. HTTP文件上传插件开发文档-JSP

    版权所有 2009-2016 荆门泽优软件有限公司 保留所有权利 官方网站:http://www.ncmem.com/ 产品首页:http://www.ncmem.com/webplug/http-u ...

  7. [转]xe6 android 使用距离传感器(Proximiry)

    The first step it's a run sample from RAD Studio that named SensorInfo on your device. On the tab Bi ...

  8. 读写文本文件之StreamReader和StreamWriter

    private string _filePath = @"1.txt"; //查询文件是否存在,如果不存在,则创建 if (!File.Exists(_filePath)) { u ...

  9. LogNet4

    ASP.Net MVC 项目中添加LogNet4 1,创建ASP.NET MVC项目 2,NuGet或者直接下载log4net.dll 并安装 3 在配置文件 web.config 加入 如下代码 & ...

  10. MySQL事务在MGR中的漫游记—路线图

    欢迎访问网易云社区,了解更多网易技术产品运营经验.   MGR即MySQL Group Replication,是MySQL官方推出的基于Paxos一致性协议的数据高可靠.服务高可用方案.MGR在20 ...