传送门: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. 在 Azure 虚拟机上快速搭建 MongoDB 集群

    MongoDB 是目前在 NoSQL 市场上非常受欢迎的一个数据库,本文介绍如何使用 Azure PowerShell 和 Azure CLI 在 Azure 虚拟机上搭建单节点 MongoDB(测试 ...

  2. C#中引用类型和值类型的区别,分别有哪些

    C#的值类型包括:结构体(数值类型,bool型,用户定义的结构体),枚举,可空类型. C#的引用类型包括:数组,用户定义的类.接口.委托,object,字符串. 数组的元素,不管是引用类型还是值类型, ...

  3. asp.net Core2.1连接到Mysql 数据库

    1.首先,安装相关插件 在nuget下安装 1.Pomelo.EntityFrameworkCore.MySql 2.MySql.Data.EntityFrameworkCore 都要是2.1 < ...

  4. 2017年12月14日 LinQ高级查&&Asp.net WebForm Asp.net MVC

    LinQ的高级查询用法 开头:StartsWith()结尾:EndsWith()模糊:Contains() 个数:Count最大值:Max(r => r.price)最小值:Min(r => ...

  5. 樹莓派3B運行.Net Core2.1 Web 項目

    安裝.Net Core 運行時和SDK(非必選) 下載地址 安裝 # 安裝運行時 sudo apt-get -y update # Install the packages necessary for ...

  6. RabbitMQ如何解决各种情况下丢数据的问题

    1.生产者丢数据 生产者的消息没有投递到MQ中怎么办?从生产者弄丢数据这个角度来看,RabbitMQ提供transaction和confirm模式来确保生产者不丢消息. transaction机制就是 ...

  7. Java 集合类常用方法

    Collection中的contains()方法和remove()方法. boolean contains(Object o);该方法是用来判断集合中是否包含某个元素,若包含,返回true,不包含返回 ...

  8. Java finally关键字

    关于finally语句块,有如下特点: 1.finally语句块可以直接和try语句块联用.try...finally... 2.try...catch...finally也可以 3.通常在final ...

  9. js两个字符串明明一样却判断显示不相等

    一.问题 两个字符串看起来一样.类型一样,判断str1==str2时返回false: 二.原因 字符串可能含有其他特殊字符:换行符(%D).空格(%20)...一般不显示. 三.如何判断 encode ...

  10. thinkphp5设置404页面不跳转

    thinkphp5设置404页面的步骤: 1. 首先关闭调试模式,即配置application/config文件,使'app_debug' => false 2. 添加自定义404页面跳转地址, ...