Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
zm50 committed Jan 27, 2024
1 parent 7a6ac08 commit 5532c38
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 14 deletions.
37 changes: 37 additions & 0 deletions blog/acwing/5459.md
Original file line number Diff line number Diff line change
@@ -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')
```
40 changes: 40 additions & 0 deletions blog/acwing/92.md
Original file line number Diff line number Diff line change
@@ -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()
```
57 changes: 57 additions & 0 deletions blog/acwing/93.md
Original file line number Diff line number Diff line change
@@ -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()
```
42 changes: 42 additions & 0 deletions blog/acwing/94.md
Original file line number Diff line number Diff line change
@@ -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()
```
20 changes: 10 additions & 10 deletions game/plane/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="/assets/img/favicon.ico">
<link rel="stylesheet" type="text/css" href="/assets/style/style.css">
<link rel="stylesheet" type="text/css" href="../../assets/style/style.css">
<title>醉墨编程</title>
<link rel="stylesheet" href="/game/plane/style/style.css">
<link rel="stylesheet" href="./style/style.css">
</head>
<header>
<nav>
Expand All @@ -24,14 +24,14 @@
<div id="score">0</div>
<div id="hp"></div>
</div>
<script src="/game/plane/game/init.js"></script>
<script src="/game/plane/model/controls.js"></script>
<script src="/game/plane/model/image.js"></script>
<script src="/game/plane/model/rock.js"></script>
<script src="/game/plane/model/bullet.js"></script>
<script src="/game/plane/model/player.js"></script>
<script src="/game/plane/game/flush.js"></script>
<script src="/game/plane/game/main.js"></script>
<script src="./game/init.js"></script>
<script src="./model/controls.js"></script>
<script src="./model/image.js"></script>
<script src="./model/rock.js"></script>
<script src="./model/bullet.js"></script>
<script src="./model/player.js"></script>
<script src="./game/flush.js"></script>
<script src="./game/main.js"></script>
</body>

</html>
1 change: 1 addition & 0 deletions game/plane/model/bullet.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function crashProcess() {
if (bullet.cross(rock)) {
let randNum = Math.random()
if (randNum < TOOL_PROBABILITY) {
rock.rotate(0)
if (randNum < TOOL_PROBABILITY / 2) {
rock.img.src = SHIELD_SRC
rock.type = 1
Expand Down
8 changes: 4 additions & 4 deletions game/plane/model/rock.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,20 @@ function updateRocks() {
for (let i = 0; i < ROCK_COUNT; i++) {
let rock = rocks[i]
rock.move()

if (rock.type == 0) {
let angle = (rock.angle + 2) % 360
rock.rotate(angle)
}
if (rock.cross(player)) {
switch (rock.type) {
// rock
case 0:
let angle = (rock.angle + 2) % 360
rock.rotate(angle)
player.hp -= ROCK_HURT
if (player.hp <= 0) {
player.gameOver()
return
}
hp.style.width = player.hp + 'px'

break

// shield
Expand Down

0 comments on commit 5532c38

Please sign in to comment.