一、题面

题目链接

二、分析

这题的关键是要确定一个点是从三个点出发的交汇点,其他的只要结合曼哈顿距离的定义即可明白。因为是三个点,这个交汇点的坐标分别对应的就是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. C# ShowDialog时窗体贱传值得方法

    用C#开发应用的时候,通常需要多个窗体!有时候为了打开窗体的时候禁止操作父窗体,我们一般采用模态对话框的方法,也算就是用ShowDialog()方法. 假设有两个窗体A和B,A作为主窗体使用ShowD ...

  2. Angular27 指令

    1 自定概述 2 自定义指令 详情参见<揭秘Angular2> 2.1 属性指令 >工具代码 <div class="panel panel-primary" ...

  3. SqlServer——神奇代码1之Update

    说明:一个带有update的循环的代码.很简单,但是在QQ群里问了,应该说是很少有人注意这个问题,也就是很少有人真的理解SQL中的Update. 代码如下: if object_id('tempdb. ...

  4. MRPT - Mobile Robot Programming Toolkit

    1. https://www.mrpt.org/Building_and_Installing_Instructions#1_Prerequisites P1. error C2371: “int32 ...

  5. ubuntu 16.04 ARM glog移植

    1. 下载源文件https://github.com/google/glog 2. 源文件有CMakeLists.txt, 直接使用toolchain.cmake 直接编译就可以了,详情参考我的随笔  ...

  6. GCC 常见参数配置

    博客转载自:https://www.cnblogs.com/zhangsir6/articles/2956798.html 简介gcc and g++现在是gnu中最主要和最流行的c & c+ ...

  7. ESP8266-iot-3

    ESP8266 WIFI操作 参考资料 模式选择 程序: 把之前的Helloworld程序复制过来改成wifi工程 先输出获取的当前模式 编译后会出错,因为os_printf的头文件没有被包含进来 结 ...

  8. Python基础入门-函数实战登录功能

    ''' 函数实战: .加法计算器 .过滤器 .登录功能实战 ''' def add(a,b): return a+b def login_order(): return 'asdfasdfdasfad ...

  9. 在使用webstorm打开本地项目文件夹的html文件时,浏览器提示404错误

    错误原因:在使用webstorm打开本地项目文件夹的html文件时,浏览器提示404错误. 错误分析:文件夹命名内包含“+”,此特殊符号导致浏览器解析错误. 改正方案:去掉特殊符号“+”

  10. 如何在DOS下以管理员身份执行命令?

    原创 普通User的DOS窗口: 以管理员身份运行的DOS窗口: 转换(Windows10系统下): 13:11:55 2018-10-18