首页 技术 正文
技术 2022年11月7日
0 收藏 785 点赞 1,087 浏览 1104 个字

画图时思路应该清晰一点。我是将坐标\((x,y)\)映射到\(canvas[y][x]\)上。

连线注意\(+\)号的情况,填充写好\(dfs\)就好了。

#include <bits/stdc++.h>
const int maxn = 100;using namespace std;int m, n, q;
char canvas[maxn + 5][maxn + 5];int vis[maxn + 5][maxn + 5];int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};void dfs(int x, int y, char c)
{
if (vis[y][x])
return;
vis[y][x] = 1;
canvas[y][x] = c;
for (int i = 0; i <= 3; i++)
{
int xx = x + dir[i][0], yy = y + dir[i][1];
if (xx >= 0 && xx <= m - 1 && yy >= 0 && yy <= n - 1 &&
canvas[yy][xx] != '|' && canvas[yy][xx] != '-' && canvas[yy][xx] != '+')
dfs(xx, yy, c);
}
}int main()
{
scanf("%d%d%d", &m, &n, &q);
for (int i = 0; i <= n - 1; i++)
for (int j = 0; j <= m - 1; j++)
canvas[i][j] = '.'; while (q--)
{
int op;
scanf("%d", &op);
if (op == 0)
{
int x1, y1, x2, y2;
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
if (x1 == x2)
{
for (int i = min(y1, y2); i <= max(y1, y2); i++)
{
if (canvas[i][x1] == '-' || canvas[i][x1] == '+')
canvas[i][x1] = '+';
else
canvas[i][x1] = '|';
}
}
else
{
for (int i = min(x1, x2); i <= max(x1, x2); i++)
{
if (canvas[y1][i] == '|' || canvas[y1][i] == '+')
canvas[y1][i] = '+';
else
canvas[y1][i] = '-';
}
}
}
else
{
int x, y;
char c[2];
scanf("%d%d%s", &x, &y, c);
memset(vis, 0, sizeof(vis));
dfs(x, y, c[0]);
}
} for (int i = n - 1; i >= 0; i--)
{
for (int j = 0; j <= m - 1; j++)
printf("%c", canvas[i][j]);
printf("\n");
} return 0;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,082
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,556
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,406
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,179
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,815
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,898