From 5532c38725da4d86351846cc1dbd41a4adbafb3e Mon Sep 17 00:00:00 2001 From: go75 <2548604505@qq.com> Date: Sat, 27 Jan 2024 21:25:38 +0800 Subject: [PATCH] update --- blog/acwing/5459.md | 37 +++++++++++++++++++++++++ blog/acwing/92.md | 40 ++++++++++++++++++++++++++ blog/acwing/93.md | 57 ++++++++++++++++++++++++++++++++++++++ blog/acwing/94.md | 42 ++++++++++++++++++++++++++++ game/plane/index.html | 20 ++++++------- game/plane/model/bullet.js | 1 + game/plane/model/rock.js | 8 +++--- 7 files changed, 191 insertions(+), 14 deletions(-) create mode 100644 blog/acwing/5459.md create mode 100644 blog/acwing/92.md create mode 100644 blog/acwing/93.md create mode 100644 blog/acwing/94.md diff --git a/blog/acwing/5459.md b/blog/acwing/5459.md new file mode 100644 index 0000000..1a5ca13 --- /dev/null +++ b/blog/acwing/5459.md @@ -0,0 +1,37 @@ +@[toc] + +# 题目描述 +![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/5777efed6f7c4366a56451ccf0b45078.png) + +# 题解思路 +记录所有区间和区间对应的索引 + +按照区间左端点进行排序 + +然后遍历排序后的区间 + +如果当前区间的右端点相比于前一个区间的右端点 有所上升或者不变则输出当前区间的索引和前一个区间的索引,然后结束循环 + +如果当前区间的左端点等于前一个区间的左端点,则输出前一个区间的索引和当前区间的索引,然后结束循环 + +如果区间遍历完毕还没找到满足条件的区间,则输出-1, -1 + +# 题解代码 +```python +n = int(input()) +parts = [] +for i in range(n): + a, b = map(int, input().split()) + parts.append([a,b,i]) + +parts.sort() +for i in range(1, n): + if parts[i][1] <= parts[i-1][1]: + print(parts[i][2] + 1, parts[i-1][2] + 1) + break + if parts[i][0] == parts[i-1][0]: + print(parts[i-1][2] + 1, parts[i][2] + 1) + break +else: + print('-1 -1') +``` \ No newline at end of file diff --git a/blog/acwing/92.md b/blog/acwing/92.md new file mode 100644 index 0000000..40cb7fc --- /dev/null +++ b/blog/acwing/92.md @@ -0,0 +1,40 @@ +@[toc] + +# 题目描述 +![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/d4314d9e590b45d5bcda5ec14aaa6a47.png) + +# 题解思路 +本题相当于二叉树的深度优先遍历,树的第i层是第i个数选或不选 +我们记录当前递归的深度deep +然后用state进行状态压缩,state第i位是1表示选第i个数,第i位是0表示不选第i个数 +进行dfs +如果当前深度为n,则说明当前已经递归完前n层,此时将state对应要选择的数打印出来,然后返回 +深度加一 +state不变动,表示不选当前层对应的数,然后进行递归 +state当前位 置为1,表示选择当前层对应的数,然后进行递归 +深度减一 +state当前位 置为0 + +直到递归结束,程序退出 +# 题解代码 +```python +n = int(input()) +deep = 0 +state = 0 +def dfs(): + global deep + global state + if deep == n: + for i in range(n): + if state >> i & 1 == 1: + print(i + 1, end=' ') + print() + return + deep += 1 + dfs() + state = state | 1 << (deep - 1) + dfs() + deep -= 1 + state -= 1 << deep +dfs() +``` \ No newline at end of file diff --git a/blog/acwing/93.md b/blog/acwing/93.md new file mode 100644 index 0000000..ba27968 --- /dev/null +++ b/blog/acwing/93.md @@ -0,0 +1,57 @@ +@[toc] + +# 题目描述 +![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/9c12e263187842178f8d518d4b68ce30.png) + +# 题解思路 +本题相当于二叉树的深度优先遍历,树的第i层表示第i个数选或不选,当选择了m次左节点后退出 +我们记录当前递归的深度deep +然后用state进行状态压缩,state第i位是1表示选第i个数,第i位是0表示不选第i个数 +count表示我们选择数的个数 + +进行dfs + +当前还能选择的数的个数即n - deep,当前还应选择的数的个数即m - count +如果当前还能选择的数的个数小于当前还应选择的数的个数,则退出搜索 + +如果当前选择的数的个数为m,则说明当前数已经选完,此时将state对应要选择的数打印出来,然后返回 + +state当前位 置为1,深度加一,当前选择的数的个数加一,表示选择当前层对应的数,然后进行递归 + +恢复state和count当前层初始的state和count +进行递归 +深度减一 + +直到递归结束,程序退出 + +# 题解代码 +```python +n, m = map(int, input().split()) + +deep = 0 +state = 0 +count = 0 +def dfs(): + global deep + global state + global count + if n - deep < m - count: + return + if count == m: + for i in range(n): + if state >> i & 1 == 1: + print(i + 1, end = ' ') + print() + return + + state |= 1 << deep + deep += 1 + count += 1 + dfs() + state -= 1 << (deep - 1) + count -= 1 + + dfs() + deep -= 1 +dfs() +``` \ No newline at end of file diff --git a/blog/acwing/94.md b/blog/acwing/94.md new file mode 100644 index 0000000..39e585a --- /dev/null +++ b/blog/acwing/94.md @@ -0,0 +1,42 @@ +@[toc] + +# 题目描述 +![](https://img-blog.csdnimg.cn/direct/5c811d4e67254502b35e23799c871012.png) + +# 题解思路 +定义递归深度deep,数字使用情况used,选择的数字顺序path + +进行递归 + +终止条件为递归深度达到n层时,打印path,然后返回 + +深度加一 +遍历未使用的数字,选择数字,然后进行递归,递归结束,恢复used +恢复深度 + +直到整个递归结束,程序结束 +# 题解代码 +```python +n = int(input()) + +used = 0 +deep = 0 +path = [0 for _ in range(n)] +def dfs(): + global used + global deep + if deep == n: + for i in range(n): + print(path[i], end=' ') + print() + return + deep += 1 + for i in range(n): + if used >> i & 1 == 0: + path[deep - 1] = i + 1 + used |= 1 << i + dfs() + used -= 1 << i + deep -= 1 +dfs() +``` diff --git a/game/plane/index.html b/game/plane/index.html index 3bf7087..c737599 100644 --- a/game/plane/index.html +++ b/game/plane/index.html @@ -5,9 +5,9 @@ - + 醉墨编程 - +