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]\)有什么 ...
随机推荐
- Kinect安装
在连接kinect机器前,需要先安装两个软件,而在安装这两个软件前需要有vs2010(专业版本和快速版),因为需要包含.net framework 4.0 kinect sdk http://www. ...
- “帮你”app-NABCD
1.你的创意解决了用户的什么需求?(N) 本学校已存在的失物招领.表白墙.二手市场等QQ群普遍存在信息冗杂,时效性差等缺点.不能充分发挥信息有效性的,我们的“帮你”APP能够充分发挥信息的有效性,让失 ...
- 纯javascript验证,100行超精简代码。
这篇文章转自--寒飞,原帖地址http://blog.csdn.net/luoyehanfei/article/details/42262249 QQ交流群235032949 纯javascript验 ...
- 【Add Two Numbers】
题目: You are given two linked lists representing two non-negative numbers. The digits are stored in r ...
- leetcode 【 Merge Sorted Array 】python 实现
题目: Given two sorted integer arrays A and B, merge B into A as one sorted array. Note:You may assume ...
- Leetcode 553.最优除法
最优除法 给定一组正整数,相邻的整数之间将会进行浮点除法操作.例如, [2,3,4] -> 2 / 3 / 4 . 但是,你可以在任意位置添加任意数目的括号,来改变算数的优先级.你需要找出怎么添 ...
- gcc学习记录
-Wall: 使输出中包含警告信息,提示一些可以避免的错误.如果没有错误,则不会输出信息. -o:后面加上可执行文件的名字.如果不加-o选项,会默认生成a.out可执行文件.举例:gcc -Wall ...
- spring bean自动注入
使用 @Repository.@Service.@Controller 和 @Component 将类标识为 Bean Spring 自 2.0 版本开始,陆续引入了一些注解用于简化 Spring 的 ...
- [AHOI2014&&JSOI2014][bzoj3876] 支线剧情 [上下界费用流]
题面 传送门 思路 转化模型:给一张有向无环图,每次你可以选择一条路径走,花费的时间为路径上边权的总和,问要使所有边都被走至少一遍(可以重复),至少需要花费多久 走至少一遍,等价于覆盖这条边 也就是说 ...
- KM算法【带权二分图完美匹配】
先orz litble--KM算法 为什么要用KM算法 因为有的题丧心病狂卡费用流 KM算法相比于费用流来说,具有更高的效率. 算法流程 我们给每一个点设一个期望值[可行顶标] 对于左边的点来说,就是 ...