HDU1896Stones(优先队列)
Stones
Time Limit : 5000/3000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 37 Accepted Submission(s) : 30
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
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
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
Sample Input
2
2
1 5
2 4
2
1 5
6 6
Sample Output
11
12
#include <iostream>
#include<queue>
#include<cstring>
#include<cstdio>
using namespace std; int i,t,n,k; struct node
{
int p,d;
};
struct cmp
{
bool operator()(node a,node b)
{
if (a.p==b.p) return a.d>b.d;
else return a.p>b.p;
}
}; int main()
{ scanf("%d",&t);
for(;t>;t--)
{
priority_queue<node,vector<node>,cmp> s;
scanf("%d",&n);
node w;
for(i=;i<=n;i++)
{
scanf("%d%d",&w.p,&w.d);
s.push(w);
}
k=;
while(!s.empty())
{
w=s.top();
s.pop();
k++;
if (k%!=)
{
w.p+=w.d;
s.push(w);
}
}
printf("%d\n",w.p);
}
return ;
}
HDU1896Stones(优先队列)的更多相关文章
- HDU1896Stones(优先队列)
地址http://acm.hdu.edu.cn/showproblem.php?pid=1896 题目大一比较简单,就是说在一条直线道路上有n个石头,往前走,遇到一个数一个,如果遇到的是第奇数个那就把 ...
- 堆排序与优先队列——算法导论(7)
1. 预备知识 (1) 基本概念 如图,(二叉)堆是一个数组,它可以被看成一个近似的完全二叉树.树中的每一个结点对应数组中的一个元素.除了最底层外,该树是完全充满的,而且从左向右填充.堆的数组 ...
- 数据结构:优先队列 基于list实现(python版)
#!/usr/bin/env python # -*- coding:utf-8 -*- #Author: Minion-Xu #list实现优先队列 class ListPriQueueValueE ...
- python优先队列,队列和栈
打印列表的疑问 class Node: def __str__(self): return "haha" print([Node(),Node()]) print(Node()) ...
- 数据结构作业——Sanji(优先队列)
山治的婚约 Description 我们知道,山治原来是地下有名的杀人家族文斯莫克家族的三子,目前山治的弟弟已经出现,叫做四治,大哥二哥就叫汪(One)治跟突(Two)治好了(跟本剧情无关) .山治知 ...
- Java优先队列
按照Java api的说法: java.util.PriorityQueue.PriorityQueue() Creates a PriorityQueue with the default init ...
- 优先队列实现Huffman编码
首先把所有的字符加入到优先队列,然后每次弹出两个结点,用这两个结点作为左右孩子,构造一个子树,子树的跟结点的权值为左右孩子的权值的和,然后将子树插入到优先队列,重复这个步骤,直到优先队列中只有一个结点 ...
- “玲珑杯”ACM比赛 Round #7 B -- Capture(并查集+优先队列)
题意:初始时有个首都1,有n个操作 +V表示有一个新的城市连接到了V号城市 -V表示V号城市断开了连接,同时V的子城市也会断开连接 每次输出在每次操作后到首都1距离最远的城市编号,多个距离相同输出编号 ...
- Dijkstra算法优先队列实现与Bellman_Ford队列实现的理解
/* Dijkstra算法用优先队列来实现,实现了每一条边最多遍历一次. 要知道,我们从队列头部找到的都是到 已经"建好树"的最短距离以及该节点编号, 并由该节点去更新 树根 到其 ...
随机推荐
- UNIX基础--权限
权限 Permissions FreeBSD使用传统的UNIX®系统的基本权限.在UNIX®系统中,基本权限分配了三种访问类型:读.写.执行.权限可以用字母r.w.x表示:也可以用二进制数表示,按rw ...
- Openjudge-计算概论(A)-比饭量
描述: 3个人比饭量,每人说了两句话: A说:B比我吃的多,C和我吃的一样多 B说:A比我吃的多,A也比C吃的多 C说:我比B吃得多,B比A吃的多. 事实上,饭量和正确断言的个数是反序的关系. 请编程 ...
- 关于erlang的binary
引自:http://cryolite.iteye.com/blog/1547252 1. binary数据是可以在不同进程间共享的 当然这些进程都在同一Erlang节点上. 这与普通term不同,后者 ...
- 6.编写一个Java应用程序,该应用程序包括2个类:Print类和主类E。Print 类里有一个方法output()功能是输出100 ~ 999之间的所有水仙花数(各位数字的 立方和等于这个三位数本身,如: 371 = 33 + 73 + 13。)在主类E的main方法中来 测试类Print。
Print类: package com.bao; public class Print { int g,s,b; void outPut() { for(int i=100;i<1000;i++ ...
- linux nfs开启
nfs设置: NFS的配置过程很简单.在服务器端中编辑/etc/exports文件,添加如下内容: /home/cotton/data/cotton/zghy 192.168.2.*(rw,s ...
- 执行 npm run update-webdriver 提示文件不能获取错误
按照angularjs官网的入门教程中输入 npm run update-webdriver 总是提示 https://chromedriver.storage.googleapis.com/2.1 ...
- Git Bash 简单操作
在Windows下使用Git Bash,用的是Linux命令,常用几个文件操作命令如下: Windows命令 Linux命令 意义 cd e:\xxx cd /e/xxx 切换到xxx目录 cd pw ...
- Oracle Day04 子查询
1.子查询解决什么问题: 当一个简单的查询查询不到结果的时候,可以使用子查询来丰富查询的条件以达到显示结果的目的. 子查询的格式: 用一个小括号包含,然后在里面写sql语句2.子查询的注意事项: 1) ...
- iOS 打包上传AppStore相关(1)-相关证书配置
最近一个老项目需要更新迭代,一个新的项目需要上线.有一些自己出现的BUG,也有一些没搞懂到处翻资料的问题.在此想做一个总结,写一下总体步骤,尽可能的详细一些,以及自己的一些理解.有很多步骤因为我们查阅 ...
- 文本注释系统 + MarkDown
标记系统: 笔记的要点 题材 缘起 目标 等级: 细节性 事实性 规律 法则 适用范围: 时间.地点.人物.起因.经过.结果,who what where when why how whom 6W1H ...