传送门:http://codeforces.com/contest/1087/problem/C

C. Connect Three

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

The Squareland national forest is divided into equal 1×11×1 square plots aligned with north-south and east-west directions. Each plot can be uniquely described by integer Cartesian coordinates (x,y)(x,y) of its south-west corner.

Three friends, Alice, Bob, and Charlie are going to buy three distinct plots of land A,B,CA,B,C in the forest. Initially, all plots in the forest (including the plots A,B,CA,B,C) are covered by trees. The friends want to visit each other, so they want to clean some of the plots from trees. After cleaning, one should be able to reach any of the plots A,B,CA,B,C from any other one of those by moving through adjacent cleared plots. Two plots are adjacent if they share a side.

For example, A=(0,0)A=(0,0), B=(1,1)B=(1,1), C=(2,2)C=(2,2). The minimal number of plots to be cleared is 55. One of the ways to do it is shown with the gray color.

Of course, the friends don't want to strain too much. Help them find out the smallest number of plots they need to clean from trees.

Input

The first line contains two integers xAxA and yAyA — coordinates of the plot AA (0≤xA,yA≤10000≤xA,yA≤1000). The following two lines describe coordinates (xB,yB)(xB,yB) and (xC,yC)(xC,yC) of plots BB and CC respectively in the same format (0≤xB,yB,xC,yC≤10000≤xB,yB,xC,yC≤1000). It is guaranteed that all three plots are distinct.

Output

On the first line print a single integer kk — the smallest number of plots needed to be cleaned from trees. The following kk lines should contain coordinates of all plots needed to be cleaned. All kk plots should be distinct. You can output the plots in any order.

If there are multiple solutions, print any of them.

Examples
input

Copy
0 0
1 1
2 2
output

Copy
5
0 0
1 0
1 1
1 2
2 2
input

Copy
0 0
2 0
1 1
output

Copy
4
0 0
1 0
1 1
2 0
Note

The first example is shown on the picture in the legend.

The second example is illustrated with the following image:

题意概括:

给三个格子的坐标,要求用最少的格子把这三个格子连起来,要求相邻格子相连需要是要有公共边。

解题思路:

所需要的总步数就是 X轴方向最大差值  加 Y轴方向最大差值 加 1.

输出的方格:

先按 X 小 Y 大的优先顺序对三个坐标排序。

从第一个点出发到第二个点,采取先沿着 X 轴 方向走,后沿着 Y轴 方向走,同时记录离第三个点的曼哈顿距离最近的一个转折点。

从转折点走到第三个点,采取先沿着Y轴方向走,后沿着 X轴方向走。

tip:如果担心会走重复的格子,加个标记就可以了。

AC code:

 #include <queue>
#include <cmath>
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
using namespace std; const int INF = 0x3f3f3f3f;
const int MAXN = 1e3+;
int N; struct date
{
int x, y;
}index[]; bool cmp(date a, date b)
{
if(a.x != b.x) return a.x < b.x;
else return a.y > b.y;
} bool mmp[MAXN][MAXN]; int main()
{
date kk, nxt;
int maxx = , maxy = , minx = INF, miny = INF;
for(int i = ; i <= ; i++){
scanf("%d %d", &index[i].x, &index[i].y);
maxx = max(maxx, index[i].x);
maxy = max(maxy, index[i].y);
minx = min(minx, index[i].x);
miny = min(miny, index[i].y);
}
sort(index+, index+, cmp);
memset(mmp, , sizeof(mmp));
int ans = (maxx-minx)+(maxy-miny)+;
printf("%d\n", ans);
printf("%d %d\n", index[].x, index[].y);
kk.x = index[].x;
kk.y = index[].y;
nxt.x = index[].x;
nxt.y = index[].y;
mmp[kk.x][kk.y] = false; int len = abs(index[].x - index[].x);
for(int i = ; i <= len; i++){
kk.x++;
if(mmp[kk.x][kk.y]) printf("%d %d\n", kk.x, kk.y);
if(kk.x == index[].x){
nxt.x = kk.x;
nxt.y = kk.y;
}
mmp[kk.x][kk.y] = false;
} len = abs(index[].y - index[].y);
for(int i = ; i <= len; i++){
if(index[].y < index[].y) kk.y++;
else kk.y--;
if(mmp[kk.x][kk.y]) printf("%d %d\n", kk.x, kk.y);
if(kk.y == index[].y){
nxt.x = kk.x;
nxt.y = kk.y;
}
mmp[kk.x][kk.y] = false;
} // printf("nxtx:%d nxty:%d\n", nxt.x, nxt.y); len = abs(index[].y - nxt.y);
for(int i = ; i <= len; i++){
if(nxt.y < index[].y) nxt.y++;
else nxt.y--;
if(mmp[nxt.x][nxt.y]) printf("%d %d\n", nxt.x, nxt.y);
mmp[nxt.x][nxt.y] = false;
} len = abs(index[].x - nxt.x);
for(int i = ; i <= len; i++){
nxt.x++;
if(mmp[nxt.x][nxt.y]) printf("%d %d\n", nxt.x, nxt.y);
mmp[nxt.x][nxt.y] = false;
} return ;
}

Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round 4) C. Connect Three 【模拟】的更多相关文章

  1. (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 ...

  2. Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2)

    Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) #include <bits/stdc++ ...

  3. Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) D. Minimum path

    http://codeforces.com/contest/1072/problem/D bfs 走1步的最佳状态 -> 走2步的最佳状态 -> …… #include <bits/ ...

  4. Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) D. Minimum path(字典序)

    https://codeforces.com/contest/1072/problem/D 题意 给你一个n*n充满小写字母的矩阵,你可以更改任意k个格子的字符,然后输出字典序最小的从[1,1]到[n ...

  5. Codeforces Round #512 (Div. 2, based on Technocup 2019 Elimination Round 1) C. Vasya and Golden Ticket 【。。。】

    任意门:http://codeforces.com/contest/1058/problem/C C. Vasya and Golden Ticket time limit per test 1 se ...

  6. Codeforces Round #512 (Div. 2, based on Technocup 2019 Elimination Round 1) E. Vasya and Good Sequences(DP)

    题目链接:http://codeforces.com/contest/1058/problem/E 题意:给出 n 个数,对于一个选定的区间,区间内的数可以通过重新排列二进制数的位置得到一个新的数,问 ...

  7. Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3)B. Personalized Cup

    题意:把一长串字符串 排成矩形形式  使得行最小  同时每行不能相差大于等于两个字符 每行也不能大于20个字符 思路: 因为使得行最小 直接行从小到大枚举即可   每行不能相差大于等于两个字符相当于  ...

  8. Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3) C. Playing Piano

    题意:给出一个数列 a1 a2......an  让你构造一个序列(该序列取值(1-5)) 如果a(i+1)>a(i) b(i+1)>b(i) 如果a(i+1)<a(i)  那么b( ...

  9. Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3) D. Barcelonian Distance 几何代数(简单)

    题意:给出一条直线 ax +by+c=0  给出两个整点 (x1,y1) (x2,y2) 只有在x,y坐标至少有一个整点的时 以及   给出的直线才有路径(也就是格子坐标图的线上) 问 两个整点所需要 ...

随机推荐

  1. 如何查找消耗资源较大的SQL

    对于优化来讲,查找消耗资源较大的SQL至关重要,下面介绍几个之前用到的SQL. 1.从V$SQLAREA中查询最占用资源的查询. select b.username username,a.disk_r ...

  2. C# 多线程系列之Semaphore使用

    Semaphore,即信号量的意思.是操作系统原始提供的内核同步对象. Semaphore semaphoreAcceptedClients = , 3,"Semaphore1") ...

  3. 十二 Cent OS下 tomcat启动项目响应速度很慢

    在tomcat部署了web项目,每次启动项目都需要花费2-3分钟,甚至有的时候需要花费10分钟左右,实在是太慢了. 在网上查找解决方案,把 jdk/jre/lib/security/java.secu ...

  4. IOC和DI到底是什么?

     在学习Spring框架的时候,我们总是能见到IOC这个单词,也时常听到DI这个词,那么他们分别是什么意思呢?接下来就讲讲个人对于这两个概念的理解  一.IOC和DI概念 IOC(控制反转):全称为: ...

  5. HOST文件配置

    HOST文件配置位置:C:\Windows\System32\drivers\etc\HOSTS 127.0.0.1 localhost 127.0.0.1 app.weilan.com 127.0. ...

  6. 51Nod1601 完全图的最小生成树计数

    传送门 我居然忘写题解啦!(记忆废) 不管怎么说,这题还算是一道好题啊……你觉得敦爷出的题会有水题么 …… 这题比较容易把人误导到Boruvka算法之类的东西上去(我们机房去刚D题的人一开始大多也被误 ...

  7. Python-MRO和C3算法

    一. python多继承 在前面的学习过程中,我们已经知道了python中类与类之间可以有继承关系,当出现x是一种y的时候就可以使用继承关系.即'is-a'关系,在继承关系中子类自动拥有父类中除了私有 ...

  8. Python入门-深浅拷贝

    首先我们在这里先补充一下基础数据类型的一些知识: 一.循环删除 1.前面我们学了列表,字典和集合的一些操作方法:增删改查,现在我们来看一下这个问题: 有这样一个列表: lst = ['周杰伦','周润 ...

  9. 软件项目技术点(1)——Tween算法及缓动效果

    AxeSlide软件项目梳理   canvas绘图系列知识点整理 Tween算法及缓动效果 软件里在切换步序时需要有过渡动画效果,从当前位置的画面缓动到目标位置的画面.动画效果可重新查看文章系列第一篇 ...

  10. easyui numberbox输入框 编辑不可编辑的切换

    背景:申请单里需要选费用类型,费用类型有的有子明细项,有个合计项    当有子明细项的时候,合计项的值是通过弹出的子明细项价格的总和(设置为可编辑没问题,因为点击出来弹框,编辑不了)    没有子明细 ...