有点麻烦..

/*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. java poi读取excel公式,返回计算值(转)

    http://blog.csdn.net/CYZERO/article/details/6573015 经测试,确实可以 1 package hrds.zpf.poi;  2  3  import o ...

  2. 博弈论经典算法(一)——对抗搜索与Alpha-Beta剪枝

    前言 在一些复杂的博弈论题目中,每一轮操作都可能有许多决策,于是就会形成一棵庞大的博弈树. 而有一些博弈论题没有什么规律,针对这样的问题,我们就需要用一些十分玄学的算法. 例如对抗搜索. 对抗搜索简介 ...

  3. 2017.12.23 第二章 统一建模语言UML概述

    第二章 统一建模语言UML概述 (1)为什么要建模 模型是某个事物的抽象,其目的是在构建这个事物之前先来理解它,因为模型忽略了那些非本质的细节,这样有利于更好的理解和表示事物: 在软件系统开发之前首先 ...

  4. pip 安装出现异常

    MacBookPro:~ mac$ pip install numpy Collecting numpy Downloading numpy-1.13.1-cp35-cp35m-macosx_10_6 ...

  5. 题解 P2626 【斐波那契数列(升级版)】

    这道题,大家一定要注意: 要对2^31取模 ! ( 本蒟蒻开始没注意到这一点,WA了 ) (不过大家在试样例的时候,试试47,出不了结果,就说明你没模2^31) 总体来说,这道题考查的知识点就两个: ...

  6. PAT (Advanced Level) Practise - 1094. The Largest Generation (25)

    http://www.patest.cn/contests/pat-a-practise/1094 A family hierarchy is usually presented by a pedig ...

  7. 解决Jquery中使用each循环时,循环外的js依旧会执行

    今天在改项目bug时,发现一个问题,我获取一个div中所有的input,并取值时,判断某一条件,但是循环外的js依然可以执行. $(".tab-reg-next input").e ...

  8. UsbKey开发

    http://slf-1983.blog.163.com/blog/static/2990236320121113113955119/

  9. 阻止touchslider事件冒泡,防止左右滑动时出发全局滑动事件

    最近适用mui开发一个项目,全局有个侧滑菜单offCanvasSideScroll,首页用了一个touchslider插件来实现行的左右滚动 touchslider的当滚动方向与侧滑菜单滚动方向一致时 ...

  10. Fakeapp 入门教程(2):使用篇!

    Fakeapp软件的使用主要分成了三个步骤, 使用之前请确保你的电脑配置还可以,推荐配置是:一张显存大于4G的N卡.Fakeapp是有支持CPU选项,但是用CPU跑非常慢. 获取脸部图片 训练模型 生 ...