NC216012 Let'sPlayCurling
题目
题目描述
Curling is a sport in which players slide stones on a sheet of ice toward a target area. The team with the nearest stone to the center of the target area wins the game.
Two teams, Red and Blue, are competing on the number axis. After the game there are \((n+m)\) stones remaining on the axis, \(n\) of them for the Red team and the other \(m\) of them for the Blue. The iii-th stone of the Red team is positioned at \(a_i\) and the \(i\)-th stone of the Blue team is positioned at \(b_i\).
Let \(c\) be the position of the center of the target area. From the description above we know that if there exists some \(i\) such that \(1 \le i \le n\) and for all \(1 \le j \le m\) we have\(|c - a_i| < |c - b_j|\) then Red wins the game. What's more, Red is declared to win \(p\) points if the number of \(i\) satisfying the constraint is exactly \(p\).
Given the positions of the stones for team Red and Blue, your task is to determine the position \(c\) of the center of the target area so that Red wins the game and scores as much as possible. Note that \(c\) can be any real number, not necessarily an integer.
输入描述
There are multiple test cases. The first line of the input contains an integer \(T\) indicating the number of test cases. For each test case:
The first line contains two integers nnn and mmm (\(1 \le n, m \le 10^5\)) indicating the number of stones for Red and the number of stones for Blue.
The second line contains nnn integers \(a_1, a_2, \cdots, a_n\) (\(1 \le a_i \le 10^9\)) indicating the positions of the stones for Red.
The third line contains mmm integers \(b_1, b_2, \cdots, b_m\) (\(1 \le b_i \le 10^9\)) indicating the positions of the stones for Blue.
It's guaranteed that neither the sum of nnn nor the sum of \(m\) will exceed \(5 \times 10^5\) .
输出描述
For each test case output one line. If there exists some \(c\) so that Red wins and scores as much as possible, output one integer indicating the maximum possible score of Red (NOT \(c\)). Otherwise output "Impossible" (without quotes) instead.
示例1
输入
3
2 2
2 3
1 4
6 5
2 5 3 7 1 7
3 4 3 1 10
1 1
7
7
输出
2
3
Impossible
备注
For the first sample test case we can assign \(c = 2.5\) so that the stones at position 2 and 3 for Red will score.
For the second sample test case we can assign \(c = 7\) so that the stones at position 5 and 7 for Red will score.
题解
知识点:STL,模拟。
选择一个点作为目标,如果存在红色石头比所有蓝色石头都严格接近目标,则红方胜利。进一步,满足比所有蓝色石头都严格接近目标的红色石头的数量是红方最后得分。
显然,红色石头会连成一段区间,中间不能有蓝色石头(包括端点),目标可以选在他们中间,使得这段红色石头都包括其中,并不含蓝色石头,最终得分就是连续红色石头的个数。地图上有很多蓝色石头分割了许多红色石头的区间,所以首先用一个 \(map\) 将坐标映射到红色石头数量,再将蓝色石头坐标的红色石头数量设为 \(0\) ,这样就有了所有石头的坐标,不为 \(0\) 的就是红色石头数量。遍历一遍,计算每个区间的红色石头个数,取其中最大值即可。
时间复杂度 \(O((n+m) \log (n+m))\)
空间复杂度 \(O(n+m)\)
代码
#include <bits/stdc++.h>
#define ll long long
using namespace std;
bool solve() {
int n, m;
cin >> n >> m;
map<int, int> mp;
for (int i = 0, tmp;i < n;i++) {
cin >> tmp;
mp[tmp]++;
}
for (int i = 0, tmp;i < m;i++) {
cin >> tmp;
mp[tmp] = 0;
}
int ans = 0, sum = 0;
for (auto [i, j] : mp) {
if (j) sum += j;
else sum = 0;
ans = max(ans, sum);
}
if (ans) cout << ans << '\n';
else return false;
return true;
}
int main() {
std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while (t--) {
if (!solve()) cout << "Impossible" << '\n';
}
return 0;
}
随机推荐
- 每天学五分钟 Liunx 101 | 存储篇:LVM
LVM LVM(Logical Volume Manager),逻辑卷管理器.一种高级文件系统管理方式,它可以动态扩展文件系统. LVM 的示意图如下所示:
- AHB 局限性
AHB's problem SoC bus 架构 AXI is used more and more 频率200M使用AHB,频率再升高就使用AXI AHB的问题 AHB协议本身限制要求较高,比如co ...
- 4. Oracle数据库提示ERROR: ORA-12560: TNS: 协议适配器错误
问题如下 造成ORA-12560: TNS: 协议适配器错误的问题的原因有两个: 有关服务没有启动 windows平台个一如下操作:开始-程序-管理工具-服务,打开服务面板,启动TNSlistener ...
- TCP连接状态的多种判断方法
前言 在TCP网络编程模型中,无论是客户端还是服务端,在网络编程的过程中都需要判断连接的对方网络状态是否正常.在linux系统中,有很多种方式可以判断连接的对方网络是否已经断开. 通过错误码和信号 ...
- [转帖]Oracle优化案例:vfs_cache_pressure和min_free_kbytes解决RMAN挂起问题
https://www.modb.pro/db/34028 环境: Oracle 11gr2 + dataguard 512GB内存 + 128核cpu + 高性能存储服务器 uname -an Li ...
- [转帖]TiDB 数据库统计表的大小方法
简介:TiDB统计表的大小,列出了一些方法: 1.第一种的统计方式: 基于统计表 METRICS_SCHEMA.store_size_amplification 要预估 TiDB 中一张表的大小,你可 ...
- TiKV占用内存超过的解决过程
TiKV占用内存超过的解决过程 背景 为了后去TiDB的极限数据. 晚上在每台服务器上面增加了多个TiKV的节点. 主要方式为: 每个NVME的硬盘增加两个TiKV的进程. 这样每个服务器两个磁盘, ...
- [转帖]【SOP】最佳实践之 TiDB 业务写变慢分析
https://zhuanlan.zhihu.com/p/647831844 前言 在日常业务使用或运维管理 TiDB 的过程中,每个开发人员或数据库管理员都或多或少遇到过 SQL 变慢的问题.这类问 ...
- [转帖]火狐URL默认打开为HTTPS,切换成http形式
火狐在当前及未来版本默认URL采用HTTPS进行链接,但个人习惯,某些网站不是https,改http在响应超时状态也会切成https,将默认为http. edge,chrome 依然还是http为主要 ...
- [转帖]一、Kafka Tool使用
一.Kafka Tool使用 1.添加cluster 2.开启SASL_PLAINTEXT 如果kafka 开启SASL_PLAINTEXT认证(用户名和密码认证) 3.高级设置 如果设置的是SASL ...