noip2017集训测试赛(六)Problem A: 炮艇大赛之正式赛
题目描述
给定一个长度为\(L \le 10^9\)的环形赛道, \(n \le 10^5\)个人在上面赛艇. 每个人的速度都不相同, 假如为正则顺时针走, 否则逆时针走. 当两个人相遇时, 他们就会开火, 编号小的那个人就会挂掉出局. 当只剩下一个人时, 这个人就获得胜利.
问: 多久以后游戏结束.
Solution
考虑什么时候游戏结束: 最后仅剩的两个人相遇, 则一个挂掉, 另一个胜利.
因此我们只要得到最后是哪两个人相遇即可.
考虑每次相遇的只能是位置相邻的两个人, 因此我们把相邻两个人相遇所需要的时间用一个堆维护起来, 每次找到最早相遇的两个人, 记录其中一个人挂掉, 并且将产生的新的相邻的两个人加入堆中即可.
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cmath>
using namespace std;
namespace Zeonfai
{
inline int getInt()
{
int a = 0, sgn = 1; char c;
while (! isdigit(c = getchar())) if (c == '-') sgn *= -1;
while (isdigit(c)) a = a * 10 + c - '0', c = getchar();
return a * sgn;
}
}
const int N = (int)1e5;
int n, L;
struct ting
{
int d, v, w;
inline int operator <(const ting &a) const { return d < a.d; }
}a[N + 7];
struct record
{
int id[2];
double T;
inline record() {}
inline record(int u, int v)
{
if (a[u].v > a[v].v) swap(u, v);
T = (double)((a[u].d - a[v].d + L) % L) / (a[v].v - a[u].v);
id[0] = u; id[1] = v;
if (a[id[0]].w < a[id[1]].w) swap(id[0], id[1]);
}
inline int operator <(const record &a) const { return T > a.T; }
};
inline void getOutput(int a, int b)
{
if (a == 0) { puts("0"); return; }
int x = a, y = b; if (x < y) swap(x, y);
while (y)
{
int tmp = x % y;
x = y; y = tmp;
}
printf("%d/%d\n", a / x, b / x);
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("'citing.in", "r", stdin);
freopen("'citing.out", "w", stdout);
#endif
using namespace Zeonfai;
n = getInt(); L = getInt();
for (int i = 0; i < n; ++ i) a[i].w = i, a[i].d = getInt();
for (int i = 0; i < n; ++ i) a[i].v = getInt();
sort(a, a + n);
priority_queue<record> que;
que.push(record(0, n - 1)); for (int i = 1; i < n; ++ i) que.push(record(i, i - 1));
static int nxt[N + 7], lst[N + 7], dd[N + 7];
memset(dd, 0, sizeof dd);
for (int i = 0; i < n; ++ i) nxt[i] = (i + 1) % n, lst[i] = (i - 1 + n) % n;
for (int i = 2; i < n; ++ i)
{
record rec;
while (1)
{
rec = que.top(); que.pop();
int flg = 1;
for (int j = 0; j < 2; ++ j) if (dd[rec.id[j]]) flg = 0;
if (flg) break;
}
dd[rec.id[1]] = 1;
nxt[lst[rec.id[1]]] = nxt[rec.id[1]]; lst[nxt[rec.id[1]]] = lst[rec.id[1]];
nxt[rec.id[1]] = lst[rec.id[1]] = -1;
que.push(record(rec.id[0], nxt[rec.id[0]])); que.push(record(rec.id[0], lst[rec.id[0]]));
// printf("%d %d\n", a[rec.id[0]].w, a[rec.id[1]].w);
}
record rec;
while (1)
{
rec = que.top(); que.pop();
int flg = 1;
for (int j = 0; j < 2; ++ j) if (dd[rec.id[j]]) flg = 0;
if (flg) break;
}
// printf("%d %d\n", a[rec.id[0]].w, a[rec.id[1]].w);
if (a[rec.id[0]].v > a[rec.id[1]].v) swap(rec.id[0], rec.id[1]);
getOutput((a[rec.id[0]].d - a[rec.id[1]].d + L) % L, abs(a[rec.id[1]].v - a[rec.id[0]].v));
}
noip2017集训测试赛(六)Problem A: 炮艇大赛之正式赛的更多相关文章
- noip2017集训测试赛(三) Problem B: mex [补档]
Description 给你一个无限长的数组,初始的时候都为0,有3种操作: 操作1是把给定区间[l,r][l,r] 设为1, 操作2是把给定区间[l,r][l,r] 设为0, 操作3把给定区间[l, ...
- noip2017集训测试赛(十一)Problem C: 循环移位
题面 Description 给定一个字符串 ss .现在问你有多少个本质不同的 ss 的子串 t=t1t2⋯tm(m>0)t=t1t2⋯tm(m>0) 使得将 tt 循环左移一位后变成的 ...
- noip2017集训测试赛(四)Problem A: fibonacci
题目大意 给你一个序列\(a_1, a_2, ..., a_n\). 我们令函数\(f(n)\)表示斐波那契数列第\(n\)项的值. 总共\(m\)个操作, 分为以下两种: 将\(x \in [L, ...
- noip2017集训测试赛(三)Problem C: MST
题面 Description 给定一个n个点m条边的连通图,保证没有自环和重边.对于每条边求出,在其他边权值不变的情况下,它能取的最大权值,使得这条边在连通图的所有最小生成树上.假如最大权值为无限大, ...
- noip2019集训测试赛(二十一)Problem B: 红蓝树
noip2019集训测试赛(二十一)Problem B: 红蓝树 Description 有一棵N个点,顶点标号为1到N的树.N−1条边中的第i条边连接顶点ai和bi.每条边在初始时被染成蓝色.高桥君 ...
- 第六届蓝桥杯软件类省赛题解C++/Java
第六届蓝桥杯软件类省赛题解C++/Java 1[C++].统计不含4的数字统计10000至99999中,不包含4的数值个数.答:暴力循环范围内所有数字判断一下就是了,答案是52488 1[Java]. ...
- 2019浙师大校赛(浙大命题)(upc复现赛)总结
2019浙师大校赛(浙大命题)(upc复现赛)总结 早上九点开始.起得迟了,吃了早饭慌慌张张跑过去,刚到比赛就开始了. 开始分别从前往后和从后往前看题,一开始A题,第一发WA,第二次读题发现漏看了还有 ...
- NYOJ-712 探寻宝藏(第六届河南省程序设计大赛)
探 寻 宝 藏 时间限制:1000 ms | 内存限制:65535 KB 难度:5 描述 传说HMH大沙漠中有一个M*N迷宫,里面藏有许多宝物.某天,Dr.Kong找到了迷宫的地图,他发现迷宫 ...
- 2016集训测试赛(二十六)Problem A: bar
Solution 首先审清题意, 这里要求的是子串而不是子序列... 我们考虑用1表示p, -1表示j. 用sum[i]表示字符串前\(i\)的前缀和. 则我们考虑一个字符串\([L, R]\)有什么 ...
随机推荐
- Redis实现之压缩列表
压缩列表 压缩列表(ziplist)是列表键和哈希键的底层实现之一,当一个列表键只包含少量列表项,并且每个列表项要嘛是整数值,要嘛是比较短的字符串,那么Redis就会使用压缩列表来做列表键的底层实现. ...
- Java -X命令
C:\Users\Administrator>java -X -Xmixed 混合模式执行 (默认) -Xint 仅解释模式执行 -Xbootclasspath:<用 ; 分隔的目录和 z ...
- C#入门篇-3:数据类型及转换
using System; using System.Text; using System.Collections; using System.Collections.Generic; //003 查 ...
- 移动弱网测试方案Network Emulator for Windows Toolkit
移动app在测试时,有时需要考虑弱网的情形下,app的表现,那么怎么营造这样子的环境呢? 一.首先需要控制网络,有两种方式其一使用网络损伤仪进行,其二采用软件方式.硬件采购费用太贵,因此使用win平台 ...
- 利用python多线程模块实现模拟接口并发
import requestsimport jsonimport threadingimport timeimport uuid class postrequests(): def __init__( ...
- Python-S9——Day100-Web前端框架之Vue
01 课程简介: 02 let和const: 03 箭头函数: 04 对象的单体模式: 05 nodejs介绍和npm操作: 06 webpack.babel介绍和vue的第一个案例: 07 昨日内容 ...
- ms sqlserver数据库主文件特别大怎么办
因为项目中需要复制数据库,作为外网测试的数据库,但是数据库特别大,复制特别费劲,即使只复制主文件,主文件也特别大. 然后百度了下,发现数据库有个收缩功能,数据库右键——任务——收缩,可以对数据库进行收 ...
- ORA-12012: 自动执行作业 "SYS"."ORA$AT_OS_OPT_SY_21" 出错
oracle 12.2.0.1版本报错: Errors in file /u01/app/oracle/diag/rdbms/easdb/easdb2/trace/easdb2_j000_27520. ...
- 【bzoj4825】[Hnoi2017]单旋 线段树+STL-set
题目描述 H 国是一个热爱写代码的国家,那里的人们很小去学校学习写各种各样的数据结构.伸展树(splay)是一种数据结构,因为代码好写,功能多,效率高,掌握这种数据结构成为了 H 国的必修技能.有一天 ...
- [NOI2009] 植物大战僵尸 [网络流]
题面: 传送门 思路: 这道题明显可以看出来有依赖关系 那么根据依赖(保护)关系建图:如果a保护b则连边(a,b) 这样,首先所有在环上的植物都吃不到,被它们间接保护的也吃不到 把这些植物去除以后,剩 ...