有点麻烦..

/*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. python redis基本操作

    #!/usr/bin/env python #-*- coding:utf-8 -*- # author:leo # datetime:2019/4/24 16:26 # software: PyCh ...

  2. 由一道CTF pwn题深入理解libc2.26中的tcache机制

    本文首发安全客:https://www.anquanke.com/post/id/104760 在刚结束的HITB-XCTF有一道pwn题gundam使用了2.26版本的libc.因为2.26版本中加 ...

  3. Cobbler自动安装的Linux系统ssh无法进入

    Linux ssh登陆老提示“permission denied,please try again” ,但是iptables已经关掉了 修改/etc/ssh/sshd_config文件.找如下的一句 ...

  4. R+hadoop

    这里面的配置 http://www.rdatamining.com/big-data/r-hadoop-setup-guide root@kali:~/hadoop_home/hadoop-1.2.1 ...

  5. 跟我一起从零开始学WCF系列课程

    http://www.microsoft.com/china/msdn/events/webcasts/shared/webcast/Series/WCF_Begin.aspx 服务和协定 服务协定使 ...

  6. arr.forEach()与for...in的用法举例

    1.forEach() 将给定的数字转换成罗马数字. 所有返回的 罗马数字 都应该是大写形式. function convert(num) { var str = ""; var ...

  7. Http请求 GET和POST,405错误

    我就简单说吧,在用SringMVC时,我们通常会用到 @RequestMapping(value="/test",method=RequestMethod.GET) public ...

  8. 《TensorFlow实战》中AlexNet卷积神经网络的训练中

    TensorFlow实战中AlexNet卷积神经网络的训练 01 出错 TypeError: as_default() missing 1 required positional argument: ...

  9. 使用VUE开发

    <一>VUE的开发分两种,一种是直接在HTML文件中使用,一种是VUE文件的形式开发 1,首先我们先让 HTML 文件支持 VUE 的语法指令提示 2,File -> Setting ...

  10. JZOJ 2136. 【GDKOI2004】汉诺塔

    2136. [GDKOI2004]汉诺塔 (Standard IO) Time Limits: 3000 ms  Memory Limits: 128000 KB  Detailed Limits   ...