2017多校联合第八场/hdu 6136Death Podracing(优先队列+循环链表)
来源:互联网 发布:sqlserver 截断日志 编辑:程序博客网 时间:2024/05/18 15:55
Death Podracing
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 448 Accepted Submission(s): 178
Problem Description
> During the Trade Federation invasion of Naboo, Anakin Skywalker won the Boonta Eve Classic on Tatooine, securing his freedom from a life of slavery. Betting on the races was a popular pastime with many of the watchers on Tatooine and it was through Qui-Gon Jinn's bet with Watto that Skywalker would win the race that Skywalker was freed.
>
> — Wookieepedia
Here comes the most awesome racing in the universe! Little Anakin sits in his own podracer, breathing deeply. He must win.
The real podracing is deadly. In this circular track (againL in length), participants start in distinct locations and race with distinct speeds (the speed can be positive and minus, which means running clockwise and counterclockwise). Every podracer is equipped with a powerful weapon system respectively -- all for triumphing over enemies!!! yes! enemies!
If two competitors meet, which means that they reach an identical location simultaneously, the one with less powerful weapon system will be destroyed and be knocked out of the racing -- dead or alive. The power of thei -th participant is exactly i , and because each person runs with a distinct speed, so there must be a winner.
The racing stops when there is only one person still running in the track -- our winner! The others are crushed into pieces.
Little Anakin wants to know, when the racing will stop.
>
> — Wookieepedia
Here comes the most awesome racing in the universe! Little Anakin sits in his own podracer, breathing deeply. He must win.
The real podracing is deadly. In this circular track (again
If two competitors meet, which means that they reach an identical location simultaneously, the one with less powerful weapon system will be destroyed and be knocked out of the racing -- dead or alive. The power of the
The racing stops when there is only one person still running in the track -- our winner! The others are crushed into pieces.
Little Anakin wants to know, when the racing will stop.
Input
The first line contains an integer T (T≤1000 ), denoting the number of test cases.
For each test case, the first line contains two integersn (2≤n≤105 ) and L (1≤L≤109 ).
The following line containsn distinct integers d1,d2,...,dn (0≤di<L ), representing the starting points of the participants.
The next line containsn distinct integers v1,v2,...,vn (0≤|vi|≤109 ), representing the velocity of the participants.
The sum of alln in all test cases doesn't exceed 2×106 .
For each test case, the first line contains two integers
The following line contains
The next line contains
The sum of all
Output
One line for each test case. You should output the answer that is reduced to lowest terms.
Sample Input
22 40 23 210 10056 89 62 71 7 24 83 1 47 529 -16 34 -38 47 49 -32 17 39 -9
Sample Output
2/137/7
Source
2017 Multi-University Training Contest - Team 8
Recommend
liuyiding | We have carefully selected several similar problems for you: 6181 6180 6179 6178 6177
【题目大意】
一堆人在操场上跑步,他们都有一定的速度和初始位置,
当两个人相遇的时候编号较小的就会出局,当场上剩下最后一个人的时候游戏结束,
问时长为多少
【题解】
我们发现每次发生碰撞的一定是相邻的两个人,
所以我们找出相邻关系中最先发生碰撞的,将碰撞失败的那个人删除,
之后继续这个过程,
按照上述的做法我们建立一个循环链表,把所有人串起来,
当发生淘汰的时候把那个人从循环链表中删去即可,
用优先队列维护相邻关系,每次出队最小相遇时间即可。
#include <iostream>#include <algorithm>#include <cstdio>#include <cmath>#include <cstring>#include <string>#include <string.h>#include <map>#include <set>#include <queue>#include <deque>#include <list>#include <bitset>#include <stack>#include <stdlib.h>#define lowbit(x) (x&-x)#define e exp(1.0)#define eps 1e-8//ios::sync_with_stdio(false);// auto start = clock();// cout << (clock() - start) / (double)CLOCKS_PER_SEC<<endl;typedef long long ll;typedef long long LL;using namespace std;typedef unsigned long long ull;const int maxn=1e5+10;const int inf=0x3f3f3f3f;struct data{ int d,v,pw;}p[maxn];int cmp(data &a,data &b){ return a.d<b.d;}int del[maxn],n,l,nxt[maxn],pre[maxn];struct node{ int den,num; node(){} node(int num,int den) { this->num=num; this->den=den; } bool operator<(const node &a)const { return (ll)num*a.den<(ll)a.num*den; }};node cal(data a,data b){ int V=b.v-a.v; int D=a.d-b.d; if(D<0) D+=l; if(V<0) V=-V,D=l-D; if(V==0) return node(inf,1); int GCD=__gcd(V,D); return node(D/GCD,V/GCD);}struct relt{ int a,b; node t; relt(){} relt(int a,int b,node t) { this->a=a; this->b=b; this->t=t; } bool operator<(const relt &a)const { return a.t<t; }};priority_queue<relt>q;void out(int x){ del[x]=1; nxt[pre[x]]=nxt[x]; pre[nxt[x]]=pre[x]; q.push(relt(pre[x],nxt[x],cal(p[pre[x]],p[nxt[x]])));}int main(){ ios::sync_with_stdio(false); int T; cin>>T; while(T--) { cin>>n>>l; memset(del,0,sizeof(del)); for(int i=0;i<n;i++) { cin>>p[i].d; p[i].pw=i; } for(int i=0;i<n;i++) cin>>p[i].v; sort(p,p+n,cmp); while(!q.empty()) q.pop(); for(int i=0;i<n;i++) { nxt[i]=(i+1)%n; pre[i]=(i-1+n)%n; q.push(relt(i,nxt[i],cal(p[i],p[nxt[i]]))); } int le=n; node ans; while(!q.empty()) { relt x=q.top(); q.pop(); if(del[x.a] || del[x.b]) continue; if(--le==1) { ans=x.t; break; } if(p[x.a].pw>p[x.b].pw) out(x.b); else out(x.a); } cout<<ans.num<<'/'<<ans.den<<endl; } return 0;}
阅读全文
0 0
- 2017多校联合第八场/hdu 6136Death Podracing(优先队列+循环链表)
- HDU 6136 Death Podracing(优先队列+循环链表)
- HDU 6136 Death Podracing(优先队列+双向链表)
- HDU 6136 Death Podracing 优先队列 + 循环链表(模拟)
- 解题报告:HDU_6136:Death Podracing (优先队列+循环链表)
- 【多校训练】hdu 6136 Death Podracing 优先队列
- HDU 6136 Death Podracing [链表]
- HDU 6136 Death Podracing (2017 Multi-Univ Training Contest 8)
- Death Podracing HDU
- [贪心+优先队列] hdu5360多校联合 第六场 Hiking
- [dp] hdu 5389 多校联合第八场 Zero Escape
- 2017多校联合第八场/hdu 6133 Army Formations(线段树合并)
- 2014多校联合-第八场
- 多校联合第八场hdu5387Clock 最大公约数
- 2017多校联合第二场 1008题 hdu 6052 To my boyfriend 计数 单调队列
- 2017多校联合第一场 1006题 hdu 6038 Function 循环节
- hdu5336 多校联合第四场1010 模拟+bfs优先队列
- 2015多校联合第五场 hdu5349 MZL's simple problem 优先队列
- LintCode:M-克隆图
- [LintCode]212.空格替换
- sqlmap 中文注释
- 创建Windows服务(C++)
- OSG-基本几何图形
- 2017多校联合第八场/hdu 6136Death Podracing(优先队列+循环链表)
- Ubuntu安装升级问题(续)
- mysql
- jq选项卡实现-弹出层效果
- java每日一练
- @RestController的使用
- 浅谈游戏开发之2D手游工具
- poj 2226
- 如何判断单链表是否有环?