HDU 1896 Stones (优先队列)
Stones
Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 662 Accepted Submission(s): 391
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.
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.
2
1 5
2 4
2
1 5
6 6
12
看懂题意,模拟即可:
#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 (优先队列)的更多相关文章
- HDU 1896 Stones (优先队列)
Problem Description Because of the wrong status of the bicycle, Sempr begin to walk east to west eve ...
- HDU 1896 Stones --优先队列+搜索
一直向前搜..做法有点像模拟.但是要用到出队入队,有点像搜索. 代码: #include <iostream> #include <cstdio> #include <c ...
- HDU 1896 Stones(优先队列)
还是优先队列 #include<iostream> #include<cstdio> #include<cstring> #include<queue> ...
- hdu 1896.Stones 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1896 题目意思:给出 n 块石头的初始位置和能到达的距离.对于第奇数次遇到的石头才抛掷,偶数次的就忽略 ...
- hdu 1509 & hdu 1873 & hdu 1896 (基础优先队列)
http://acm.hdu.edu.cn/showproblem.php?pid=1509 裸的优先队列的应用,输入PUT的时候输入名字,值和优先值进队列,输入GRT的时候输出优先值小的名字和对应的 ...
- HDU 1896:Stones(优先队列)
Stones Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total Sub ...
- Stones HDU 1896
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1896 题目大意: 有n个石头,每个石头有:p 它所在的位置 ,d 它能扔多远 从0 开始,遇到第奇 ...
- hdoj 1896 Stones【优先队列】
Stones Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Subm ...
- E - Stones 优先队列
来源1896 Because of the wrong status of the bicycle, Sempr begin to walk east to west every morning an ...
随机推荐
- 3分钟搞定Linux系统正则表达式
正则表达式是一种字符模式,用于在查找过程中匹配制定的字符. 元字符通常在Linux中分为两类:Shell元字符,由Linux Shell进行解析:正则表达式元字符,由vi/grep/sed/awk等文 ...
- 阿里云centos安装ftp与svn过程
1.下载xshell或者secureCRT 2.登录centos或者服务器 3.安装vsftpd [root@xxx]# yum install vsftpd //安装vsftpd [root@xxx ...
- OpenGL ES 3.0顶点着色器(二)
#version es uniform mat4 u_mvpMatrix; in vec4 a_position; in vec4 a_color;out vec4 v_color;void main ...
- firefox chrome ie9,10,11 不支持selectSingleNode和selectNodes的解决方法
firefox并不支持selectSingleNode和selectNodes的解决方法 function test(){ var perid = document.thisForm.PerID.va ...
- Using a Microsoft Account to Logon and Resulting Internet Communication in Windows 8
Using a Microsoft Account to Logon and Resulting Internet Communication in Windows 8 此主题尚未评级 - 评价此主题 ...
- 算法笔记_221:串的简单处理(Java)
目录 1 问题描述 2 解决方案 1 问题描述 串的处理在实际的开发工作中,对字符串的处理是最常见的编程任务.本题目即是要求程序对用户输入的串进行处理.具体规则如下:1. 把每个单词的首字母变为大 ...
- 算法笔记_204:第四届蓝桥杯软件类决赛真题(Java语言C组)
目录 1 好好学习 2 埃及分数 3 金蝉素数 4 横向打印二叉树 5 危险系数 6 公式求值 前言:以下代码仅供参考,若有错误欢迎指正哦~ 1 好好学习 汤姆跟爷爷来中国旅游.一天,他帮助中国的 ...
- Maven的坐标与资源库
在Maven世界中,每个工程都有它唯一的 组织名.模块名.版本 ,这三个就是maven项目的坐标,一个maven工程可以打包成jar.war.pom等形式,但是它们都是拥有上述三个坐标的.我们在项目过 ...
- Java多线程之syncrhoized内置互斥锁的用法详解
转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/5827547.html 解决并行冲突最有效的方法就是加同步锁,主要有以下几种方法: 1:动态方法 ...
- vim自动保存折叠
我经常使用的是手工折叠方式,就是 :set foldmethod=manual vim常用的折叠命令有: zf:折叠选定的行 zo:打开折叠 zR:打开所有折叠 zM:关闭所有折叠 zd:删除折叠 我 ...