hdu 1509 & hdu 1873 & hdu 1896 (基础优先队列)
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 (基础优先队列)的更多相关文章
- hdu 1509 Windows Message Queue (优先队列)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1509 题目大意:每一次输入都有序号和优先级,优先级小的先输出,优先级相同的话则序号小的先输出!第一次用 ...
- HDU 1896 Stones (优先队列)
Problem Description Because of the wrong status of the bicycle, Sempr begin to walk east to west eve ...
- HDU 1873 看病要排队 优先队列
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s) ...
- HDU 1896 Stones --优先队列+搜索
一直向前搜..做法有点像模拟.但是要用到出队入队,有点像搜索. 代码: #include <iostream> #include <cstdio> #include <c ...
- hdu 1509 Windows Message Queue (优先队列)
Windows Message QueueTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- hdu 1509 Windows Message Queue
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1509 Windows Message Queue Description Message queue ...
- hdu 4784 Dinner Coming Soon(spfa + 优先队列)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4784 思路:建图,对于同一个universe来说,就按题目给的条件相连,对于相邻的universe,连 ...
- HDU 1535 Invitation Cards(逆向思维+邻接表+优先队列的Dijkstra算法)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1535 Problem Description In the age of television, n ...
- HDU 1254 推箱子(BFS加优先队列)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1254 推箱子 Time Limit: 2000/1000 MS (Java/Others) Me ...
随机推荐
- C#整数的三种强制类型转换int、Convert.ToInt32()、int.Parse()的区别
.int适合简单数据类型之间的转换,C#的默认整型是int32(不支持bool型): .int.Parse(string sParameter)是个构造函数,参数类型只支持string类型: .Con ...
- ASP.NET 简介
简介:ASP.NET - 制作网站应用程序的技术1. WebForm 2. MVC 什么东西? winform 界面 - 后台 - 数据库 共同组合出来的程序:ASP.NET 界面(HTML+CS ...
- vue样式绑定
vue 绑定class 和style 有相同的地方,可以是数组和对象,对于class class是真实的在css样式中添加的,只不过在元素中添加需要:class这样代表绑定,然后这个class作为对象 ...
- Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.0.2:resources 在我的myeclipse中新建maven工程总出现这个问题
只需在下图中更改代码 更改后是这样的: <plugin> <groupId>org.apache.maven.plugins</groupId> <artif ...
- hive 踩坑
1. create tabl metastore.MetaStoreDirectSql: Self-test query [select "DB_ID" from "DB ...
- linux中weblogic相关命令操作
在weblogic的目录下找到bin目录,其中有startWeblogic.sh.startManagerWeblogic.sh等 首先需要启动startWeblogic.sh,这个是管理服务,也就是 ...
- shell 通过shift获得某位后的入参
有时shell的入参个数不定,想要获得第2位后的参数,作为新的入参调用其他脚本 通常这时候想到的方法是用遍历,例如下面的方法: for (( i=2;i<=$#;i++)) do ...
- H5 边框:带border的百分比布局
响应式Web设计经常需要我们通过百分比设置组件宽度.如果我们不考虑边框,那么很容易就可以实现,但如果你给每一列以及总宽度都采用百分比设置,那这个时候固定的边框大小就会出来捣乱.下面我们将看到一组方法去 ...
- django的优缺点(非原创)
Django 大包大揽,用它来快速开发一些 Web 应用是不错的.如果你顺着 Django 的设计哲学来,你会觉得 Django 很好用,越用越顺手:相反,你如果不能融入或接受 Django 的设计哲 ...
- 这篇说的是Unity Input 输入控制器
关于Unity3D是什么.我就不多做解释了.由于工作原因,该系列原创教程不定期更新.每月必然有更新.谢谢各位 Unity Input---输入控制管理器: Edit->Project Setti ...