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 ...
随机推荐
- unity 数学公式
Mathf.Abs绝对值 计算并返回指定参数 f 绝对值. Mathf.Acos反余弦 static function Acos (f : float) : float 以弧度为单位计算并返回参数 f ...
- python list 常用
l = [,,,] b = [,,] l.remove() #val del l[] #key new_list = l.extend(b) #[,,,,,,] new_list = l.append ...
- Ambient Light
[Ambient Light] Ambient light is light that is present all around the scene and doesn’t come from an ...
- 自定义sql server 聚合涵数
using System; using System.Data; using System.Data.SqlClient; using System.Data.SqlTypes; using Micr ...
- 581. Shortest Unsorted Continuous Subarray
Given an integer array, you need to find one continuous subarray that if you only sort this subarr ...
- 【Nodejs】Node.js(Express)の環境構築
[Express]の環境 参考URL:http://expressjs.com/en/starter/generator.html ①Node.jsの準備 (参考URL:https://www.cnb ...
- Error in building opencv with ffmpeg
I installed ffmpeg according to this article. ffmpeg installation was ok. Now I build opencv with ff ...
- anaconda的安装tensorflow
在anaconda prompt中我们输入 anaconda search -t conda tensorflow 查看能在哪里安装tensorflow anaconda show dhirschfe ...
- mute
mute - 必应词典 英[mjuːt] n.哑吧:沉默的人:[法律]拒绝答辩的被告人:鸟粪 adj.哑的:缄默无言的:(一时)说不出话的:(猎狗)不叫的 v.排泄:减弱…的声音:柔和…的色调 网络静 ...
- Java之成员访问控制
Java中数据成员.方法成员有四种访问控制.