Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round 4) C. Connect Three 【模拟】
传送门:http://codeforces.com/contest/1087/problem/C
C. Connect Three
1 second
256 megabytes
standard input
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.
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.
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.
0 0
1 1
2 2
5
0 0
1 0
1 1
1 2
2 2
0 0
2 0
1 1
4
0 0
1 0
1 1
2 0
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 【模拟】的更多相关文章
- (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 ...
- 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++ ...
- 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/ ...
- 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 ...
- 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 ...
- 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 个数,对于一个选定的区间,区间内的数可以通过重新排列二进制数的位置得到一个新的数,问 ...
- Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3)B. Personalized Cup
题意:把一长串字符串 排成矩形形式 使得行最小 同时每行不能相差大于等于两个字符 每行也不能大于20个字符 思路: 因为使得行最小 直接行从小到大枚举即可 每行不能相差大于等于两个字符相当于 ...
- 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( ...
- 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坐标至少有一个整点的时 以及 给出的直线才有路径(也就是格子坐标图的线上) 问 两个整点所需要 ...
随机推荐
- easyui导出当前datagrid数据(含表头)
JS代码 //导出当前DataGrid数据 function doExportCommon() { var list = getCheckedRowCommon(); var exportList = ...
- IDEA启动Jetty报404
在别的电脑上是OK的,到本机就不行了,很可能是Working路径的问题. 设置这里的路径即可:(你的web模块路径)
- Lucene学习之四:Lucene的索引文件格式(2)
本文转载自:http://www.cnblogs.com/forfuture1978/archive/2009/12/14/1623599.html 略有删减和补充 四.具体格式 上面曾经交代过,L ...
- npm proxy报错处理
npm经常抽风,动不动安装一个模块就这样了: 提示是否设置了正确的代理地址,解决方法网上有很多,有说取消代理.重新设置代理等等,最简单粗暴解决: 删除nodejs安装路径下面的npmrc文件,再使用淘 ...
- 设置固定ip后无法上公网
把电脑ip设置成固定ip后,发现其不能上公网,突然想到要设置DNS. 运行cmd程序,输入命令ipconfig /all查看此网络的DNS,设置固定ip 时添加此DNS地址即可.
- Effective C++ .09 不在构造和析构过程中调用virtual函数
看过C++对象模型的话就可以知道,在构造基类时,完整的vtable没有建立起来(表项没有被相应的子类函数替换),因而无法调用到子类的函数(即构造函数中的virtual函数是本类里的方法,不是virtu ...
- (1-3)line-height与图片的表现
(1-3)line-height与图片的表现 这篇文章真的很重要,耐心看,重中之重. 一.行高和图片的表现 图片和行高有什么歪腻呢?? 很多人不明白,为什么我图片好好的放在一个标签里面它就出现了如下问 ...
- 教你小三角,适用移动端等,解决移动端a标签的默认样式
1.小三角,通过给一个div设置足够大的边框,让它的上边框,右边框,左边框,的背景颜色设置成透明的,来实现,如下: <!DOCTYPE html> <html> <hea ...
- 配合sublime使用flexible.js实现微信开发页面自适应
什么是flexible.js 是一个终端设备适配的解决方案.也就是说它可以让你在不同的终端设备中实现页面适配. 是一个用来适配移动端的javascript框架.根据宽度的不同设置不同的字体大小,样式间 ...
- 注册表----修改Win7登录界面
在进行操作前,需要准备好背景图片.对背景图片的要求有三点: (1)图片必须是JPG格式: (2)必须将图片命名为backgroundDefault; (3)图片的体积必须小于256KB. 按下[Win ...