补题链接:Here

A - Rock-paper-scissors

石头剪刀布,两方是一样的则输出该值,否则输出该值

int s[4] = {0, 1, 2};
void solve() {
int x, y;
cin >> x >> y;
if (x == y) cout << x;
else {
for (int i = 0; i < 3; i++)
if (s[i] != x && s[i] != y)
cout << s[i];
}
}

B - Nuts

坚果数超过 \(10\) 个便累加(x-10)

void solve() {
int n;
cin >> n;
int cnt = 0;
for (int i = 0, x; i < n; ++i) {
cin >> x;
if (x > 10)cnt += (x - 10);
}
cout << cnt;
}

C - Tour

\(n\) 个城市,\(m\) 条单向道路,请问在以每个城市为起点能有多少个终点(本身也算


\(n\le2000\) ,DFS 在图上搜索即可

const int N = 2e3 + 10;
vector<int>e[N];
bool vis[N];
void dfs(int u) {
if (vis[u])return ;
vis[u] = true;
for (int v : e[u])dfs(v);
}
void solve() {
int n, m; cin >> n >> m;
while (m--) {
int a, b; cin >> a >> b;
e[a].push_back(b);
}
int ans = 0;
for (int i = 1; i <= n; ++i) {
memset(vis, false, sizeof(vis));
dfs(i);
for (int j = 1; j <= n; ++j)if (vis[j])ans++;
}
cout << ans;
}

D - Cooking

两个微波炉,\(n\) 道菜,每个菜需要 \(a_i\) 分钟加热,请问最少需要多少时间才能把所有菜都加热完毕


烤箱的使用顺序无关紧要;只有为每道菜指定一个烤箱才是必要的。

考虑到根据要分配的两个烤箱中的哪一个将菜分为两组,该问题等价于“将N个菜分为两组,使烹调菜所需的最大次数之和最小化。”设为 \(t_1+…+t_n\)。我们可以假设第一个烤箱的占用时间不少于第二个烤箱的占用时间(如果不是,我们可以交换这两个烤箱)。然后,第一烤箱的使用持续时间至少为 \(S/2\) 。由于我们想在这个约束条件下尽可能减少使用第一台烤箱的时间,所以问题归结为“\(t_1…t_n\)的子集的最小和大于或等于 \(S/2\) 是多少?”如果我们能为每个x回答“ \(T_1,…,T_N\)的子集是否存在,这只不过是一个子集和问题,所以它可以在 \(\mathcal{O}(N\sum_iT_i)\) 的总和中找到∑ 具有以下布尔值的DP

bitset<100004>f;
void solve() {
int n; cin >> n;
int cnt = 0;
f[0] = 1;
for (int i = 0, x; i < n; ++i) {
cin >> x;
f |= f << x; cnt += x;
}
int ans = 1e9;
for (int i = 0; i < 1e5; ++i)if (f[i])ans = min(ans, max(i, cnt - i));
cout << ans;
}

E - Rush Hour 2

AtCoder王国有 \(n\) 个城市和 \(m\) 条双向道路

假设在 \(t\) 时刻经过了第 \(i\) 条道路,则通过的时间为 \(C_i + ⌊\frac{D_i}{t+1}⌋\)

现在请问最短的时间是多少,Takahashi 可以从城市 \(1\) 到达城市 \(n\) ,如果到达不了则输出 \(-1\)


利用优先队列跑 BFS,同时用 tuple 元组存储数据 (记得开启 C++17 来保证 tuple 可通过编译)

#define inf 9223372036854775807LL
#define N 100005
using ll = long long;
using Edge = tuple<int, int, int>;
using pli = pair<ll, int>;
vector<Edge> e[N];
ll dist[N];
void solve() {
int n, m;
cin >> n >> m;
while (m--) {
int a, b, c, d;
cin >> a >> b >> c >> d;
if (--a == --b)continue;
e[a].emplace_back(b, c, d);
e[b].emplace_back(a, c, d);
}
dist[0] = 0LL;
for (int i = 1; i < n; i++) dist[i] = inf;
priority_queue<pli, vector<pli>, greater<pli>>q;
q.emplace(0, 0);
while (!q.empty()) {
auto [t, u] = q.top();
q.pop();
if (dist[u] != t)continue;
for (auto [v, c, d] : e[u]) {
ll t2 = sqrt((long double) d) - 0.5;
if (t2 < t) t2 = t;
t2 += ll(c) + ll(d) / (t2 + 1ll);
if (t2 < dist[v])
q.emplace(dist[v] = t2, v); }
}
cout << (dist[n - 1] == inf ? -1 : dist[n - 1]) << endl;
}

AtCoder Beginner Contest 204 (AB水题,C题DFS,D题位运算DP,E题BFS好题)的更多相关文章

  1. AtCoder Beginner Contest 204

    身败名裂了,\(AK\)场转掉分场. 都是水题不说了. 这篇文鸽了.

  2. AtCoder Beginner Contest 087 D People on a Line(DFS)

    题意 给出n个点,m组关系L,R,D,L在R的左边距离D,判断是否存在n个人的位置满足m组关系 分析 Consider the following directed graph G: There ar ...

  3. AtCoder Beginner Contest 068 ABCD题

    A - ABCxxx Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement This contes ...

  4. AtCoder Beginner Contest 053 ABCD题

    A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...

  5. AtCoder Beginner Contest 223

    AtCoder Beginner Contest 223 A是纯纯的水题,就不说了 B - String Shifting 思路分析 我真的sb,一开始想了好久是不是和全排列有关,然后读了好几遍题目也 ...

  6. AtCoder Beginner Contest 184 题解

    AtCoder Beginner Contest 184 题解 目录 AtCoder Beginner Contest 184 题解 A - Determinant B - Quizzes C - S ...

  7. AtCoder Beginner Contest 052

    没看到Beginner,然后就做啊做,发现A,B太简单了...然后想想做完算了..没想到C卡了一下,然后还是做出来了.D的话瞎想了一下,然后感觉也没问题.假装all kill.2333 AtCoder ...

  8. AtCoder Beginner Contest 137 F

    AtCoder Beginner Contest 137 F 数论鬼题(虽然不算特别数论) 希望你在浏览这篇题解前已经知道了费马小定理 利用用费马小定理构造函数\(g(x)=(x-i)^{P-1}\) ...

  9. AtCoder Beginner Contest 075 C bridge【图论求桥】

    AtCoder Beginner Contest 075 C bridge 桥就是指图中这样的边,删除它以后整个图不连通.本题就是求桥个数的裸题. dfn[u]指在dfs中搜索到u节点的次序值,low ...

  10. AtCoder Beginner Contest 153 题解

    目录 AtCoder Beginner Contest 153 题解 A - Serval vs Monster 题意 做法 程序 B - Common Raccoon vs Monster 题意 做 ...

随机推荐

  1. 中间件IIS监控指标、配置和Windbg调试分析

    1. 关键性能计数器指标 a. Web服务(W3SVC)性能计数器 当前连接数(Current Connections):显示当前所有HTTP连接的数量.过高的数值可能表明网站流量过大或连接无法及时释 ...

  2. 每天5分钟复习OpenStack(十二)Ceph FileStore 和 BlueSotre

    一个最小化的Ceph集群需要三个组件MON MGR OSD.上一章我们部署了MON,本章节我们完成剩下MGR 和OSD 的部署.在文末我们将重点介绍下什么是FileStore和BlueStore,并详 ...

  3. lua面向对象(类)和lua协同线程与协同函数、Lua文件I/O

    -- create a class Animal={name = "no_name" , age=0 } function Animal:bark(voice) print(sel ...

  4. [THUPC 2023 初赛] 快速 LCM 变换

    题目描述 小 I 今天学习了快速最小公倍数变换(Fast Least-Common-Multiple Transform, FLT),于是他想考考你. 给定一个长度为 \(n\) 的正整数序列 \(r ...

  5. [ABC233G] Strongest Takahashi

    Problem Statement There is a $N \times N$ grid, with blocks on some squares. The grid is described b ...

  6. MybatisPlus最新代码生成器(version3.5.1+),自定义文件模板

    1.导入依赖(我这里用的是gradle构建工具,maven也一样啦~) plugins { id 'java' id 'org.springframework.boot' version '2.7.3 ...

  7. 2023计算机保研经验贴 直博向(南大cs,计算所,科大高研院,浙大cs,交大cs,国科cs,北大cs,清华cs)

    写在前面 本人作为普通选手,只能将个人经验分享一二,不能代表其他人的想法和意见,望路过的大佬们高抬贵手-,如果有相关老师或者同学认为我违反了保密条例请与我私信联系,我会第一时间删除相关内容. 个人情况 ...

  8. HTTP 代理服务器的设计与实现(C++)

    实验内容 设计并实现一个基本 HTTP 代理服务器.要求在指定端口(例如 8080)接收来自客户的 HTTP 请求并且根据其中的 URL 地址访问该地址 所指向的 HTTP 服务器(原服务器),接收 ...

  9. Linux SNMP监控配置

    1, 安装SNMP服务 [root@zlm log]# yum -y install net-snmp net-snmp-utils 2, 编辑SNMP配置文件[root@zlm log]# vim ...

  10. proxy代理实现接口调用处理

    proxy代理实现接口调用处理 我们知道,要调用接口必须要实例化才能调用. 那么我们能不能不实例化调用呢?像mybatis.hibernate那样定义一个接口就能注入调用.其实他们的底层实现就是用代理 ...