传送门: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
  1. 0 0
  2. 1 1
  3. 2 2
output

Copy
  1. 5
  2. 0 0
  3. 1 0
  4. 1 1
  5. 1 2
  6. 2 2
input

Copy
  1. 0 0
  2. 2 0
  3. 1 1
output

Copy
  1. 4
  2. 0 0
  3. 1 0
  4. 1 1
  5. 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:

  1. #include <queue>
  2. #include <cmath>
  3. #include <cstdio>
  4. #include <vector>
  5. #include <cstring>
  6. #include <iostream>
  7. #include <algorithm>
  8. #define LL long long
  9. using namespace std;
  10.  
  11. const int INF = 0x3f3f3f3f;
  12. const int MAXN = 1e3+;
  13. int N;
  14.  
  15. struct date
  16. {
  17. int x, y;
  18. }index[];
  19.  
  20. bool cmp(date a, date b)
  21. {
  22. if(a.x != b.x) return a.x < b.x;
  23. else return a.y > b.y;
  24. }
  25.  
  26. bool mmp[MAXN][MAXN];
  27.  
  28. int main()
  29. {
  30. date kk, nxt;
  31. int maxx = , maxy = , minx = INF, miny = INF;
  32. for(int i = ; i <= ; i++){
  33. scanf("%d %d", &index[i].x, &index[i].y);
  34. maxx = max(maxx, index[i].x);
  35. maxy = max(maxy, index[i].y);
  36. minx = min(minx, index[i].x);
  37. miny = min(miny, index[i].y);
  38. }
  39. sort(index+, index+, cmp);
  40. memset(mmp, , sizeof(mmp));
  41. int ans = (maxx-minx)+(maxy-miny)+;
  42. printf("%d\n", ans);
  43. printf("%d %d\n", index[].x, index[].y);
  44. kk.x = index[].x;
  45. kk.y = index[].y;
  46. nxt.x = index[].x;
  47. nxt.y = index[].y;
  48. mmp[kk.x][kk.y] = false;
  49.  
  50. int len = abs(index[].x - index[].x);
  51. for(int i = ; i <= len; i++){
  52. kk.x++;
  53. if(mmp[kk.x][kk.y]) printf("%d %d\n", kk.x, kk.y);
  54. if(kk.x == index[].x){
  55. nxt.x = kk.x;
  56. nxt.y = kk.y;
  57. }
  58. mmp[kk.x][kk.y] = false;
  59. }
  60.  
  61. len = abs(index[].y - index[].y);
  62. for(int i = ; i <= len; i++){
  63. if(index[].y < index[].y) kk.y++;
  64. else kk.y--;
  65. if(mmp[kk.x][kk.y]) printf("%d %d\n", kk.x, kk.y);
  66. if(kk.y == index[].y){
  67. nxt.x = kk.x;
  68. nxt.y = kk.y;
  69. }
  70. mmp[kk.x][kk.y] = false;
  71. }
  72.  
  73. // printf("nxtx:%d nxty:%d\n", nxt.x, nxt.y);
  74.  
  75. len = abs(index[].y - nxt.y);
  76. for(int i = ; i <= len; i++){
  77. if(nxt.y < index[].y) nxt.y++;
  78. else nxt.y--;
  79. if(mmp[nxt.x][nxt.y]) printf("%d %d\n", nxt.x, nxt.y);
  80. mmp[nxt.x][nxt.y] = false;
  81. }
  82.  
  83. len = abs(index[].x - nxt.x);
  84. for(int i = ; i <= len; i++){
  85. nxt.x++;
  86. if(mmp[nxt.x][nxt.y]) printf("%d %d\n", nxt.x, nxt.y);
  87. mmp[nxt.x][nxt.y] = false;
  88. }
  89.  
  90. return ;
  91. }

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. 什么是web service (转)

    一.序言 大家或多或少都听过WebService(Web服务),有一段时间很多计算机期刊.书籍和网站都大肆的提及和宣传WebService技术,其中不乏很多吹嘘和做广告的成分.但是不得不承认的是Web ...

  2. IDEA创建一个Spring MVC 框架Java Web项目,Gradle构建

    注:此篇有些细节没写出,此文主要写重要的环节和需要注意的地方,轻喷 新建项目 选择Gradle , 勾选java 和 web.之后就是设定项目路径和名称,这里就不啰嗦了. build.gradle文件 ...

  3. git flow强制重新初始化

    Gitflow工作流定义了一个围绕项目发布的严格分支模型. git flow初始化命令: git flow init 关于各个分支的命名一路回车就可以了,如果不小心修改了默认的分支命名,后来又觉得不爽 ...

  4. 十三、nginx 强制下载txt等文件

    当前的浏览器能够识别文件格式,如果浏览器本身能够解析就会默认打开,如果不能解析就会下载该文件. 那么使用nginx做资源服务器的时候,如何强制下载文件呢? location /back/upload/ ...

  5. 8、springboot之定时任务

    @Configuration @EnableScheduling public class SchedulingConfig { @Scheduled(cron = "0/5 * * * * ...

  6. 一 NIO的概念

    Java NIO由下列几个核心部分组成: Channels(通道) Buffers(缓冲区) Asynchronous IO(异步IO) Channel 和 Buffer 基本上所有的IO在NIO中都 ...

  7. 域名解析成功后,怎样访问服务器上Eclipse中的Web工程

    右击工程选择Export-->选择Web文件夹下的WAR file-->Destination下选择文件存放的地址-->Finish就可以获得WAR文件了然后将WAR文件放到tomc ...

  8. 51nod 1135 原根(原根)

    题意 题目链接 Sol 可以证明素数的原根不会超过他的\(\frac{1}{4}\) 那么预处理出\(P - 1\)的所有的质因数\(p_1, p_2 \dots p_k\),暴力判断一下,如果$\e ...

  9. canvas合成图片 圣诞节新技能戴帽

    <!doctype html><html><head><meta charset="utf-8"><title>Html ...

  10. Git连接GitLab远程仓库

    1.简介 远程仓库是指托管在网络上的项目仓库,现在互联网上有很多项目托管平台,比如github.gitlab等.为了不公开自己项目代码,可以在自己的服务器上搭建自己的项目仓库,最常见的是搭建GitLa ...