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. javascript——获取列表选择行的列值

    表格布局 方法 代码 $("#send").click(function(){ //获取选择的行号 n= $('input:radio[name="radio" ...

  2. Overcoming the List View Threshold in SharePoint CAML queries

    From: https://www.codeproject.com/articles/1076854/overcoming-the-list-view-threshold-in-sharepoint- ...

  3. Mysql正则匹配某列是否含有手机号

    SELECT COUNT(1) FROM t_user WHERE user_name REGEXP ".[1][35678][0-9]{9}."; 解释: 正则中 .的意思是所有 ...

  4. wdcp下nginx+apache混合模式的主机配置

    /www/wdlinux/httpd-2.2.22/conf/vhost/xxx.xxx.com.conf <VirtualHost *:88>DocumentRoot /www/web/ ...

  5. git 本地与服务器的同步

    如果在服务器上直接用 git init 则会自动在当前目录创建.git目录但在本地clone后修改后,不能push,这是由于git默认拒绝了push操作,需要进行设置,修改.git/config添加如 ...

  6. 20160205.CCPP体系具体解释(0015天)

    程序片段(01):01.杨辉三角.c 内容概要:杨辉三角 #include <stdio.h> #include <stdlib.h> #define N 10 //01.杨辉 ...

  7. Zoning and LUN Masking

    In a SAN ( Storage Area Network ), if all the hosts are allowed to access all the drives in the SAN, ...

  8. 升级华为s2016

    Part 1 升级Bootrom 概述:启动启动菜单,用xmodem协议升级BootRom 升级的文件如下: wnm2.2.3-0004.zip :web网管zip压缩包文件. S2008_16-VR ...

  9. Java 通配符匹配查找文件

    比较了一下Java正则表达式与通配符之间的差别,很简单的进行了一下转化就行了.此外要注意String的replace和replaceAll的用法的含义,不要搞错了. 字符串匹配例子 String s  ...

  10. 算法笔记_216:第六届蓝桥杯软件类校赛部分真题(Java语言C组)

    目录 1 题目一 2 题目二 3 题目三 4 题目四 5 题目五 前言:以下代码仅供参考,若有错误欢迎指正哦~ 1 题目一 二项式的系数规律,我国数学家很早就发现了. 如[图1.png],我国南宋数学 ...