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 要么为一个正 ...
随机推荐
- Linux下C语言高手成长路线(转载)
建议学习路径: 首先先学学编辑器,vim, emacs什么的都行. 然后学make file文件,只要知道一点就行,这样就可以准备编程序了. 然后看看<C程序设计语言>K&R,这样 ...
- PHP基础之 string 字符串函数
/*=================常用字符串处理函数================== ltrim(); //去掉字符串左边的空格 rtrim(); //去掉字符串 ...
- POJ 1947 Rebuilding Roads
树形DP..... Rebuilding Roads Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 8188 Accepted: ...
- HDOJ 4739 Zhuge Liang's Mines
Zhuge Liang's Mines Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- SpringMVC的Controller方法的参数不能直接绑定List、Set、Map
List需要绑定在对象上,而不能直接写在Controller方法的参数中. http://www.iteye.com/topic/973918
- 求方程式ax^2+bx+c=0的根。
#include <stdio.h>#include <stdlib.h>#include<math.h>int main(){ int a,b,c,d; doub ...
- eclipse工具背景色模板-程序员保护好自己的眼睛
做为coder,要保护好自己的眼睛,eclipse 强烈推荐 Eclipse Color Theme插件,该插件包含多种当前流行的主题选择. 安装方法: 安装方法:1.先安装一个Eclipse Col ...
- git之remote branch controller(远程分支控制)
1.创建本地分支 git branch //查看远程分支 git checkout -b branch_name //创建远程分支 在查看分支git branch 2.将分支提交到远程仓库 此时远程 ...
- oracle 行列转换的运用
问题: 员工表: A(E_ID,NAME,) 部门表: B(D_ID,D_NAME) 员工与部门关系:C(ID,E_ID,D_ID) SELECT A.E_ID,A.NAME ,B.D_NAME ...
- 【转】php 下载保存文件保存到本地的两种实现方法
来源:http://www.jb51.net/article/40485.htm 第一种: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 <?php function d ...