[acwing周赛复盘] 第 61 场周赛20220723
一、本周周赛总结
- 第三题几何题,先再草稿纸上推了半天公式,又去现场查python保留几位小数怎么写。
- 最后还是wa半天。
- 而且第三题答案不唯一。
二、 4497. 分糖果
链接: 4497. 分糖果
1. 题目描述
2. 思路分析
定级Easy。
签到题,就硬写。
3. 代码实现
import io
import os
import sys
from collections import deque
if os.getenv('LOCALTESTACWING'):
sys.stdin = open('input.txt')
if __name__ == '__main__':
T = int(input())
for _ in range(T):
a,b,c = map(int, input().split())
print((a+b+c)//2)
三、4498. 指针
链接: 4498. 指针
1. 题目描述
2. 思路分析
- 一开始没好思路,看了下数据范围15,那么直接dfs枚举。
3. 代码实现
import io
import os
import sys
from collections import deque
if os.getenv('LOCALTESTACWING'):
sys.stdin = open('input.txt')
if __name__ == '__main__':
n = int(input())
arr = []
for _ in range(n):
arr.append(int(input()))
m = len(arr)
def dfs(index, s):
if index == m:
if s % 360 == 0:
return True
return False
if dfs(index + 1, s + arr[index]):
return True
return dfs(index + 1, s - arr[index])
print('YES' if dfs(0, 0) else 'NO')
四、4499. 画圆
链接: 4499. 画圆
1. 题目描述
2. 思路分析
几何题。
- 条件一代表你的圆要在给定圆(x1,y1,R)内。
- 条件二代表你的圆不能覆盖给定点(x2,y2),但可以接触(定着它)。
- 条件三代表你的圆要尽可能大,那么也就是说你的圆要顶着这个点使劲膨胀。
- 特判如果给定点不在圆内,那我们能构造的圆就是给定圆,直接调整小数点输出即可。
- 如果在圆内,且是圆心,那我们的圆直径就是给定圆的半径,显然圆心位置在圆里绕着给定圆心滚动即可随便取,无限种可能,这里把y固定。
- 剩下的情况就需要套公式,可以看我下边的图,代码直接套结论。
3. 代码实现
import io
import os
import sys
from collections import deque
if os.getenv('LOCALTESTACWING'):
sys.stdin = open('input.txt')
def sovle(R, x1, y1, x2, y2):
if (y1 - y2) ** 2 + (x1 - x2) ** 2 >= R ** 2:
return print("%.6f" % (x1 * 1.0), "%.6f" % (y1 * 1.0), "%.6f" % (R * 1.0))
if x1 == x2 and y1 == y2:
return print("%.6f" % ((x1 + R/2) ), "%.6f" % (y1 * 1.0), "%.6f" % (R / 2))
c = ((y1 - y2) ** 2 + (x1 - x2) ** 2) ** 0.5
c2 = c + R
y3 = (y2 - c2 * (y2 - y1) / c)
x3 = (x2 - c2 * (x2 - x1) / c)
y4 = (y3 + y2) / 2
x4 = (x3 + x2) / 2
r = c2 / 2
print("%.6f" % x4, "%.6f" % y4, "%.6f" % r)
if __name__ == '__main__':
R, x1, y1, x2, y2 = map(int, input().split())
sovle(R, x1, y1, x2, y2)
六、参考链接
- 无