传送门: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. 如何学习OpenStack

    转自:http://www.chenshake.com/learn-how-openstack/ 如何学习OpenStack 由于工作的关系,也招收实习生,希望可以通过实习生的培养,让他们对Opens ...

  2. C#根据用户输入字符串,输出大写字母有几个,小写字母有几个

    static void Main(string[] args) { // 根据用户输入字符串,输出大写字母有几个,小写字母有几个. Console.WriteLine("请输入一行英文代码& ...

  3. nodejs常用npm包

    express常用npm包整理如下 art-template 一款js模板引擎,性能不错 jayson     一款纯node的rpc应用包,可实现rpc服务.tcp.http等服务 multer   ...

  4. 三、Bean的初始化

    一.使用构造器实例化Bean:这是最简单的方式,Spring IOC容器既能使用默认空构造器也能使用有参构造器两种方式创建bean 空构造器 <bean name="bean1&quo ...

  5. C Primer Plus note6

    error: invalid preprocessing directive #difine| 无效的宏定义处理 宏定义define 写成了 difine.

  6. PAT 1033. To Fill or Not to Fill

    #include <cstdio> #include <cstdlib> #include <vector> #include <algorithm> ...

  7. 图片大于div时的居中显示

    当图片大于div时,想要图片居中显示,如果图片等比例缩小可能会导致图片不能填充整个div,如果直接将图片不设置宽高,将其外层div设置overflow:hidden:这时即使外层div设置了水平垂直居 ...

  8. window下Jekyll建站过程

    > 前言 最近决定要写一个博客,先后注册了博客园和CSND的博客,但是他们的界面主题都不是很符合自己的要求,还没有足够个性化的发挥空间,遂决定自己建一个博客. 网上找了一下教程,感觉都不太详细, ...

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

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

  10. Android ImageButton单击切换按钮图片效果

    正常状态的效果: 按钮按下的效果图片: 一.在java中为图片按钮增加触摸监听的函数来实现图片切换,代码如下: ImageButton btn = (ImageButton)findViewById( ...