2017多校联合第八场/hdu 6136Death Podracing(优先队列+循环链表)

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 (again  L 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 the  i-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.
 

Input
The first line contains an integer  T ( T1000), denoting the number of test cases. 

For each test case, the first line contains two integers  n ( 2n105) and  L ( 1L109).

The following line contains  n distinct integers  d1,d2,...,dn ( 0di<L), representing the starting points of the participants. 

The next line contains  n distinct integers  v1,v2,...,vn ( 0|vi|109), representing the velocity of the participants.

The sum of all  n in all test cases doesn't exceed  2×106.
 

Output
One line for each test case. You should output the answer that is reduced to lowest terms.
 

Sample Input
 
           
2 2 4 0 2 3 2 10 100 56 89 62 71 7 24 83 1 47 52 9 -16 34 -38 47 49 -32 17 39 -9
 

Sample Output
 
           
2/1 37/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 
 

Statistic |  Submit |  Discuss |  Note


【题目大意】

  一堆人在操场上跑步,他们都有一定的速度和初始位置,
  当两个人相遇的时候编号较小的就会出局,当场上剩下最后一个人的时候游戏结束,
  问时长为多少

 

【题解】

  我们发现每次发生碰撞的一定是相邻的两个人,
  所以我们找出相邻关系中最先发生碰撞的,将碰撞失败的那个人删除,
  之后继续这个过程,
  按照上述的做法我们建立一个循环链表,把所有人串起来,
  当发生淘汰的时候把那个人从循环链表中删去即可,
  用优先队列维护相邻关系,每次出队最小相遇时间即可。


#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#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<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.tq;
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>p[i].d;
            p[i].pw=i;
        }
        for(int i=0;i>p[i].v;
        sort(p,p+n,cmp);
        while(!q.empty())
            q.pop();
        for(int i=0;ip[x.b].pw) out(x.b);
            else out(x.a);
        }
        cout<

你可能感兴趣的:(STL,==数据结构==)