有点麻烦..

/*hdu6136[模拟+优先队列] 2017多校8*/
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
struct frac {
LL p, q;
frac(LL P, LL Q) {
p = P / __gcd(P, Q);
q = Q / __gcd(P, Q);
}
frac() {p = , q = ;}
bool operator < (const frac& a) const {
return p * a.q < q * a.p;
}
bool operator > (const frac& a) const {
return p * a.q > q * a.p;
}
frac operator + (frac a) const {
LL d = __gcd(q, a.q);
LL P = a.q / d * p + q / d * a.p;
return frac(P, q / d * a.q);
}
};
ostream& operator << (ostream& out, const frac& a) {
out << a.p << "/" << a.q ;
return out;
}
struct node {
LL v; LL d;
int s, pos;
node(LL V = , LL D = , int S = ): v(V), d(D), s(S) {}
} a[];
struct Node {
int l, r;
frac f;
Node(int L, int R, frac F): l(L), r(R) , f(F) {}
Node() {r = l = ;}
bool operator < (const Node& a) const {
return f > a.f;
}
};
bool cmp(const node& a, const node& b) {
return a.d < b.d;
}
int T, n, dead[], nxt[], pre[];
LL l;
frac gettime(node a, node b) {
LL dist = b.d - a.d;
if (dist < ) dist = l - (a.d - b.d);
if (a.v >= && b.v <= ) {
return frac(dist, a.v - b.v);
}
if (a.v <= && b.v >= ) {
return frac(l - dist, b.v - a.v);
}
if (a.v >= && b.v >= ) {
if (b.v > a.v) {
return frac(l - dist, b.v - a.v);
}
else return frac(dist, a.v - b.v);
}
else if (a.v <= && b.v <= ) {
if (b.v < a.v) {
return frac(dist, a.v - b.v);
}
else return frac(l - dist, b.v - a.v);
}
return frac();
}
void del(int x) {
nxt[pre[x]] = nxt[x];
pre[nxt[x]] = pre[x];
}
void solve() {
//memset(nxt, 0, sizeof(nxt));
//memset(pre, 0, sizeof(pre));
memset(dead, , sizeof(dead));
sort(a, a + n, cmp);
priority_queue<Node>q;
for (int i = ; i < n; i++) {
if (n == ) {
nxt[] = , pre[] = ;
nxt[] = , pre[] = ;
q.push(Node(, , gettime(a[], a[])));
break;
}
nxt[i] = (i + ) % n;
pre[(i + ) % n] = i;
q.push(Node(i, (i + ) % n, gettime(a[i], a[(i + ) % n])));
} frac ans(, );
int deadnum = ;
while (!q.empty()) {
Node now = q.top();
q.pop();
if (dead[now.l] || dead[now.r]) continue;
// puts("");
//cout << a[now.l].s << " meet " << a[now.r].s << endl;
//cout << "dist: " << a[now.l].d << ' ' << a[now.r].d << endl;
//cout << "need: " << now.f << endl;
if (deadnum == n - ) {
while (!q.empty()) {
now = q.top();
q.pop();
if (!dead[now.l] && !dead[now.r]) {
break;
}
}
ans = now.f;
break;
}
if (a[now.l].s > a[now.r].s) {
del(now.r);
dead[now.r]++; deadnum++;
//cout << "kill: " << a[now.r].s << endl;
//cout << "push: " << a[now.l].d << ' ' << a[nxt[now.l]].d << endl;
if (now.l != nxt[now.l])
q.push(Node(now.l, nxt[now.l], gettime(a[now.l], a[nxt[now.l]])));
}
else {
del(now.l);
dead[now.l]++; deadnum++;
//cout << "kill: " << a[now.l].s << endl;
// cout << "push: " << a[pre[now.r]].d << ' ' << a[now.r].d << endl;
if (pre[now.r] != now.r)
q.push(Node(pre[now.r], now.r, gettime(a[pre[now.r]], a[now.r])));
}
}
printf("%lld/%lld\n", ans.p, ans.q);
}
int main() {
scanf("%d", &T);
while (T--) {
scanf("%d%lld", &n, &l);
for (int i = ; i < n; i++) {
a[i].s = i;
scanf("%lld", &a[i].d);
}
for (int i = ; i < n; i++) {
scanf("%lld", &a[i].v);
}
solve();
}
return ;
}

hdu6136[模拟+优先队列] 2017多校8的更多相关文章

  1. hdu6034[模拟] 2017多校1

    /*hdu6034[模拟] 2017多校1*/ //暴力模拟26个26进制数即可, 要注意进位 #include<bits/stdc++.h> using namespace std; t ...

  2. 2017 多校5 hdu 6093 Rikka with Number

    2017 多校5 Rikka with Number(数学 + 数位dp) 题意: 统计\([L,R]\)内 有多少数字 满足在某个\(d(d>=2)\)进制下是\(d\)的全排列的 \(1 & ...

  3. 2017 多校5 Rikka with String

    2017 多校5 Rikka with String(ac自动机+dp) 题意: Yuta has \(n\) \(01\) strings \(s_i\), and he wants to know ...

  4. 2017 多校4 Wavel Sequence

    2017 多校4 Wavel Sequence 题意: Formally, he defines a sequence \(a_1,a_2,...,a_n\) as ''wavel'' if and ...

  5. 2017 多校4 Security Check

    2017 多校4 Security Check 题意: 有\(A_i\)和\(B_i\)两个长度为\(n\)的队列过安检,当\(|A_i-B_j|>K\)的时候, \(A_i和B_j\)是可以同 ...

  6. 2017 多校3 hdu 6061 RXD and functions

    2017 多校3 hdu 6061 RXD and functions(FFT) 题意: 给一个函数\(f(x)=\sum_{i=0}^{n}c_i \cdot x^{i}\) 求\(g(x) = f ...

  7. 2017 多校2 hdu 6053 TrickGCD

    2017 多校2 hdu 6053 TrickGCD 题目: You are given an array \(A\) , and Zhu wants to know there are how ma ...

  8. 2017 多校1 I Curse Myself

    2017 多校2 I Curse Myself(第k小生成树) 题目: 给一张带权无向连通图,该图的任意一条边最多只会经过一个简单环,定义\(V(k)为第k小生成树的权值和\),求出\(\sum_{k ...

  9. hdu6134[莫比乌斯反演] 2017多校8

    /*hdu6134[莫比乌斯反演] 2017多校8*/ #include <bits/stdc++.h> using namespace std; typedef long long LL ...

随机推荐

  1. UVA 215 Spreadsheet Calculator (模拟)

    模拟题.每个单元格有表达式就dfs,如果有环那么就不能解析,可能会重复访问到不能解析的单元格,丢set里或者数组判下重复. 这种题首先框架要对,变量名不要取的太乱,细节比较多,知道的库函数越多越容易写 ...

  2. bzoj4622 [NOI 2003] 智破连环阵

    Description B国在耗资百亿元之后终于研究出了新式武器——连环阵(Zenith Protected Linked Hybrid Zone).传说中,连环阵是一种永不停滞的自发性智能武器.但经 ...

  3. python_21_copy

    import copy person=['name',['saving',100]] #3种浅copy方式 p1=copy.copy(person) p2=person[:] p3=list(pers ...

  4. utf8、ansii、unicode编码之间的转换

    #include "stdafx.h"#include "windows.h"#include <iostream>#include <str ...

  5. Solr7部署报错:java.lang.NoSuchMethodError: javax.servlet.ServletInputStream.isFinished()Z

    错误信息: Servlet.service() for servlet [default] in context with path [/solr] threw exception [Filter e ...

  6. C盘扩展卷是灰色的扩容方法

    当想要扩容C盘的时候可能会发现C盘的扩展卷竟然是灰色的.原因是C盘旁边没有紧挨着的“”未分配空间“”, 只要将D盘的空间分出一些来就可以了. !!!磁盘的分区合并有风险,重要文件等记得先备份  !!! ...

  7. LeetCode954二倍数对数组

    问题:二倍数对数组 给定一个长度为偶数的整数数组 A,只有对 A 进行重组后可以满足 “对于每个 0 <= i < len(A) / 2,都有 A[2 * i + 1] = 2 * A[2 ...

  8. DevOps - 日志分析 -ELK

    wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-co ...

  9. Play on Words HDU - 1116 (并查集 + 欧拉通路)

    Play on Words HDU - 1116 Some of the secret doors contain a very interesting word puzzle. The team o ...

  10. [BZOJ3684][拉格朗日反演+多项式求幂]大朋友和多叉树

    题面 Description 我们的大朋友很喜欢计算机科学,而且尤其喜欢多叉树.对于一棵带有正整数点权的有根多叉树,如果它满足这样的性质,我们的大朋友就会将其称作神犇的:点权为\(1\)的结点是叶子结 ...