hdu6136[模拟+优先队列] 2017多校8
有点麻烦..
/*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的更多相关文章
- hdu6034[模拟] 2017多校1
/*hdu6034[模拟] 2017多校1*/ //暴力模拟26个26进制数即可, 要注意进位 #include<bits/stdc++.h> using namespace std; t ...
- 2017 多校5 hdu 6093 Rikka with Number
2017 多校5 Rikka with Number(数学 + 数位dp) 题意: 统计\([L,R]\)内 有多少数字 满足在某个\(d(d>=2)\)进制下是\(d\)的全排列的 \(1 & ...
- 2017 多校5 Rikka with String
2017 多校5 Rikka with String(ac自动机+dp) 题意: Yuta has \(n\) \(01\) strings \(s_i\), and he wants to know ...
- 2017 多校4 Wavel Sequence
2017 多校4 Wavel Sequence 题意: Formally, he defines a sequence \(a_1,a_2,...,a_n\) as ''wavel'' if and ...
- 2017 多校4 Security Check
2017 多校4 Security Check 题意: 有\(A_i\)和\(B_i\)两个长度为\(n\)的队列过安检,当\(|A_i-B_j|>K\)的时候, \(A_i和B_j\)是可以同 ...
- 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 ...
- 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 ...
- 2017 多校1 I Curse Myself
2017 多校2 I Curse Myself(第k小生成树) 题目: 给一张带权无向连通图,该图的任意一条边最多只会经过一个简单环,定义\(V(k)为第k小生成树的权值和\),求出\(\sum_{k ...
- hdu6134[莫比乌斯反演] 2017多校8
/*hdu6134[莫比乌斯反演] 2017多校8*/ #include <bits/stdc++.h> using namespace std; typedef long long LL ...
随机推荐
- IOS UITextFieldDelegate (常用的代理方法)
#pragma mark - UITextFieldDelegate // 返回NO代表着文本输入框不可以改变(不可以编辑) - (BOOL)textField:(UITextField *)text ...
- World Wind Java开发之四——搭建本地WMS服务器(转)
在提供地理信息系统客户端时,NASA还为用户提供了开源的WMS Server 服务器应用:World Wind WMS Server.利用这个应用,我们可以架设自己的WMS服务并使用自己的数据(也支持 ...
- 关于profile集合
profile集合是mongodb的慢操作日志 > db.getProfilingStatus() { , , } 可以通过getProfilingStatus来查看当前profile设置 pr ...
- 分布式版本控制系统git
最近看到这篇文章,简洁易懂,特摘抄至https://www.cnblogs.com/bgwhite/p/9403233.html 供大家提供参考. git可以说是世界上最先进的版本控制系统,大多语句的 ...
- Python实现进度条小程序
一.print()参数介绍 1.end:指定打印结束后添加的字符,默认值为换行符 for j in range(3): print('hello world') for i in range(3): ...
- Jmeter模拟http请求
一.获取用户信息(GET请求):http://hostname/getuser?userid=1 1.打开jmeter,创建一个线程组,再添加一个http请求Sampler 2.设置域名.路径.请求方 ...
- Luogu P1471 方差
题目传送门 开了十倍空间才过是什么鬼?该不会我线段树炸了吧-- 细思极恐 平均数都会求,维护区间和,到时候除一下就好了. 方差的求法如下 (用的Luogu的图片) 因为要维护一个平方,我们可以考虑使用 ...
- Jquery-EasyUI combobox下拉框使用
制作一个json文件: <input data-options="url:'${pageContext.request.contextPath }/json/combobox_data ...
- VM内存溢出
平常开发时,有的人会运行的同时,会改代码,可能会导致VM内存溢出 Eclipse需要设置如下步骤: 1.点击Run>Run Configurations.. 2.定位到Tomcat(自己本地配置 ...
- Linux菜鸟起飞之路【一】基本知识与Linux的安装
一.操作系统基本常识 1.操作系统的定义:操作系统是用来协调.管理和控制计算机硬件与软件资源的系统程序,介于硬件与应用程序之间. 2.操作系统内核的定义:操作系统内核是一个管理和控制程序,负责管理计算 ...