Stones

Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 662    Accepted Submission(s): 391

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, when he meet a stone, he will throw it ahead as far as possible if it is the odd stone he meet, or leave it where it was if it is the even stone. Now give you some informations about the stones on the road, you are to tell me the distance from the start point to the farthest stone after Sempr walk by. Please pay attention that if two or more stones stay at the same position, you will meet the larger one(the one with the smallest Di, as described in the Input) first.
 
Input
In the first line, there is an Integer T(1<=T<=10), which means the test cases in the input file. Then followed by T test cases. 
For each test case, I will give you an Integer N(0<N<=100,000) in the first line, which means the number of stones on the road. Then followed by N lines and there are two integers Pi(0<=Pi<=100,000) and Di(0<=Di<=1,000) in the line, which means the position of the i-th stone and how far Sempr can throw it.
 
Output
Just output one line for one test case, as described in the Description.
 
Sample Input
2
2
1 5
2 4
2
1 5
6 6
 
Sample Output
11
12
 
Author
Sempr|CrazyBird|hust07p43
 
Source
 
Recommend
lcy
 

看懂题意,模拟即可:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<cstdlib> using namespace std; struct node{
int loc,dis;
bool operator < (const node &a) const{
if(a.loc==loc)
return a.dis<dis;
return a.loc<loc;
}
}; int main(){ //freopen("input.txt","r",stdin); priority_queue<node> q;
int t,n;
scanf("%d",&t);
node cur;
while(t--){
while(!q.empty())
q.pop();
scanf("%d",&n);
int a,b;
while(n--){
scanf("%d%d",&a,&b);
cur.loc=a; cur.dis=b;
q.push(cur);
}
int ans=;
int cnt=,tmp=;
while(!q.empty()){
if(cnt&){ //第奇数个石子还得往前扔
ans+=q.top().loc-tmp;
tmp=q.top().loc;
cur.loc=tmp+q.top().dis;
cur.dis=q.top().dis;
q.pop();
//printf(" ** %d\n",cur.loc);
q.push(cur);
}else{
ans+=q.top().loc-tmp;
tmp=q.top().loc;
q.pop();
//printf(" ## %d\n",cur.loc);
}
cnt++;
//printf("tmp=%d ans=%d\n",tmp,ans);
}
printf("%d\n",ans);
}
return ;
}

HDU 1896 Stones (优先队列)的更多相关文章

  1. HDU 1896 Stones (优先队列)

    Problem Description Because of the wrong status of the bicycle, Sempr begin to walk east to west eve ...

  2. HDU 1896 Stones --优先队列+搜索

    一直向前搜..做法有点像模拟.但是要用到出队入队,有点像搜索. 代码: #include <iostream> #include <cstdio> #include <c ...

  3. HDU 1896 Stones(优先队列)

    还是优先队列 #include<iostream> #include<cstdio> #include<cstring> #include<queue> ...

  4. hdu 1896.Stones 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1896 题目意思:给出 n 块石头的初始位置和能到达的距离.对于第奇数次遇到的石头才抛掷,偶数次的就忽略 ...

  5. hdu 1509 & hdu 1873 & hdu 1896 (基础优先队列)

    http://acm.hdu.edu.cn/showproblem.php?pid=1509 裸的优先队列的应用,输入PUT的时候输入名字,值和优先值进队列,输入GRT的时候输出优先值小的名字和对应的 ...

  6. HDU 1896:Stones(优先队列)

    Stones Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Sub ...

  7. Stones HDU 1896

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1896 题目大意: 有n个石头,每个石头有:p  它所在的位置 ,d  它能扔多远 从0 开始,遇到第奇 ...

  8. hdoj 1896 Stones【优先队列】

    Stones Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Subm ...

  9. E - Stones 优先队列

    来源1896 Because of the wrong status of the bicycle, Sempr begin to walk east to west every morning an ...

随机推荐

  1. 【R】自定义函数方法

  2. Spring(二十):Spring AOP(四):基于配置文件的方式来配置 AOP

    基于配置文件的方式来配置 AOP 前边三个章节<Spring(十七):Spring AOP(一):简介>.<Spring(十八):Spring AOP(二):通知(前置.后置.返回. ...

  3. MFC对话框:模态对话框及其弹出过程

    From: http://www.jizhuomi.com/school/c/160.html 加法计算器对话框程序大家照着做一遍后,相信对基于对话框的程序有些了解了,有个好的开始对于以后的学习大有裨 ...

  4. GLFW_KEY_KP_ADD和GLFW_KEY_KP_SUBTRACT

      这两个键的代码分别为: GLFW_KEY_KP_ADD(334) GLFW_KEY_KP_SUBTRACT(333)   对应的是键盘右侧数字面板上的+ -键.

  5. java 大文件上传 断点续传 完整版实例 (Socket、IO流)

    ava两台服务器之间,大文件上传(续传),采用了Socket通信机制以及JavaIO流两个技术点,具体思路如下: 实现思路: 1.服:利用ServerSocket搭建服务器,开启相应端口,进行长连接操 ...

  6. PHP Manager for IIS

    SOAP error on IIS8 Registering new PHP version sets bad values set for FastCGI activityTimeout, requ ...

  7. 【linux】Ubuntu中shell脚本无法使用source的原因及解决方法

    问题现象: shell脚本中source aaa.sh时提示 source: not found 原因: ls -l `which sh` 提示/bin/sh -> dash 这说明是用dash ...

  8. linux中fuser用法详解

    fuser功能 fuser 可以显示出当前哪个程序在使用磁盘上的某个文件.挂载点.甚至网络端口,并给出程序进程的详细信息.  fuser显示使用指定文件或者文件系统的进程ID.默认情况下每个文件名后面 ...

  9. c++10进制转换为任意2-16进制数字

    #include<stdio.h> #include<stdlib.h> #include<iostream> using namespace std; int m ...

  10. python乱码问题之爬虫篇

    UnicodeDecodeError: 'gbk' codec can't decode byte 0xae in position 167: illegal multibyte sequence 使 ...