HDU 1896 Stones

  还是优先队列

#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
#define maxn 100010
struct Node
{
    int x,y,id;
    friend bool operator < (Node a,Node b)
    {
        if(a.x != b.x) return a.x > b.x;
        else if(a.y != b.y) return a.y > b.y;
        else return a.id < b.id;
    }
} node[maxn];
priority_queue<Node>que;
int main()
{
    int t,n;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        for(int i = 0; i < n; i++)
        {
            scanf("%d%d",&node[i].x,&node[i].y);
            node[i].id = i+1;
            que.push(node[i]);
        }
        int tot = 0,maxt = -9999;
        while(!que.empty())
        {
            tot++;
            Node tmp = que.top();
            que.pop();
            if(tot & 1 == 1)
            {
                Node next = tmp;
                next.x = tmp.x + tmp.y;
                if(next.x > maxt) maxt = next.x;
                que.push(next);
            }
        }
        printf("%d\n",maxt);
    }
    return 0;
}
时间: 2024-11-05 02:13:29

HDU 1896 Stones的相关文章

hdu 1896.Stones 解题报告

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1896 题目意思:给出 n 块石头的初始位置和能到达的距离.对于第奇数次遇到的石头才抛掷,偶数次的就忽略.问最多能扔到多远.如果有多颗石头在一个位置,距离小的那个标记为先遇到的. 所以先解说一下第二个测试案例: 2 1  5 6  6 在6这个位置的时候,由于5比6小,所以规定1(5)这个点是先遇上的,是偶数次遇到,所以忽略. 用优先队列做,位置近的优先级越高,如果位置相同,距离短的优先级越高. 1

HDU 1896 Stones (优先队列)

Problem Description Because of the wrong status of the bicycle, Sempr begin to walk east to west every morning and walk back every evening. Walking may cause a little tired, so Sempr always play some games this time. There are many stones on the road

hdu 杭电1896 Stones【优先队列】

Problem Description Because of the wrong status of the bicycle, Sempr begin to walk east to west every morning and walk back every evening. Walking may cause a little tired, so Sempr always play some games this time. There are many stones on the road

hdu 1509 &amp; hdu 1873 &amp; hdu 1896 (基础优先队列)

http://acm.hdu.edu.cn/showproblem.php?pid=1509 裸的优先队列的应用,输入PUT的时候输入名字,值和优先值进队列,输入GRT的时候输出优先值小的名字和对应的值 注意的是优先级一样的时候输出顺序在前的 1 #include<cstdio> 2 #include<cstring> 3 #include<queue> 4 using namespace std; 5 struct point { 6 int val,odr,num;

hdoj 1896 Stones

Stones Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 1474    Accepted Submission(s): 921 Problem Description Because of the wrong status of the bicycle, Sempr begin to walk east to west every

hdoj 1896 Stones【优先队列】

Stones Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 1363    Accepted Submission(s): 850 Problem Description Because of the wrong status of the bicycle, Sempr begin to walk east to west every

HDU 1896 【留个使用priority_queue容器的样例】

感谢<啊哈!算法>的讲解,水鸟弄懂了什么是优先队列. 题意是:在路上有很多石子,给出他们的初始位置和小明能够将他们扔出的距离,当小明遇到奇数个石子的时候就会把它扔出,遇到偶数个就会忽略他,一直走到路上没有石子为止,求解最后一个石子的位置. 一开始用排序做的,果断超时,看了题解才知道这是优先队列. 贴优先队列的代码: #include<stdio.h> int n; struct st { int pos,dis; }; st stone[100010]; void swap(int

HDU1896 优先队列2

D - 优先队列入门2 Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1896 Description Because of the wrong status of the bicycle, Sempr begin to walk east to west every morning and walk back every evenin

HDU 4573 Throw the Stones(动态三维凸包)(2013 ACM-ICPC长沙赛区全国邀请赛)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4573 Problem Description Remember our childhood? A few naked children throw stones standing on the same position, the one throws farther win the game. Aha, of course, there are some naughty boys who care