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. C++学习一Virtual

    没有系统性学习C++,所以工作中使用特别别扭,也不是不会,也不是不懂,但读代码和写代码时总有点生疏感.所以该补还是补起来,现在想想还是学生时代学习的知识更加扎实,那是融入骨子里的. virtual函数 ...

  2. poj1061-青蛙的约会-(贝祖定理+扩展欧几里得定理+同余定理)

    青蛙的约会 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions:132162   Accepted: 29199 Descripti ...

  3. SPSS-因子分析

    因子分析 有可能用较少的综合指标分析存在于各变量中的各类信息,而各综合指标之间彼此是不相关的,代表各类信息的综合指标称为因子.定义:因子分析就是用少数几个因子来描述许多指标或因素之间的联系,以较少几个 ...

  4. beebase

    1.简单介绍 BeeBase是一个在线生物信息学数据库,显示与Apis mellifera.欧洲蜜蜂以及一些病原体和其他物种有关的数据.它是与蜜蜂基因组测序联盟合作开发的.BeeBase是蜜蜂研究社区 ...

  5. destructuring assignment

    [destructuring assignment] The destructuring assignment syntax is a JavaScript expression that makes ...

  6. Dubbo启动过程(Spring方式)详解

    一.使用Spring xml配置方式的启动过程 1. 解析XML,注册Bean 2. 监听Spring事件 3. 启动或关闭dubbo 二.详细过程 1. 解析XML,注册Bean 利用Spring提 ...

  7. eclipse jvm配置

    Eclipse设置JVM参数:->Run Configurations ->VM arguments,如下:

  8. BGRA与BGR的相互转换

    BGRA转BGR void BgraToBgr(BYTE *bgraData,int *bgraSize) { ,j=; j<*bgraSize; i+=,j+=) { *(bgraData+i ...

  9. Nginx的配置文件nginx.conf配置详解

    user nginx nginx; #Nginx用户及组:用户 组.window下不指定 worker_processes 8; #工作进程:数目.根据硬件调整,通常等于CPU数量或者2倍于CPU. ...

  10. f5源站获取http/https访问的真实源IP解决方案

    1.背景 F5负载均衡设备,很多场景下需要采用旁挂的方式部署.为了保证访问到源站的数据流的request和response的TCP路径一致,f5采用了snat机制.但是这样导致源站上看到的来源IP都是 ...