Educational Codeforces Round 87 (Rated for Div. 2)
比赛链接:https://codeforces.com/contest/1354
A - Alarm Clock
题意
一个人要睡够 $a$ 分钟,一开始睡 $b$ 分钟后闹钟响铃,之后每次设置 $c$ 分钟后响铃,设置好后需要 $d$ 分钟入睡。
题解
首先判断能不能一开始就睡足 $a$ 分钟,如果不能判断能不能入睡,如果可以用需要补睡的时间对每次可以睡着的时间取上整。
代码
#include <bits/stdc++.h>
using ll = long long;
using namespace std; void solve() {
ll a, b, c, d; cin >> a >> b >> c >> d;
if (b >= a) {
cout << b << "\n";
} else {
ll need = a - b;
if (c <= d)
cout << -1 << "\n";
else
cout << b + c * ((need + c - d - 1) / (c - d)) << "\n";
}
} int main() {
int t; cin >> t;
while (t--) solve();
}
B - Ternary String
题意
字符串 $s$ 由 1,2,3 组成,输出包含 1,2,3 的最短连续子串。
题解
记录 1,2,3 的位置,枚举 1,2,3 的前后关系即可。
代码
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9; void solve() {
string s; cin >> s;
vector<int> pos[3];
for (int i = 0; i < s.size(); i++) {
pos[s[i] - '1'].push_back(i);
}
int p[3] = {0, 1, 2};
int ans = INF;
do {
for (int a : pos[p[0]]) {
auto b = upper_bound(pos[p[1]].begin(), pos[p[1]].end(), a);
if (b == pos[p[1]].end()) break;
auto c = upper_bound(pos[p[2]].begin(), pos[p[2]].end(), *b);
if (c == pos[p[2]].end()) break;
ans = min(ans, *c - a + 1);
}
} while(next_permutation(p, p + 3));
cout << (ans == INF ? 0 : ans) << "\n";
} int main() {
int t; cin >> t;
while (t--) solve();
}
C1 - Simple Polygon Embedding
题意
计算能包含正多边形的正方形的最小边长,正多边形可以旋转。(多边形的边数为 2 * 偶数)
题解

这是正八边形时的情况,观察发现边数为四的倍数的正多边形都可以恰好对称地四等分嵌在正方形中,所以计算出内切圆直径即可。
代码
#include <bits/stdc++.h>
#define PI acos(-1)
using namespace std; void solve() {
int n; cin >> n;
n = 2 * n;
printf("%.9f\n", cos(PI / n) / sin(PI/ n));
} int main() {
int t; cin >> t;
while (t--) solve();
}
C2 - Not So Simple Polygon Embedding
题意
计算能包含正多边形的正方形的最小边长,正多边形可以旋转。(多边形的边数为 2 * 奇数)
题解

正六边形时大概长这样,算出正六边形与正方形的边较小的夹角为 15 度,求出对角线长乘以 sin 即可,其他边数情况我不太会证,但是觉得应该和正六边形差不多emmm...
代码
#include <bits/stdc++.h>
#define PI acos(-1)
using namespace std; void solve() {
int n; cin >> n;
n = 2 * n;
printf("%.9f\n", 0.5 / sin(PI / (2 * n)));
} int main() {
int t; cin >> t;
while (t--) solve();
}
D - Multiset
题意
开始时 $multiset$ 中有 $n$ 个元素,之后 $q$ 次操作如下:
- $k_i > 0$,插入 $k_i$
- $k_i < 0$,删除第 $|k_i|$ 个元素(删除元素的序号不会大于集合的大小)
题解
树状数组模拟。
代码一
复杂度:$O_{(nlog_n)}$,参考自:square1001
#include <bits/stdc++.h>
using namespace std;
const int N = 1048576; int bit[N]; void add(int pos, int val) {
for (int i = pos; i <= N; i += i & (-i)) {
bit[i] += val;
}
} int bsearch(int x) {
int ptr = 0;
for (int i = N / 2; i >= 1; i >>= 1) {
if (bit[ptr + i] < x) {
x -= bit[ptr + i];
ptr += i;
}
}
return ptr + 1;
} int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, q; cin >> n >> q;
for (int i = 0; i < n; i++) {
int x; cin >> x;
add(x, 1);
}
int cnt = n;
for (int i = 0; i < q; i++) {
int x; cin >> x;
if (x > 0) {
add(x, 1);
++cnt;
} else {
add(bsearch(-x), -1);
--cnt;
}
}
cout << (cnt ? bsearch(1) : 0);
}
代码二
复杂度:$O_{(nlog_n^2)}$,参考自:_封刀看海
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100; int bit[N]; void update(int pos, int val) {
for (int i = pos; i <= N; i += i & (-i)) {
bit[i] += val;
}
} int query(int pos) {
int ans = 0;
for (int i = pos; i >= 1; i -= i & (-i)) {
ans += bit[i];
}
return ans;
} int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, q; cin >> n >> q;
for (int i = 0; i < n; i++) {
int x; cin >> x;
update(x, 1);
}
for (int i = 0; i < q; i++) {
int x; cin >> x;
if (x > 0) {
update(x, 1);
} else {
int l = 1, r = N;
while (l < r) {
int mid = (l + r) / 2;
if (query(mid) >= -x)
r = mid;
else
l = mid + 1;
}
update(l, -1);
}
}
int ans = find_if(bit, bit + N, [] (int x) {
return x > 0;
}) - bit;
cout << (ans == N ? 0 : ans);
}
Educational Codeforces Round 87 (Rated for Div. 2)的更多相关文章
- Educational Codeforces Round 87 (Rated for Div. 2) D树状数组加二分删除的值
Sample Input 5 4 1 2 3 4 5 -5 -1 -3 -1 Sample Output 3 思路,首先发现a[i]的值的范围是在1~n之间,每次插入我们可以直接把cnt[a[i]]+ ...
- Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship
Problem Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...
- Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)
Problem Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...
- Educational Codeforces Round 43 (Rated for Div. 2)
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...
- Educational Codeforces Round 35 (Rated for Div. 2)
Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...
- Educational Codeforces Round 63 (Rated for Div. 2) 题解
Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...
- Educational Codeforces Round 39 (Rated for Div. 2) G
Educational Codeforces Round 39 (Rated for Div. 2) G 题意: 给一个序列\(a_i(1 <= a_i <= 10^{9}),2 < ...
随机推荐
- 【Git】简易使用教程
Git简介 诞生 简单的来说,就是为了托管庞大的Linux源码,开始选择了商用的版本控制系统BitKeeper,但是因为一系列操作,BitKeeper不让用了,所以Linus花了两周时间自己用C写了一 ...
- wpf 通过为DataGrid所绑定的数据源类型的属性设置Attribute改变DataGrid自动生成列的顺序
环境Win10 VS2019 .Net Framework4.8 在wpf中,如果为一个DataGrid绑定到一个数据源,默认情况下DataGrid会为数据源类型的每个属性生成一个列(Column)对 ...
- 原生javascript制作省市区三级联动详细教程
多级联动下拉菜单是前端常见的效果,省市区三级联动又属于其中最典型的案例.多级联动一般都是与数据相关联的,根据数据来生成和修改联动的下拉菜单.完成一个多级联动效果,有助于增强对数据处理的能力. 本实例以 ...
- LeetCode383. 赎金信
题目 给定一个赎金信 (ransom) 字符串和一个杂志(magazine)字符串,判断第一个字符串 ransom 能不能由第二个字符串 magazines 里面的字符构成.如果可以构成,返回 tru ...
- ctfhub技能树—sql注入—时间盲注
打开靶机 查看页面信息 测试时间盲注 可以看到在执行命令后会有一定时间的等待,确定为时间盲注 直接上脚本 1 #! /usr/bin/env python 2 # _*_ coding:utf-8 _ ...
- Linux设置开机自动挂载镜像文件
1.将文件上传到服务器上(本例上传到/Data/software下) 2.挂载 mount -o loop /Data/software/rhel-server-7.6-x86_64-dvd.iso ...
- 为什么不建议用var
看了这个例子估计你就会明白了 var a = 'global'; function test() { if (!a) { var a = 'part'; } console.log(a); } tes ...
- C++:标准I/O流
标准I/O对象:cin,cout,cerr,clog cout; //全局流对象 输出数据到显示器 cin; //cerr没有缓冲区 clog有缓冲区 cerr; //标准错误 输出数据到显示器 cl ...
- .NET Core 问题记录
前言: 最近在项目中遇到了遇到了写部署步骤过多的问题,为了减少.net core项目部署步骤:需要对一些基础问题进行验证: 如端口设置.单页应用程序(angluar)合并部署方式等相关问题,特将解决过 ...
- Arduino 上手实战呼吸灯
前言 这篇稿子比以往的时候来的稍晚了一些,望fans们见谅,那即便如此,最终还是姗姗来迟了,公司新一轮战略性部署,被拖出去孵化新产品,开拓新市场去了,手头精力没有那么多了,另外产品一茬接一茬.韭菜一波 ...