hdoj-1896 stones
Stones
Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 1375 Accepted Submission(s): 859
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
2
1 5
2 4
2
1 5
6 6
11
12#include<stdio.h>
#include<algorithm>
#include<queue>
using namespace std;
struct Stone/*存放石头的坐标和扔的距离*/
{
int x;
int y;
};
bool operator< (Stone a,Stone b)/*队列排序,如果坐标相同则按照扔的距离排序*/
{
if(a.x==b.x&&a.y>b.y)
return true;
else return a.x>b.x;
}
int main()
{
int t,n;
scanf("%d",&n);
while(n--)
{
scanf("%d",&t);
Stone temp;
int sum=1;/*用sum来表示第几个要扔的石头*/
priority_queue<Stone>q;/*定义一个队列*/
for(int i=0;i<t;i++)
{
scanf("%d%d",&temp.x,&temp.y);
q.push(temp);/*将每个数据存放到队列中去*/
}
while(!q.empty())/*队列不为空时就一直进行下去*/
{
temp=q.top();/*用temp来表示队顶元素,同时要出队*/
q.pop();
if(sum%2)/*第奇数个要扔的石头才能进入*/
{
temp.x+=temp.y;/*记录石头的位置*/
q.push(temp);
}
sum++;
}
printf("%d\n",temp.x);
}
return 0;
}
hdoj-1896 stones的更多相关文章
- hdoj 1896 Stones【优先队列】
Stones Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Subm ...
- hdu 1896.Stones 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1896 题目意思:给出 n 块石头的初始位置和能到达的距离.对于第奇数次遇到的石头才抛掷,偶数次的就忽略 ...
- HDU 1896 Stones (优先队列)
Problem Description Because of the wrong status of the bicycle, Sempr begin to walk east to west eve ...
- HDU 1896 Stones (优先队列)
Stones Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Subm ...
- HDU 1896 Stones --优先队列+搜索
一直向前搜..做法有点像模拟.但是要用到出队入队,有点像搜索. 代码: #include <iostream> #include <cstdio> #include <c ...
- HDU 1896 Stones(优先队列)
还是优先队列 #include<iostream> #include<cstdio> #include<cstring> #include<queue> ...
- 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 开始,遇到第奇 ...
- HDU-1896 Stones
http://acm.hdu.edu.cn/showproblem.php?pid=1896 题意:一个人从0开始走起,遇到偶数个石头就踢.要是同一位置有多个石头,则先扔最重的石头(也就是扔的最近的那 ...
- E - Stones 优先队列
来源1896 Because of the wrong status of the bicycle, Sempr begin to walk east to west every morning an ...
随机推荐
- js技巧(二)
1.封装获取id: function show(Id){ var aa=document.getElementById(Id); return aa; } 调用:console.log(show(&q ...
- csf 课件转化为wmv正常格式
1. 下载csf文件到本地:如下图 2.从下面百度网盘下载到本地: https://pan.baidu.com/s/1BBbgq n85a 3.安装并出现下面图标,点击打开 4. 运行如下图 5. ...
- Redis主从复制失败(master_link_status:down)
今天配置redis主从复制时出现master_link_status:down提示. 首先打开slave的redis.conf配置文件,确定slaveof 和masterauth 两个选项配置是否正确 ...
- 【技术累积】【点】【java】【28】Map遍历
Map遍历 map的遍历一般有几种吧 遍历entrySet for(Map.Entry<String,String> entry : map.entrySet()){ } Iterator ...
- 一文读懂架构师都不知道的isinstance检查机制
起步 通过内建方法 isinstance(object, classinfo) 可以判断一个对象是否是某个类的实例.但你是否想过关于鸭子协议的对象是如何进行判断的呢? 比如 list 类的父类是继 o ...
- WING IDE 快捷键
工欲善其事必先利其器,所以我们无论使用什么编译器,都要熟悉一些快捷键. Ctrl+N新建文件 Ctrl+O 打开文件夹 Ctrl+W 关闭当前文件 Ctrl+S 保存文件 Ctrl+shif+S 另存 ...
- c# 图片资料
- Optimizing web servers for high throughput and low latency
转自:https://blogs.dropbox.com/tech/2017/09/optimizing-web-servers-for-high-throughput-and-low-latency ...
- Coefficient Computation (大整数、Java解决)
Coefficient Computation UVALive8265 题意:计算组合数C(n,k)的值并将值按给定的进制输出. 思路:Java大整数类硬上. PS:刚刚学完Java的大整数类,结果却 ...
- bupt summer training for 16 #2 ——计算几何
https://vjudge.net/contest/171368#overview A.一个签到题,用叉积来判断一个点在一条线的哪个方向 可以二分,数据范围允许暴力 #include <cst ...