C. Connect Three Round #528 (Div. 2)【曼哈顿距离】
一、题面
二、分析
这题的关键是要确定一个点是从三个点出发的交汇点,其他的只要结合曼哈顿距离的定义即可明白。因为是三个点,这个交汇点的坐标分别对应的就是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)【曼哈顿距离】的更多相关文章
- Codeforces Round #528 (Div. 2)题解
Codeforces Round #528 (Div. 2)题解 A. Right-Left Cipher 很明显这道题按题意逆序解码即可 Code: # include <bits/stdc+ ...
- 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 ...
- (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 ...
- Codeforces Round #528 Div. 1 自闭记
整天自闭. A:有各种讨论方式.我按横坐标排了下然后讨论了下纵坐标单调和不单调两种情况.写了15min也就算了,谁能告诉我printf和cout输出不一样是咋回事啊?又调了10min啊?upd:突然想 ...
- D. Minimum Diameter Tree Round #528 (Div. 2)【树】
一.题面 题目链接 二.分析 该题注意读题的时候有强调边的权值为非负(即可以为0),此题就是求树两个叶子节点之间的最短距离.为了使两个叶子节点之间的距离最短,那么其实就是让每个最后到叶子的那条路径尽量 ...
- A. Right-Left Cipher Round #528 (Div. 2)【字符串】
一.题面 题目链接 二.分析 该题就是一个字符串的还原.长度为奇数时从左边开始,长度为偶数时从右边开始. 三.AC代码 #include <bits/stdc++.h> using nam ...
- B. Div Times Mod Round #528 (Div. 2)【简单数学】
一.题面 题目链接 二.分析 一个简单的数学题目,这里首先要把x分解了看 $x = kd + c$ 这样原问题中的n就变成了 $n = dc$ 上面这个式子中,c因为是x除k取余得到的,那么可以肯定 ...
- 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 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
随机推荐
- Java 基于web service 暴露接口 供外部调用
package cn.zr.out.outinterface; import java.text.SimpleDateFormat; import java.util.Date; import jav ...
- algorithm notes
1.算法可视化 https://visualgo.net/en
- ssh -X前设置DISPLAY=localhost:0
如果是在windows上用XMing做XServer,前面的localhost不能省,否则会被当作一个unix domain socket,而XMing没有实现这个功能,所以会出错 connect / ...
- 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 + ...
- Python基础 之列表、字典、元组、集合
基础数据类型汇总 一.列表(list) 例如:删除索引为奇数的元素 lis=[11,22,33,44,55] #第一种: for i in range(len(lis)): if i%2==1: de ...
- HTTP文件上传插件开发文档-JSP
版权所有 2009-2016 荆门泽优软件有限公司 保留所有权利 官方网站:http://www.ncmem.com/ 产品首页:http://www.ncmem.com/webplug/http-u ...
- [转]xe6 android 使用距离传感器(Proximiry)
The first step it's a run sample from RAD Studio that named SensorInfo on your device. On the tab Bi ...
- 读写文本文件之StreamReader和StreamWriter
private string _filePath = @"1.txt"; //查询文件是否存在,如果不存在,则创建 if (!File.Exists(_filePath)) { u ...
- LogNet4
ASP.Net MVC 项目中添加LogNet4 1,创建ASP.NET MVC项目 2,NuGet或者直接下载log4net.dll 并安装 3 在配置文件 web.config 加入 如下代码 & ...
- MySQL事务在MGR中的漫游记—路线图
欢迎访问网易云社区,了解更多网易技术产品运营经验. MGR即MySQL Group Replication,是MySQL官方推出的基于Paxos一致性协议的数据高可靠.服务高可用方案.MGR在20 ...