http://acm.hdu.edu.cn/showproblem.php?pid=1509

裸的优先队列的应用,输入PUT的时候输入名字,值和优先值进队列,输入GRT的时候输出优先值小的名字和对应的值

注意的是优先级一样的时候输出顺序在前的

 #include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
struct point {
int val,odr,num;
char na[];
bool operator <(const point & q)const
{
if (odr==q.odr) return num>q.num;
else return odr>q.odr;
}
};
int main()
{
char lsy[];
int k=;
point temp;
priority_queue<point>que;
while (~scanf("%s",lsy))
{
if (strcmp(lsy,"GET")==)
{
if (que.size()!=)
{
temp=que.top();
que.pop();
printf("%s %d\n",temp.na,temp.val);
}
else
printf("EMPTY QUEUE!\n");
}
else
{
scanf("%s %d %d",temp.na,&temp.val,&temp.odr);
temp.num=k++;
que.push(temp);
}
}
return ;
}

http://acm.hdu.edu.cn/showproblem.php?pid=1873

也很简单的优先队列,有三个医生的,每个医生又自己的顺序,所以可以建立三个队列

 #include<cstdio>
#include<queue>
#include<cstring>
using namespace std;
struct point {
int x,num;
bool operator <(const point & q)const
{
if (x==q.x) return num>q.num;
else return x<q.x;
}
};
int main()
{
int t,x,y;
char lsy[];
priority_queue<point> a,b,c;
point temp;
while (~scanf("%d",&t))
{
int k=;
while (a.size()!=)
a.pop();
while (b.size()!=)
b.pop();
while (c.size()!=)
c.pop();
while (t--)
{
scanf("%s",lsy);
if (strcmp(lsy,"IN")==)
{
scanf("%d %d",&x,&y);
temp.num=k++;
temp.x=y;
if (x==) a.push(temp);
else if (x==) b.push(temp);
else c.push(temp);
}
else
{
scanf("%d",&x);
if (x==)
{
if (a.size()==)
printf("EMPTY\n");
else
{
temp=a.top(),a.pop();
printf("%d\n",temp.num);
}
}
else if (x==)
{
if (b.size()==)
printf("EMPTY\n");
else
{
temp=b.top(),b.pop();
printf("%d\n",temp.num);
}
}
else
{
if (c.size()==)
printf("EMPTY\n");
else
{
temp=c.top(),c.pop();
printf("%d\n",temp.num);
}
}
}
}
}
return ;
}

http://acm.hdu.edu.cn/showproblem.php?pid=1896

题意 遇到第奇数个的石头就把它往前扔规定的距离,遇到第偶数个的石头就不动它 问最远的石头据出发点(起点)的距离

优先队列的应用,想到优先队列就很好解决了

 #include<cstdio>
#include<queue>
using namespace std;
struct point {
int x,y;
bool operator <(const point & q) const
{
if (x==q.x) return y>q.y;
else return x>q.x;
}
};
int main()
{
int t,n;
while (~scanf("%d",&t))
{
while (t--)
{
int k=;
priority_queue<point> que;
point temp;
scanf("%d",&n);
while (n--)
{
scanf("%d %d",&temp.x,&temp.y);
que.push(temp);
}
while (!que.empty())
{
temp=que.top(),que.pop();
if (k%==)
{
temp.x+=temp.y;
que.push(temp);
}
k++;
}
printf("%d\n",temp.x);
}
}
return ;
}

hdu 1509 & hdu 1873 & hdu 1896 (基础优先队列)的更多相关文章

  1. hdu 1509 Windows Message Queue (优先队列)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1509 题目大意:每一次输入都有序号和优先级,优先级小的先输出,优先级相同的话则序号小的先输出!第一次用 ...

  2. HDU 1896 Stones (优先队列)

    Problem Description Because of the wrong status of the bicycle, Sempr begin to walk east to west eve ...

  3. HDU 1873 看病要排队 优先队列

    Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s) ...

  4. HDU 1896 Stones --优先队列+搜索

    一直向前搜..做法有点像模拟.但是要用到出队入队,有点像搜索. 代码: #include <iostream> #include <cstdio> #include <c ...

  5. hdu 1509 Windows Message Queue (优先队列)

    Windows Message QueueTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  6. hdu 1509 Windows Message Queue

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1509 Windows Message Queue Description Message queue ...

  7. hdu 4784 Dinner Coming Soon(spfa + 优先队列)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4784 思路:建图,对于同一个universe来说,就按题目给的条件相连,对于相邻的universe,连 ...

  8. HDU 1535 Invitation Cards(逆向思维+邻接表+优先队列的Dijkstra算法)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1535 Problem Description In the age of television, n ...

  9. HDU 1254 推箱子(BFS加优先队列)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1254 推箱子 Time Limit: 2000/1000 MS (Java/Others)    Me ...

随机推荐

  1. oracle合并语句

    在sql server中的合并语句可以用xml path 详见http://www.cnblogs.com/codeyu/archive/2010/05/25/1743474.html 而oracle ...

  2. DOS批量拷贝本地目录到远程主机(定时执行)

     echo !USER!  net use \\!REMOTE_ADDR!\IPC$ /u:!USER!  copy D:\batch\ip.bat \\!REMOTE_ADDR!\Admin$\ / ...

  3. MD5加密和彩虹表

    首先叙述一下彩虹表的原理.本部分内容.图片和例子基本来自英文维基的Rainbow table词条(Rainbow table)——中文维基中目前(2013年10月9日)尚无对应的词条——因此对本答案中 ...

  4. Nginx入门安装升级

    1).Nginx ("engine x") 是一个高性能HTTP 和 反向代理 服务器.IMAP.POP3.SMTP 服务器. Nginx特点是占有内存少,并发能力强,事实上Ngi ...

  5. HTTPConnectionPool(host:XX)Max retries exceeded with url

    爬虫多次访问同一个网站一段时间后会出现错误 HTTPConnectionPool(host:XX)Max retries exceeded with url '<requests.package ...

  6. java fastJson

    // 大区的数据 String cityList = "[{'title':'华北','value':'1','children':[{'title':'山东','value':'1.1', ...

  7. enum-枚举当做key-value业务使用

    1.枚举当做key-value业务使用 package com.uwillbe.pad.enums; import java.util.ArrayList; import java.util.List ...

  8. Multiple APK Support

    [Multiple APK Support] Multiple APK support is a feature on Google Play that allows you to publish d ...

  9. CentOS 下搭建SVN

    CentOS 7下搭建配置SVN服务器 1. 安装 CentOS通过yum安装subversion. $ sudo yum install subversion subversion安装在/bin目录 ...

  10. c# 记录内容到txt文件

    string a= content;//采样结果 if (!File.Exists("e:\\newfile\\newtxt.txt")) { new FileStream(&qu ...