HDU 1896:Stones(优先队列)
Stones
Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 4165    Accepted Submission(s): 2699
Problem Description
Because of the wrong status of the bicycle, Sempr begin to walk east to west every morning and walk back every evening. Walking may cause a little tired, so Sempr always play some games this time. 
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
In the first line, there is an Integer T(1<=T<=10), which means the test cases in the input file. Then followed by T test cases. 
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
Just output one line for one test case, as described in the Description.
Sample Input
2
2
1 5
2 4
2
1 5
6 6
Sample Output
11
12
题意
有n个石子,每个石子的位置和能丢出去的距离已经给了出来。如果石子是在第奇数个,将该位置的最重的石子扔出去(如果只有一个石子,不需要选;如果有多个石子,将丢出去距离最近的那个扔出去)。问最后距离起点最远的石子距离起点有多远。
思路
定义一个结构体的优先队列,按照题目要求设置优先级,将题目中已知的石子的位置和丢出去的距离放入优先队列中。
然后拿出来优先队列中的最上面的石子,如果该石子在奇数位置,进行移动后重新加入到队列中;如果是偶数,不用管他。用一个数maxx记录石子到达的最远距离,当队列为空的时候,停止操作,输出maxx
AC代码
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <limits.h>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <string>
#define ll long long
#define ms(a) memset(a,0,sizeof(a))
#define pi acos(-1.0)
#define INF 0x3f3f3f3f
const double E=exp(1);
const int maxn=1e6+10;
using namespace std;
struct wzy
{
    int place,dis;
}s;
bool operator < (const wzy &a,const wzy &b)
{
    if(a.place==b.place)
        return a.dis>b.dis;
    else
        return a.place>b.place;
}
int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	int t;
	int n;
	int p,d;
	cin>>t;
	while(t--)
    {
        priority_queue<wzy>que;
        cin>>n;
        for(int i=1;i<=n;i++)
        {
            cin>>p>>d;
            s.place=p;
            s.dis=d;
            que.push(s);
        }
        int maxx=0;
        for(int i=1;;i++)
        {
            if(que.empty())
                break;
            s=que.top();
            que.pop();
            if(i%2)
            {
                s.place+=s.dis;
                maxx=max(s.place,maxx);
                que.push(s);
            }
        }
        cout<<maxx<<endl;
    }
	return 0;
}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 (优先队列)
		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<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的时候输出优先值小的名字和对应的 ... 
- 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 ... 
随机推荐
- 20170724wdVBA正则表达式提取答案到Excel
			Public Sub RegExtractData() Dim StartTime, UsedTime StartTime = VBA.Timer Dim FilePath$ Dim FileName ... 
- 20170517xlVBA添加数据透视表
			Sub AddPovitTable() 'Constance Const DATA_SHEET As String = "Advanced Filter" Const DATA_A ... 
- The Monster CodeForces - 917A (括号匹配)
			链接 大意:给定字符串, 只含'(',')','?', 其中'?'可以替换为'('或')', 求有多少个子串可以的括号可以匹配 (不同子串之间独立) 记$s_($为'('个数, $s_)$为')'个数 ... 
- 『PyTorch』第五弹_深入理解Tensor对象_中上:索引
			一.普通索引 示例 a = t.Tensor(4,5) print(a) print(a[0:1,:2]) print(a[0,:2]) # 注意和前一种索引出来的值相同,shape不同 print( ... 
- bzoj2286: [Sdoi2011]消耗战  虚树
			在一场战争中,战场由n个岛屿和n-1个桥梁组成,保证每两个岛屿间有且仅有一条路径可达.现在,我军已经侦查到敌军的总部在编号为1的岛屿,而且他们已经没有足够多的能源维系战斗,我军胜利在望.已知在其他k个 ... 
- ccf消除类游戏
			问题描述 消除类游戏是深受大众欢迎的一种游戏,游戏在一个包含有n行m列的游戏棋盘上进行,棋盘的每一行每一列的方格上放着一个有颜色的棋子,当一行或一列上有连续三个或更多的相同颜色的棋子时,这些棋子都被消 ... 
- POJ 1442 treap
			裸treap. 只需增加一个size记录其儿子个数便可找到第k大数. #include <cstdio> #include <cstring> #include <cti ... 
- IE6中CSS常见BUG全集及解决方案——摘自网友
			IE6中CSS常见BUG全集及解决方案 IE6双倍边距bug 当页面内有多个连续浮动时,如本页的图标列表是采用左浮动,此时设置li的左侧margin值时,在最左侧呈现双倍情况.如外边距设置为10px, ... 
- xmind visio mindmanager edraw比较
			xmind visio mindmanager edraw比较 xmind visio mindmanager Edraw 中心主题 有 无 有 泳道图 无 有 有 结构上讲 [思维导图] ... 
- photoshop cc 智能切图
			这节分享一个photoshop cc 开始有的自动生成图标的方法 psd练习文件 http://pan.baidu.com/s/1pL2dwL1 1 工具:我这里用的是photoshop cc 201 ... 
