Codeforces Global Round 5
A. Balanced Rating Changes
签到,分正负搞一下就行。
B. Balanced Tunnel
题意:
给出\(n\)辆车的进洞顺序和出洞顺序,问有多少量车实现了洞中超车。
思路:
对于进洞的车\(i\),找到其出洞之前所有的车,若有车还未进洞,则那辆车实现了超车。
对于出洞序列维护一个指针\(j\),可以证明,任一时刻\(j\)之前的车都处于超车和没超车两种状态,也就是说\(j\)是单调不减的。
然后就类似于双指针搞下就行。
Code
#include <bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
// #define Local
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 1e5 + 5;
int n;
int a[N], b[N];
bool chk[N], fined[N];
void run() {
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= n; i++) cin >> b[i];
int j = 1;
for(int i = 1; i <= n; i++) {
chk[a[i]] = 1;
while(j <= n && !fined[a[i]] && b[j] != a[i]) {
if(!chk[b[j]]) fined[b[j]] = 1;
++j;
}
}
int ans = 0;
for(int i = 1; i <= n; i++) {
ans += fined[i];
}
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cout << fixed << setprecision(20);
#ifdef Local
freopen("../input.in", "r", stdin);
freopen("../output.out", "w", stdout);
#endif
while(cin >> n) run();
return 0;
}
C2. Balanced Removals (Harder)
题意:
在三维空间中给出\(n\)个点,现在要不断删除以两个点为对角线顶点的立方体,并要求立方体中不含任何其它点。
输出删除序列。
思路:
- 可以考虑二维状态怎么处理这个问题。
- 显然若\(x\)都不同,排序直接删除就行
- 若存在\(x\)相同,我们需要单独删除横坐标相同的点,最后至多留下一个点,问题转换为上述问题。
- 那么对于三维状态也同理,只是实现起来稍微复杂一点。
详见代码:
Code
#include <bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
// #define Local
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 50005;
int n;
struct Point{
int x, y, z, id;
bool operator < (const Point &A) const {
if(x != A.x) return x < A.x;
if(y != A.y) return y < A.y;
if(z != A.z) return z < A.z;
return id < A.id;
}
}a[N];
void run() {
for(int i = 1; i <= n; i++) {
cin >> a[i].x >> a[i].y >> a[i].z;
a[i].id = i;
}
sort(a + 1, a + n + 1);
std::vector<Point> v2;
for(int i = 1, j; i <= n; i = j) {
j = i;
while(j <= n && a[i].x == a[j].x) ++j;
std::vector<Point> v;
for(int k = i, t; k < j; k = t) {
t = k;
while(t < j && a[k].y == a[t].y) ++t;
for(int p = k; p < t; p += 2) {
if (p + 1 < t) {
cout << a[p].id << ' ' << a[p + 1].id << '\n';
} else {
v.push_back(a[p]);
}
}
}
for(int p = 0; p < sz(v); p += 2) {
if(p + 1 < sz(v)) {
cout << v[p].id << ' ' << v[p + 1].id << '\n';
} else {
v2.push_back(v[p]);
}
}
}
for(int i = 0; i < sz(v2); i += 2) {
cout << v2[i].id << ' ' << v2[i + 1].id << '\n';
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cout << fixed << setprecision(20);
#ifdef Local
freopen("../input.in", "r", stdin);
freopen("../output.out", "w", stdout);
#endif
while(cin >> n) run();
return 0;
}
D. Balanced Playlist
题意:
给出一个环,每个点有权值。现在从每个点出发,定义走过路径上点权的最大值为\(max\),那么走到一个点其权值\(v\)满足\(v<\frac{max}{2}\)时停止。
问从每一个点出发所走的路径长度为多少,若无限走下去则输出\(-1\)。
思路:
这个题我是暴力*过去的hhhh。
我的做法就是类似于双指针那样,维护两个指针来跑,但复杂度可能高达\(O(n^2)\)。后来我加了点trick就1700ms给卡过去了2333。
但其实\(O(nlogn)\)的做法很多,二分、线段树这些都行...但二分+RMQ应该是最简单的做法吧。
给出我的暴力代码:
Code
#include <bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
// #define Local
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 3e5 + 5;
int n;
int a[N];
int ans[N];
//y < x
bool ok(int x, int y) {
return y < (x + 1) / 2;
}
void run() {
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= n; i++) a[i + 2 * n] = a[i + n] = a[i];
int Min = *min_element(a + 1, a + n + 1);
int Max = *max_element(a + 1, a + n + 1);
if(!ok(Max, Min)) {
for(int i = 1; i <= n; i++) cout << -1 << " \n"[i == n];
return;
}
for(int i = 1, j; i <= n; i = j + 1) {
j = i;
int mx = a[i], p = i;
while(j + 1 <= 3 * n && !ok(mx, a[j + 1])) {
++j;
if(a[j] >= mx) {
mx = a[j];
p = j;
}
}
for(int k = i; k <= p; k++) {
ans[k] = j + 1 - k;
}
while(p < n && ok(a[p + 1], a[j + 1])) {
++p;
ans[p] = j + 1 - p;
}
j = p;
}
for(int i = 1; i <= n; i++) cout << ans[i] << " \n"[i == n];
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cout << fixed << setprecision(20);
#ifdef Local
freopen("../input.in", "r", stdin);
freopen("../output.out", "w", stdout);
#endif
while(cin >> n) run();
return 0;
}
Codeforces Global Round 5的更多相关文章
- CodeForces Global Round 1
CodeForces Global Round 1 CF新的比赛呢(虽然没啥区别)!这种报名的人多的比赛涨分是真的快.... 所以就写下题解吧. A. Parity 太简单了,随便模拟一下就完了. B ...
- Codeforces Global Round 1 - D. Jongmah(动态规划)
Problem Codeforces Global Round 1 - D. Jongmah Time Limit: 3000 mSec Problem Description Input Out ...
- Codeforces Global Round 2 题解
Codeforces Global Round 2 题目链接:https://codeforces.com/contest/1119 A. Ilya and a Colorful Walk 题意: 给 ...
- Codeforces Global Round 1 (A-E题解)
Codeforces Global Round 1 题目链接:https://codeforces.com/contest/1110 A. Parity 题意: 给出{ak},b,k,判断a1*b^( ...
- Codeforces Global Round 3
Codeforces Global Round 3 A. Another One Bites The Dust 有若干个a,有若干个b,有若干个ab.你现在要把这些串拼成一个串,使得任意两个相邻的位置 ...
- Codeforces Global Round 1 (CF1110) (未完结,只有 A-F)
Codeforces Global Round 1 (CF1110) 继续补题.因为看见同学打了这场,而且涨分还不错,所以觉得这套题目可能会比较有意思. 因为下午要开学了,所以恐怕暂时不能把这套题目补 ...
- 【手抖康复训练1 】Codeforces Global Round 6
[手抖康复训练1 ]Codeforces Global Round 6 总结:不想复习随意打的一场,比赛开始就是熟悉的N分钟进不去时间,2333,太久没写题的后果就是:A 题手抖过不了样例 B题秒出思 ...
- Codeforces Global Round 11 个人题解(B题)
Codeforces Global Round 11 1427A. Avoiding Zero 题目链接:click here 待补 1427B. Chess Cheater 题目链接:click h ...
- 【Codeforces Round 1110】Codeforces Global Round 1
Codeforces Round 1110 这场比赛只做了\(A\).\(B\).\(C\),排名\(905\),不好. 主要的问题在\(D\)题上,有\(505\)人做出,但我没做出来. 考虑的时候 ...
- 树形DP ---- Codeforces Global Round 2 F. Niyaz and Small Degrees引发的一场血案
Aspirations:没有结果,没有成绩,acm是否有意义?它最大的意义就是让我培养快速理解和应用一个个未知知识点的能力. ————————————————————————————————————— ...
随机推荐
- Java网络爬虫 Jsoup
一.Jsoup介绍 我们抓取到页面之后,还需要对页面进行解析.可以使用字符串处理工具解析页面,也可以使用正则表达式,但是这些方法都会带来很大的开发成本,所以我们需要使用一款专门解析html页面的技术. ...
- C# .NET的BinaryFormatter、protobuf-net、Newtonsoft.Json以及自己写的序列化方法序列化效率和序列化后的文件体积大小对比
测试结果如下图: 测试结果整理后: 结论: 1.这几个工具中,protobuf-net序列化和反序列化效率是最快的 2.BinaryFormatter和Newtonsoft.Json反序列化慢的比较多 ...
- 【Cef编译】 CefSharp编译失败,检测到“RuntimeLibrary”的不匹配项: 值“MT_StaticRelease”不匹配值“MD_DynamicRelease”
编译CefSharp生成后一个libcef_dll_wrapper.lib时,供CefSharp使用.结果CefSharp编译的时候报错.遇到以下异常: libcef_dll_wrapper.lib( ...
- IDEA中使用Maven模板创建Servelet项目并使用Tomcat来运行项目
首先需要正确安装Maven和Tomact,Maven安装和Tomact安装步骤,参见别的文章. 一.创建Maven工作空间 点击Finish按钮后,耐心等待.直到出现BUILD SUCCESS为止. ...
- How to: Display a List of Non-Persistent Objects in a Popup Dialog 如何:在弹出对话框中显示非持久化对象列表
This example demonstrates how to populate and display a list of objects that are not bound to the da ...
- JDK1.8 中的HashMap
HashMap本质上Java中的一种数据结构,他是由数组+链表的形式组织而成的,当然了在jdk1.8后,当链表长度大于8的时候为了快速寻址,将链表修改成了红黑树. 既然本质上是一个数组,那我们 ...
- [转]Python十个高大上的语法
Python 是一种代表简单思想的语言,其语法相对简单,很容易上手.不过,如果就此小视 Python 语法的精妙和深邃,那就大错特错了.本文精心筛选了最能展现 Python 语法之精妙的十个知识点,并 ...
- SpringCloud之Feign:REST客户端
在Spring Cloud集群中,各个角色的通信基于REST服务,在调用服务时,需要使用REST客户端,常用,除了使用Spring自带的RestTemplate,也可使用另一个REST客户端:Feig ...
- java 坐标系运算 判断一个地理坐标是否在电子围栏 圆、矩形、多边形区域内
转载自:https://blog.csdn.net/Deepak192/article/details/79402694 测试没问题,我用的是原始坐标:要注意的是坐标转换问题,要看当前是属于什么坐标系 ...
- 截取字符串substr和substring两者的区别
两者有相同点: 如果只是写一个参数,两者的作用都是一样的:就是截取字符串当前下标以后直到字符串最后的字符串片段. 不同点:第二个参数: substr(startIndex,lenth): 第二个参数是 ...