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连试试水的深浅..... ...
随机推荐
- WordPress 4.1去掉侧边栏“功能”小工具中WordPress.Org
打开wp-includes/default-widgets.php,注释掉第398到第403行 echo apply_filters( 'widget_meta_poweredby', sprintf ...
- 520. Detect Capital判断单词有效性
[抄题]: Given a word, you need to judge whether the usage of capitals in it is right or not. We define ...
- 在英文Win7操作系统上部署C#开发的Web系统出现乱码的解决方法
今天,迁移机器,把一个使用C#开发的Web系统部署到一台英文版Win7操作系统上,部署好以后,系统可以登录,只是网页上出现汉字乱码. 在这台电脑上,打开Word等文本编辑器,是可以正常输入.显示中文的 ...
- JS获得css样式即获得元素的计算样式(《Javascript精粹修订版》书摘)
为HTML文档中的元素指定样式可以有3种方法:使用内嵌样式.在页面的head中对Style进行声明以及外部 CSS 文件.元素的视觉效果往往是由上述3种方式的结合或者其中某一种方式来确定的,但是内嵌样 ...
- oracle数据库数据类型和约束
今天为大家分享一下关键数据库里面的数据类型和约束.我们都知道国家要讲法律,干什么事情都要遵守法律,比如小的时候你上学的时候要遵守课堂纪律.不能迟到和早退,同样的我们在数据库中创建一些表.或者查询一些表 ...
- Java 线程的通讯--生产者和消费者
package 生产者和消费者; //消费者 public class Customer implements Runnable { private Share_resources rescource ...
- Deep Visual-Semantic Alignments for Generating Image Descriptions(深度视觉-语义对应对于生成图像描述)
https://cs.stanford.edu/people/karpathy/deepimagesent/ Abstract We present a model that generates na ...
- Regularization and model selection
Suppose we are trying select among several different models for a learning problem.For instance, we ...
- git手动解决内容冲突
<span style="font-size:18px;">git checkout -b lab4 origin/lab4 git merge lab3</sp ...
- XE ListBox实现伸缩效果
功能:实现年月日压缩,初始化时item是所有年,点击年展开月,点击月展开天,再点击则收缩. 思路:实际上一开始是将所有item显示,只是将月日的item.height赋值为0, 记录每一行的it ...