Skip to content

Commit

Permalink
add BUAAOJ5352
Browse files Browse the repository at this point in the history
  • Loading branch information
GoatGirl98 committed Jan 13, 2024
1 parent 60432e6 commit 8673d77
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,8 @@ YES

不超过2步,DFS就完事了

需要注意,dfs时要么判断当前数是否访问过,要么就要判断不能直接掉头(比如上一步是向上走这一步就向下走),这样的话就不需要一个访问数组了,因为转完两次是不可能掉头回到已经访问过的数的。

# `J` microhhh的回文词(难)

时间限制:1000ms 内存限制:65536kb
Expand Down
3 changes: 3 additions & 0 deletions 2020级-软件学院-算法分析与设计/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 2020级-软件学院-算法分析与设计

有一道期末的题开放了,故进行收录。
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include <iostream>
#include <sstream>
#include <bitset>
#include <string>
#define putchar putchar_unlocked
using namespace std;
const int N = 2501;
int T;
int n;
// pow_3[n] = 3^(n - 1)
int pow_3[10] = {0, 1, 3, 9, 27, 81, 243, 729, 2187};
bitset<N> a[N];
bitset<3> origin[3];
string s;
void init()
{
for (int i = 0; i < pow_3[n]; ++i)
a[i].reset();
for (int i = 0; i < 3; ++i)
origin[i].reset();
}
void dfs(int n, int x, int y)
{
if (n == 1)
{
a[x].set(y);
return;
}
int len = pow_3[n - 1];
for (int i = 0; i < 3; ++i)
for (int j = 0; j < 3; ++j)
if (origin[i].test(j))
dfs(n - 1, x + i * len, y + j * len);
}
int main()
{
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
getline(cin, s);
stringstream _T(s);
_T >> T;
while (T--)
{
init();
getline(cin, s);
stringstream _n(s);
_n >> n;
for (int i = 0; i < 3; ++i)
{
getline(cin, s);
while (s.back() == '\r')
s.pop_back();
for (int j = 0; j < s.length(); ++j)
if (s[j] == 'o')
origin[i].set(j);
}
dfs(n, 0, 0);
int len = pow_3[n];
for (int i = 0; i < len; ++i, putchar('\n'))
for (int j = 0; j < len; ++j)
putchar(a[i].test(j) ? 'o' : ' ');
putchar('\n');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# T1-20级算法第1次期末测试

# 分形图2

时间限制: 1000 ms 内存限制: 65536 kb

总通过人数: 8 总提交人数: 13

## 题目背景

分形通常被定义为“一个粗糙或零碎的几何形状,可以分成数个部分,每个部分都是(至少近似是)整体缩小后的形状”,即具有自相似的形状。

某种分形定义如下:

度为 $n=1$ 时:

```
o
```

度为 $n=2$ 时:

```
o
ooo
o
```

度为 $n=3$ 时:

```
o
ooo
o
o o o
ooooooooo
o o o
o
ooo
o
```

## 题目描述

给定字符 `o`,度为 $2$ 时的分形,输出其度为 $n(1≤n≤8)$ 时的分形。

## 输入

输入包含多组数据(不超过10组)。

第一行是数据组数 $m$ ,从第二行开始为具体的数据。每组数据第一行是度数 $n$ ,后面三行是度为 $2$ 时的分形。

## 输出

对每组数据,输出度数 $n$ 对应的分形,并在分形最后输出一个空行。

## 样例输入

```
2
3
o
ooo
o
3
o o
o
o o
```

## 样例输出

```
o
ooo
o
o o o
ooooooooo
o o o
o
ooo
o
o o o o
o o
o o o o
o o
o
o o
o o o o
o o
o o o o
```

## Hint1

`char *gets(char *str)` 函数在执行过程中不会对边界进行检查,极其容易受到缓冲区溢出的攻击。因此,在 C++11 中该函数已经被移除。

对于使用 C++ 完成本题并希望使用上述函数的同学,请使用以下两个更为安全的函数作为替代:

```
char *gets_s(char *str, rsize_t n);
char *fgets( char *restrict str, int count, FILE *restrict stream);
```

## Hint2

在 Windows 下,默认的换行符是 `CRLF`,而在 Linux(评测机)中,默认换行符为 `LF`

## 思路

基础的分治递归。然后由于只需要记录每个格子是否要输出 `o` ,我们可以将二维 `bool` 数组改成 `bitset` 数组以进行空间优化。然后就是处理字符串的时候,`getline` 需要特判一下处理行末 `\r` 的问题。

0 comments on commit 8673d77

Please sign in to comment.