Educational Codeforces Round 85 (Div. 2)
题目链接:https://codeforces.com/contest/1334
A. Level Statistics
题意
一个关卡有玩家的尝试次数和通关次数,按时间顺序给出一个玩家 $n$ 个时刻的数据,判断这些数据是否合理。
思路
- 通关次数不会多于尝试次数:$c_i≤p_i$
- 后一时刻的尝试次数不会多于前一时刻:$p_i≤p_{i-1}$
- 后一时刻的通关次数不会多于前一时刻:$c_i≤c_{i-1}$
- 增加的通关次数不会多于增加的尝试次数:$c_i-c_{i-1}≤p_i-p_{i-1}$
代码
#include <bits/stdc++.h>
using namespace std; void solve() {
int n; cin >> n;
int p[n], c[n];
for (int i = 0; i < n; i++) {
cin >> p[i] >> c[i];
}
for (int i = 0; i < n; i++) {
if (c[i] > p[i]) {
cout << "NO" << "\n";
return;
}
}
for (int i = 1; i < n; i++) {
if (p[i] < p[i - 1] || c[i] < c[i - 1] || c[i] - c[i - 1] > p[i] - p[i - 1]) {
cout << "NO" << "\n";
return;
}
}
cout << "YES" << "\n";
} int main() {
int t; cin >> t;
while (t--) solve();
}
B. Middle Class
题意
已知 $n$ 个人财富值,可以不限次地选取一些人将他们的财富值汇总后平均分配,问最后最多有多少人财富值不少于 $x$ 。
思路
降序排列,分配多余的财富值,第一次不能凑齐 $x$ 时之前的人数即为答案。
代码
#include <bits/stdc++.h>
using ll = long long;
using namespace std; void solve() {
int n, x; cin >> n >> x;
int a[n]; for (int & i : a) cin >> i;
sort(a, a + n, greater<int>());
ll extra = 0, ans = 0;
for (int i : a) {
if (i >= x) {
extra += i - x;
++ans;
} else if (extra >= x - i) {
extra -= x - i;
++ans;
}
}
cout << ans << "\n";
} int main() {
int t; cin >> t;
while (t--) solve();
}
C. Circle of Monsters
题意
有一圈怪兽,每个怪兽有 $a_i$ 点生命值,每射击 $1$ 次怪兽会掉 $1$ 点生命值,当怪兽死亡时会对下一个怪兽造成 $b_i$ 点伤害,要想消灭所有怪兽最少需要射击多少次。
思路
先求出至少需要射击多少次,即 $\sum_{i=0}^{n-1}a[i] - b[i-1]$,然后枚举以哪只怪兽为起点,取总和的最小值即可。
代码
#include <bits/stdc++.h>
#define pre(i) ((i - 1 + n) % n)
using ll = long long;
using namespace std; void solve() {
int n; cin >> n;
ll a[n], b[n];
for (int i =0 ; i < n; i++) {
cin >> a[i] >> b[i];
}
ll sum = 0;
for (int i = 0; i < n; i++) {
sum += max(0LL, a[i] - b[pre(i)]);
}
ll ans = 1e18;
for (int i = 0; i < n; i++) {
if (a[i] > b[i]) {
ans = min(ans, sum + b[i]);
} else {
ans = min(ans, sum + a[i]);
}
}
cout << ans << "\n";
} int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t; cin >> t;
while (t--) solve();
}
D. Minimum Euler Cycle
题意
求一个 $n$ 点完全有向图字典序最小的欧拉回路的一段区间。
如果图G中的一个路径包括每个边恰好一次,则该路径称为欧拉路径(Euler path)。如果一个回路是欧拉路径,则称为欧拉回路(Euler circuit)。
思路
因为是求字典序最小的回路,所以我们每次可以通过折返先走完较小的点,比如 $4$ 个点时:
每次以 1 为起点:1 2 1 3 1 4
每次以 2 为起点:2 3 2 4
每次以 3 为起点:3 4
回到 1 构成回路:1
- 观察发现前 $n-1$ 个区间长度为等差数列,即 $len_i=2*(n-i)$,
- 所以我们可以用前缀和 $pre\_sum$ 记录到每个区间时的元素总个数,之后可以据此用 $lower\_bound$ 二分查找第 $i$ 个元素所在的区间编号 $seg\_num$ 。
- 确认区间后,该元素编号减去之前区间的元素总个数即为该元素在该区间内的编号,即 $num = i - pre\_sum[seg\_num-1]$ 。
- 观察每个区间,因为是反复折返一个点,所以该区间内的奇数元素大小都等于 $seg\_num$,偶数元素大小等于 $seg\_num + num / 2$ 。
- 最后特判 $i > pre\_sum[n-1]\ return\ 1$ 即可。
代码
#include <bits/stdc++.h>
using ll = long long;
using namespace std; const int M = 1e5+100;
ll n, l, r, pre_sum[M]; int cal(ll x) {
if (x > pre_sum[n - 1]) return 1;
int seg_num = lower_bound(pre_sum, pre_sum + n, x) - pre_sum;
int num = x - pre_sum[seg_num - 1];
if (num & 1) return seg_num;
else return seg_num + num / 2;
} void solve() {
cin >> n >> l >> r;
for (int i = 1; i < n; i++) {
pre_sum[i] = pre_sum[i - 1] + 2 * (n - i);
}
for (ll i = l; i <= r; i++) {
cout << cal(i) << " \n"[i==r];
}
} int main() {
int t; cin >> t;
while (t--) solve();
}
D题代码参考自:MiFaFaOvO(dlstxdy)。
Educational Codeforces Round 85 (Div. 2)的更多相关文章
- Educational Codeforces Round 85 (Rated for Div. 2)
\(Educational\ Codeforces\ Round\ 85\ (Rated\ for\ Div.2)\) \(A. Level Statistics\) 每天都可能会有人玩游戏,同时一部 ...
- Educational Codeforces Round 84 (Div. 2)
Educational Codeforces Round 84 (Div. 2) 读题读题读题+脑筋急转弯 = =. A. Sum of Odd Integers 奇奇为奇,奇偶为偶,所以n,k奇偶性 ...
- Educational Codeforces Round 58 Div. 2 自闭记
明明多个几秒就能场上AK了.自闭. A:签到. #include<iostream> #include<cstdio> #include<cmath> #inclu ...
- Educational Codeforces Round 47 (Div 2) (A~G)
目录 Codeforces 1009 A.Game Shopping B.Minimum Ternary String C.Annoying Present D.Relatively Prime Gr ...
- Educational Codeforces Round 46 (Div 2) (A~G)
目录 Codeforces 1000 A.Codehorses T-shirts B.Light It Up C.Covered Points Count(差分) D.Yet Another Prob ...
- Educational Codeforces Round 45 (Div 2) (A~G)
目录 Codeforces 990 A.Commentary Boxes B.Micro-World C.Bracket Sequences Concatenation Problem D.Graph ...
- Educational Codeforces Round 86 (Div. 2)
比赛链接:https://codeforces.com/contest/1342 A - Road To Zero 题意 有两个非负整数 x, y 以及两种操作: 支付 a 点代价使其中一个数加一或减 ...
- Educational Codeforces Round 119 (Div. 2), (C) BA-String硬着头皮做, 能做出来的
题目链接 Problem - C - Codeforces 题目 Example input 3 2 4 3 a* 4 1 3 a**a 6 3 20 **a*** output abb abba b ...
- Educational Codeforces Round 108 (Div. 2), C map套vector存储
地址 Problem - C - Codeforces 题目 题意 一个学校有n个人参加比赛,他们分别属于ui队,每个人的能力值为si 当每个队需要1~n个人的时候,这个学校能参加的人的能力值和最大 ...
随机推荐
- Unity优化 1
浅谈Unity中的GC以及优化(转) Unity 官方文档,正巧在博客园发现了已经有位大神(zblade)把原文翻译出来了,而且质量很高~,译文地址 在这里.下面我就可耻地把译文搬运了过来,作为上面思 ...
- 【Oracle】sum(..) over(..)用法分析
今天再看sql优化详解的时候,提到了一个sum(..) over(..) 于是自己实验并在网上找了相关的一些文章来看 下面创建一张表: create sequence xulie increment ...
- [java]文件上传下载删除与图片预览
图片预览 @GetMapping("/image") @ResponseBody public Result image(@RequestParam("imageName ...
- 利用容器逃逸实现远程登录k8s集群节点
某天, 某鱼说要吃瞄, 于是...... 李国宝:边缘计算k8s集群SuperEdge初体验 zhuanlan.zhihu.com 图标 照着上一篇文章来说,我这边边缘计算集群有一堆节点. 每个节 ...
- Poj-P1088题解【动态规划/记忆化搜索】
本文为原创,转载请注明:http://www.cnblogs.com/kylewilson/ 题目出处: http://poj.org/problem?id=1088 题目描述: 区域由一个二维数组给 ...
- Flask之静态文件处理
静态文件的处理 推荐 from flask import Flask,render_template app = Flask(__name__,template_folder='templates', ...
- GlusterFS分布式存储系统复制集更换故障Brick操作记录
场景: GlusterFS 3节点的复制集,由于磁盘故障,其中一个复制集需要重装系统,所以需要重装glusterfs并将该节点加入glusterfs集群 一. 安装GlusterFS 首先在重装系统节 ...
- Frame of Reference and Roaring Bitmaps
https://www.elastic.co/cn/blog/frame-of-reference-and-roaring-bitmaps http://roaringbitmap.org/ 2015 ...
- xftp 提示无法显示远程文件夹
在用xftp远程服务器,打开文件夹的时候一直提示"无法显示远程文件夹" 解决方案: 1.网上大多解决方案是文件->属性->选项->将使用被动模式选项去掉即可 2. ...
- Spring Boot中进行Junit测试
Spring Boot新版本默认使用Junit5,pom依赖为: <dependency> <groupId>org.springframework.boot</grou ...