题目描述

给定一个长度为\(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: 炮艇大赛之正式赛的更多相关文章

  1. noip2017集训测试赛(三) Problem B: mex [补档]

    Description 给你一个无限长的数组,初始的时候都为0,有3种操作: 操作1是把给定区间[l,r][l,r] 设为1, 操作2是把给定区间[l,r][l,r] 设为0, 操作3把给定区间[l, ...

  2. noip2017集训测试赛(十一)Problem C: 循环移位

    题面 Description 给定一个字符串 ss .现在问你有多少个本质不同的 ss 的子串 t=t1t2⋯tm(m>0)t=t1t2⋯tm(m>0) 使得将 tt 循环左移一位后变成的 ...

  3. noip2017集训测试赛(四)Problem A: fibonacci

    题目大意 给你一个序列\(a_1, a_2, ..., a_n\). 我们令函数\(f(n)\)表示斐波那契数列第\(n\)项的值. 总共\(m\)个操作, 分为以下两种: 将\(x \in [L, ...

  4. noip2017集训测试赛(三)Problem C: MST

    题面 Description 给定一个n个点m条边的连通图,保证没有自环和重边.对于每条边求出,在其他边权值不变的情况下,它能取的最大权值,使得这条边在连通图的所有最小生成树上.假如最大权值为无限大, ...

  5. noip2019集训测试赛(二十一)Problem B: 红蓝树

    noip2019集训测试赛(二十一)Problem B: 红蓝树 Description 有一棵N个点,顶点标号为1到N的树.N−1条边中的第i条边连接顶点ai和bi.每条边在初始时被染成蓝色.高桥君 ...

  6. 第六届蓝桥杯软件类省赛题解C++/Java

    第六届蓝桥杯软件类省赛题解C++/Java 1[C++].统计不含4的数字统计10000至99999中,不包含4的数值个数.答:暴力循环范围内所有数字判断一下就是了,答案是52488 1[Java]. ...

  7. 2019浙师大校赛(浙大命题)(upc复现赛)总结

    2019浙师大校赛(浙大命题)(upc复现赛)总结 早上九点开始.起得迟了,吃了早饭慌慌张张跑过去,刚到比赛就开始了. 开始分别从前往后和从后往前看题,一开始A题,第一发WA,第二次读题发现漏看了还有 ...

  8. NYOJ-712 探寻宝藏(第六届河南省程序设计大赛)

    探 寻 宝 藏 时间限制:1000 ms  |  内存限制:65535 KB 难度:5   描述 传说HMH大沙漠中有一个M*N迷宫,里面藏有许多宝物.某天,Dr.Kong找到了迷宫的地图,他发现迷宫 ...

  9. 2016集训测试赛(二十六)Problem A: bar

    Solution 首先审清题意, 这里要求的是子串而不是子序列... 我们考虑用1表示p, -1表示j. 用sum[i]表示字符串前\(i\)的前缀和. 则我们考虑一个字符串\([L, R]\)有什么 ...

随机推荐

  1. Python中函数参数类型和参数绑定

    参数类型 Python函数的参数类型一共有五种,分别是: POSITIONAL_OR_KEYWORD(位置参数或关键字参数) VAR_POSITIONAL(可变参数) KEYWORD_ONLY(关键字 ...

  2. App 设计技巧

    http://www.360doc.com/content/14/1120/18/21412_426730809.shtml http://veryui.diandian.com/post/2013- ...

  3. IOS开发学习笔记010-面向对象的三大特性

    面向对象的三大特性 1.封装 2.继承 3.多态 一.封装 将类内部的属性保护起来,在外部不能直接访问,那么如果需要访问怎么办呢? OC提供了set方法来对成员变量进行访问 set方法 1.作用:提供 ...

  4. ADO之密码验证--3次错误就锁定『改进』

    这里使用了SqlHelper,简化程序 自己写一个SqlHelper,把数据库的连接等都写到里面去. 首先把连接字符串添加到配置文件里去,右键解决方案-->添加新建项-->选择应用程序配置 ...

  5. Python+Selenium练习篇之15-在浏览器中新开一个tab

    本文介绍如selenium方法打开一个新的tab,我们知道在浏览器里,我们按住 ctrl+ t 就可以新打开一个tab.所以我们学习如何利用webdriver中send_key 的方法去触发ctrl+ ...

  6. 菜鸟之路——机器学习之非线性回归个人理解及python实现

    关键词: 梯度下降:就是让数据顺着梯度最大的方向,也就是函数导数最大的放下下降,使其快速的接近结果. Cost函数等公式太长,不在这打了.网上多得是. 这个非线性回归说白了就是缩小版的神经网络. py ...

  7. linq本质扩展方法+lambda表达式

    string[] names = { "aa","bb","cc","dd"}; /* IEnumerable<s ...

  8. 【转】log4js在PM2的cluster模式下大坑

    请直接查看原文:https://blog.yourtion.com/fix-log4js-with-pm2-not-work.html 之前一直使用 debug 还有 console.log 去打日志 ...

  9. Linux性能分析调优工具介绍

    1.常用性能分析工具 1)CPU性能分析工具 vmstat ps sar time strace pstree top 2)Memory性能分析工具 vmstat strace top ipcs ip ...

  10. python和tensorflow安装

    一.Python安装 python采用anaconda安装,简单方便,下载python3.6的anaconda  linux64的sh安装文件. 1.bash Anaconda-2.1.0-Linux ...