AtCoder abc 144

文章讲述了三个编程题目:D-WaterBottlex涉及计算水的面积和体积,E-Gluttony要求找到数组两两相乘积不超过限制的最大值,F-ForkintheRoad讨论了在给定图中删除一条边以优化期望值的问题。文章使用Python和相关库解决这些问题,运用了排序、二分查找和动态规划策略。

D - Water Bottle
x先除以a,得到面积。体积和面积是等同考虑的。
分两种情况,一种是水比一半面积少,一种是水比一半面积多。

# -*- coding: utf-8 -*-
# @time     : 2023/6/2 13:30
# @author   : yhdu@tongwoo.cn
# @desc     :
# @file     : atcoder.py
# @software : PyCharm

import bisect
import copy
import sys
from sortedcontainers import SortedList
from collections import defaultdict, Counter, deque
from functools import lru_cache, cmp_to_key
import heapq
import math
sys.setrecursionlimit(50050)


def main():
    items = sys.version.split()
    if items[0] == '3.10.6':
        fp = open("in.txt")
    else:
        fp = sys.stdin
    a, b, x = map(int, fp.readline().split())
    x /= a
    if x >= 0.5 * a * b:
        y = 2 * (a * b - x) / a
        t = (math.atan2(y, a) / math.pi) * 180
        print(t)
    else:
        y = 2 * x / b
        t = (math.atan2(y, b) / math.pi) * 180
        print(90 - t)


if __name__ == "__main__":
    main()

E - Gluttony
等价于求两个数组
a1,a2...anb1,b2...bna_1,a_2...a_n \\ b_1,b_2...b_na1,a2...anb1,b2...bn
求数组元素的两两相乘积最大值不能超过L的解法,并求L的最小值。
当你看到求数组某函数最大值的最小值,并且毫无头绪的时候,就应该想到二分。

元素两两相乘的积很明显的应该从a正序,b倒序进行相乘,此时可以保证L最小。如果不满足性质,那么将a扣掉份额。最后累计要扣掉的份额,计算是否满足题目需求。

# -*- coding: utf-8 -*-
# @time     : 2023/6/2 13:30
# @author   : yhdu@tongwoo.cn
# @desc     :
# @file     : atcoder.py
# @software : PyCharm

import bisect
import copy
import sys
from sortedcontainers import SortedList
from collections import defaultdict, Counter, deque
from functools import lru_cache, cmp_to_key
import heapq
import math
sys.setrecursionlimit(50050)


def main():
    items = sys.version.split()
    if items[0] == '3.10.6':
        fp = open("in.txt")
    else:
        fp = sys.stdin
    n, k = map(int, fp.readline().split())
    a = list(map(int, fp.readline().split()))
    b = list(map(int, fp.readline().split()))
    a.sort()
    b.sort(reverse=True)

    def check(x):
        ret = 0
        for i in range(n):
            if a[i] * b[i] <= x:
                continue
            ret += a[i] - x // b[i]
        return ret <= k

    lo, hi = 0, 10 ** 13
    while lo < hi:
        mi = (lo + hi) // 2
        if check(mi):
            hi = mi
        else:
            lo = mi + 1
    print(lo)


if __name__ == "__main__":
    main()

F - Fork in the Road
普通不删点的dp不难想到。
N=600下,枚举每条可能删的边会超时。但是由于只需要删一条边,因此针对每个点,只可能是它期望值最大的子节点和它之间的那条边被删掉。
因此暴力求解即可。

# -*- coding: utf-8 -*-
# @time     : 2023/6/2 13:30
# @author   : yhdu@tongwoo.cn
# @desc     :
# @file     : atcoder.py
# @software : PyCharm

import bisect
import copy
import sys
from sortedcontainers import SortedList
from collections import defaultdict, Counter, deque
from functools import lru_cache, cmp_to_key
import heapq
import math
sys.setrecursionlimit(50050)


def main():
    items = sys.version.split()
    if items[0] == '3.10.6':
        fp = open("in.txt")
    else:
        fp = sys.stdin
    n, m = map(int, fp.readline().split())
    g = [[] for _ in range(n)]
    f = [0] * n
    a = [0] * n

    def calc(pt: int):
        mx, sel = -1, -1
        if len(g[pt]) == 1:
            return 1e18
        for i in g[pt]:
            if a[i] > mx:
                mx, sel = a[i], i
        for i in range(n - 2, -1, -1):
            f[i] = 0
            c = 0
            for j in g[i]:
                if i == pt and j == sel:
                    continue
                f[i] += f[j]
                c += 1
            f[i] = f[i] / c + 1
        return f[0]

    for i in range(m):
        u, v = map(int, fp.readline().split())
        u, v = u - 1, v - 1
        g[u].append(v)

    for i in range(n - 2, -1, -1):
        a[i] = 0
        for j in g[i]:
            a[i] += a[j]
        a[i] = a[i] / len(g[i]) + 1
    ans = a[0]
    for i in range(n - 1):
        ans = min(ans, calc(i))
    print(ans)


if __name__ == "__main__":
    main()

关于 AtCoder Beginner Contest 387 的信息如下: ### 关于 AtCoder Beginner Contest 387 AtCoder Beginner Contest (ABC) 是一项面向编程爱好者的定期在线竞赛活动。对于 ABC387,该赛事通常会在周末举行,并持续大约100分钟,在此期间参赛者需解决一系列算法挑战问题。 #### 比赛详情 - **举办平台**: AtCoder Online Judge System[^2] - **比赛时间长度**: 大约为1小时40分钟 - **难度级别**: 初学者友好型,适合那些刚开始接触竞争性程序设计的人群参与 - **题目数量**: 一般情况下会提供四到六道不同难度级别的题目供选手解答 #### 题目概览 虽然具体细节可能因官方发布而有所变化,但可以预期的是,这些题目将会覆盖基础的数据结构、字符串处理以及简单图论等方面的知识点。每一道题目的描述都会清晰给出输入输出格式说明及样例测试数据以便理解需求并验证解决方案的有效性。 为了获取最准确的比赛时间和确切的题目列表,请访问 [AtCoder 官方网站](https://atcoder.jp/) 并查看最新的公告板或直接导航至对应编号的具体页面来获得更新的信息。 ```python import requests from bs4 import BeautifulSoup def get_contest_info(contest_id): url = f"https://atcoder.jp/contests/{contest_id}" response = requests.get(url) if response.status_code == 200: soup = BeautifulSoup(response.text, 'html.parser') title_element = soup.find('title') problem_list_elements = soup.select('.panel.panel-default a[href^="/contests/{}/tasks"]'.format(contest_id)) contest_title = title_element.string.strip() if title_element else "Contest Title Not Found" problems = [element['href'].split('/')[-1] for element in problem_list_elements] return { "name": contest_title, "problems": problems } else: raise Exception(f"Failed to fetch data from {url}") abc_387_details = get_contest_info("abc387") print(abc_387_details) ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值