传送门: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. Firebird execute block 批处理

    火鸟的批处理,效率好高,使用简单. execute block as declare variable i ; begin ) do begin :i = :i + ; insert into m_u ...

  2. Magento 2开发教程 - 创建新模块

    视频在youtube网站国内访问不了,可以使用FQ软件查看. 视频地址:www.youtube.com/embed/682p52tFcmY@autoplay=1 下面是视频文字介绍: Magento ...

  3. Redis - 事务操作

    Redis的事务基于四个命令: MULTI EXEC DISCARD WATCH 创建事务 Redis的事务从一个MULTI命令开始,MULTI总会命令返回"ok". 接着就可以开 ...

  4. [android] 练习PopupWindow实现对话框

    练习使用Dialog实习对话框 package com.example.tsh; import android.app.Activity; import android.app.Dialog; imp ...

  5. ThreadLocal介绍以及源码分析

    ThreadLocal 线程主变量 前面部分引用其他优秀博客,后面源码自己分析的,如有冒犯请私聊我. 用Java语言开发的同学对 ThreadLocal 应该都不会陌生,这个类的使用场景很多,特别是在 ...

  6. 微服务-分布式日志系统Logstash部署

    参考资料: 1 .Logstash中文官网 2. 阿里云Elasticsearch> 最佳实践 > logstash部署 3. logstash.elasticsearch.kibana搭 ...

  7. 关于display:inline-block布局导致错位问题分析

    移动端设计稿需求是这样的,如下图: 未知的几个头像从左至右并行居中排列. 一般可能直接使用float,但是设计图要求头像排列始终是居中的,于是想到要让它们成为行内元素,然后可使用的方法有flex bo ...

  8. Codeforces Round #413 B. T-shirt buying

    B. T-shirt buying time limit per test   3 seconds memory limit per test   256 megabytes   A new pack ...

  9. 03_Adaptive注解

    [Adaptive注解] package com.alibaba.dubbo.common.extension; import com.alibaba.dubbo.common.URL; import ...

  10. 关于安卓开发的学习一:webview

    在网上看到几篇不错的博客,分享和学习一下! Android使用WebView加载网页 https://blog.csdn.net/tuke_tuke/article/details/51684254 ...