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. 网易的Spark技术实践

    http://www.infoq.com/cn/news/2014/04/netease-spark-practice?utm_source=infoq&utm_medium=popular_ ...

  2. JPA(四):EntityManager

    Persistence Persistence类使用于获取EntityManagerFactory实例,该类包含一个名为createEntityManagerFactory的静态方法. // 创建En ...

  3. Ubuntu mysql开启远程登录的方法

    一.问题 Ubuntu  16.0.4   mysql5.7 二.解决问题 Ubuntu中MySQL的配置文件是在/etc/mysql/mysql.conf.d/mysqld.cnf,VI该文件把 b ...

  4. mongodb最大连接数、最大连接数修改

        mongodb最大连接数是20000. 所以业界流传一段话,千万级以下的用mysql.千万级以上的用mongodb,亿级以上的用hadoop.   查看mongodb最大连接数 mongodb ...

  5. Mac os 系统头像位置。

    ~/Library/Containers/com.apple.ImageKit.RecentPictureService/Data/Library/Images/Recent Pictures/

  6. ZH奶酪:如何在Ubuntu上安装Java/管理多个JAVA/设置JAVA_HOME

    0.简介 Java的地位及重要性,大家都懂的,很多软件都依赖于jdk,在Ubuntu上安装Java的选择有很多,openJDK,Oracle Jdk... 1.安装默认 JRE/JDK(可选) 这是最 ...

  7. 【医疗行业】关于dcm4che DICOM Toolkit:C-Move与C-Get

    在医学影像领域,DICOM标准与dcm4che的重要性毋庸置疑.幸好,这些开源的dcm4che DICOM 工具包,能对我们提供不少帮助. 在这里有很多的工具: Sources: https://gi ...

  8. 查看postgre都有哪些语句占用CPU,以及对应的sql语句

    查看占用CPU最多的几个postgresql ps aux | grep postgres | sort -n -r -k | head - | awk '{print $2, $3}' 查看所有po ...

  9. java 加密

    加密.大体上分为双向加密和单向加密,而双向加密又分为对称加密和非对称加密. 双向加密大体意思就是明文加密后形成密文,能够通过算法还原成明文. 单向加密仅仅是对信息进行了摘要计算,不能通过算法生成明文. ...

  10. 字符串匹配算法——BF、KMP、Sunday

    一:Brute force 从源串的第一个字符开始扫描,逐一与模式串的对应字符进行匹配,若该组字符匹配,则检测下一组字符,如遇失配,则退回到源串的第二个字符,重复上述步骤,直到整个模式串在源串中找到匹 ...