hdu 1896.Stones 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1896
题目意思:给出 n 块石头的初始位置和能到达的距离。对于第奇数次遇到的石头才抛掷,偶数次的就忽略。问最多能扔到多远。如果有多颗石头在一个位置,距离小的那个标记为先遇到的。
所以先解说一下第二个测试案例:
2
1 5
6 6

在6这个位置的时候,由于5比6小,所以规定1(5)这个点是先遇上的,是偶数次遇到,所以忽略。
用优先队列做,位置近的优先级越高,如果位置相同,距离短的优先级越高。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std; const int maxn = + ;
struct node {
int P, D;
bool operator < (const node& a) const {
return P > a.P || (P == a.P && D > a.D);
}
}; int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE int T, N;
node stone;
priority_queue<node> pq;
while (scanf("%d", &T) != EOF) {
while (T--) {
scanf("%d", &N);
for (int i = ; i < N; i++) {
scanf("%d%d", &stone.P, &stone.D);
pq.push(stone);
}
int ans = ;
int judge = ;
while (!pq.empty()) {
stone = pq.top();
pq.pop();
if (judge) {
stone.P += stone.D;
ans = stone.P;
pq.push(stone);
}
judge = !judge;
}
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 (优先队列)
Stones Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Subm ...
- 【LeetCode】771. Jewels and Stones 解题报告
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述: 题目大意 解题方法 数组count 字典Counter 日期 题目地址 ...
- Bestcoder13 1003.Find Sequence(hdu 5064) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5064 题目意思:给出n个数:a1, a2, ..., an,然后需要从中找出一个最长的序列 b1, b ...
- Valentine's Day Round 1001.Ferries Wheel(hdu 5174)解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5174 题目意思:给出 n 个人坐的缆车值,假设有 k 个缆车,缆车值 A[i] 需要满足:A[i−1] ...
- BestCoder27 1001.Jump and Jump... (hdu 5162) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5162 题目意思:有 n 个 kid,每个 kid 有三个成绩 a, b, c.选最大的一个成绩作为这个 ...
- BestCoder27 1002.Taking Bus(hdu 5163) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5163 题目意思:有 n 个车站,给出相邻两个车站的距离,即车站 i 和车站 i+1 的距离为 di ( ...
- BestCoder25 1001.Harry and Magical Computer(hdu 5154) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5154 题目意思:有 n 门 processes(编号依次为1,2,...,n),然后给出 m 种关系: ...
- BestCoder14 1002.Harry And Dig Machine(hdu 5067) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5067 题目意思:给出一个 n * m 的方格,每一个小方格(大小为1*1)的值要么为 0 要么为一个正 ...
随机推荐
- CF451B Sort the Array 水题
Codeforces Round #258 (Div. 2) Sort the Array B. Sort the Array time limit per test 1 second memory ...
- CString
CString gray("Gray"); CString cat("Cat"); CString graycat = gray + cat; 与其用 sp ...
- 基于AngularJS的过滤与排序
前面了解了AngularJS的使用方法,这里就简单的写个小程序,实现查询过滤以及排序的功能. 本程序中可以了解到: 1 angularjs的过滤器 2 ng-repeat的使用方法 3 控制器的使用 ...
- OFFICE文档(DOC,XLS,PPT)打开报错的解决办法!
一般情况下,打开OFFICE文档报错都是因为模板文件出错!! 至于为什么会出错这个问题不好说,可能是不正确关闭文档等等,重装OFFICE也不一定能解决问题! 出现这种情况一般是所有的Word文档或者E ...
- 新手使用R的注意事项
1.最好先设置工作目录 如: setwd(“D:/DataDig”) 注意不是”\”,是”/” 再读取数据,如: datafile = read.csv("./test.csv") ...
- 关于hibernate链接数据源的配置参数详细解释(转)
具体使用方法还可以参考以下地址: http://blog.csdn.net/xb12369/article/details/41517409 以下信息转自: http://baike.baidu.co ...
- CSS DIV HOVER
<html> <head> <meta http-equiv="Content-Type" content="text/html; char ...
- ProgressDialog使用总结
以前对ProgressDialog不太熟练,特地看到的这个文章 ProgressDialog的使用 ProgressDialog 继承自AlertDialog,AlertDialog继承自Dialo ...
- 如何获取到Android控件的高度
问题 如何获取一个控件的长和高,相信很多朋友第一眼看见这个问题都会觉得很简单,直接在onCreate里面调用getWidth.getMeasuredWidth不就可以获得了吗,但是,事实上是并没有简单 ...
- 分享一个快速设置背景的js 自动获取背景图的长宽
我来分享一个快速设置背景的js (需要jq支持!) 快速切图铺页面用---就是不需要手动输入背景图的长宽 自动获取背景图的长宽 : <div class="wrap"> ...