#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<string.h>
using namespace std; typedef struct minheap *Heap;
struct minheap
{
int last,max;
int data[];
char str[][];
int para[];
}Minheap; void HeapInset(int x,Heap H,char s[],int pa)
{
int i; i=++H->last;
while(i!=&&x<H->data[i/])
{
H->data[i]=H->data[i/];
strcpy(H->str[i],H->str[i/]);
H->para[i]=H->para[i/];
i/=;
}
H->data[i]=x;
strcpy(H->str[i],s);
H->para[i]=pa;
} int deleMin(Heap H)
{
int i,ci;
int x,y;
char str[];
int pa;
x=H->data[];//堆中最小元 strcpy(str,H->str[H->last]);
pa=H->para[H->last];
y=H->data[H->last]; H->last--; i=;
ci=;
//cout<<"last="<<H->last<<endl;
while(ci<=H->last)
{
//cout<<"ci="<<ci<<"y="<<y<<endl<<" "<<H->data[ci]<<endl;
if(ci<H->last&&H->data[ci+]<H->data[ci])ci++;
if(H->data[ci]>y)break; H->data[i]=H->data[ci];
strcpy(H->str[i],H->str[ci]);
H->para[i]=H->para[ci]; i=ci;
ci*=;
} H->data[i]=y;
strcpy(H->str[i],str);
H->para[i]=pa;
int tmp;
if(H->data[i]==H->data[i+])
{
tmp=H->data[i];H->data[i]=H->data[i+];H->data[i+]=tmp;
tmp=H->para[i];H->para[i]=H->para[i+];H->para[i+]=tmp;
strcpy(str,H->str[i]);strcpy(H->str[i],H->str[i+]);
strcpy(H->str[i+],str);
} return x;
}
int main()
{
char str[],s1[];
int para,data;
Heap H;
H=(Heap)malloc(sizeof(Minheap));
H->last=;
H->max=;
while(cin>>s1)
{ if(s1[]=='P')
{
cin>>str>>para>>data;
HeapInset(data,H,str,para); //cout<<"insert: "<<str<<" "<<para<<" "<<data<<endl; //cout<<"text:"<<H->str[1]<<" "<<H->data[1]<<endl;
}
else if(s1[]=='G')
{
if(H->last==)
printf("EMPTY QUEUE!\n");
else
{
cout<<H->str[]<<" "<<H->para[]<<endl; deleMin(H);
//cout<<"last:"<<H->str[H->last]<<" "<<H->data[H->last]<<endl;
//cout<<"last-1:"<<H->str[H->last-1]<<" "<<H->data[H->last-1]<<endl;
} }
//cout<<H->last<<endl;
}
return ;
}

一直WA~最小堆。应该是相同的优先级的时候,按照输入顺序输出

HDOJ 1590的更多相关文章

  1. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  2. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  3. HDOJ 1326. Box of Bricks 纯水题

    Box of Bricks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  4. HDOJ 1004 Let the Balloon Rise

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...

  5. hdoj 1385Minimum Transport Cost

    卧槽....最近刷的cf上有最短路,本来想拿这题复习一下.... 题意就是在输出最短路的情况下,经过每个节点会增加税收,另外要字典序输出,注意a到b和b到a的权值不同 然后就是处理字典序的问题,当松弛 ...

  6. HDOJ(2056)&HDOJ(1086)

    Rectangles    HDOJ(2056) http://acm.hdu.edu.cn/showproblem.php?pid=2056 题目描述:给2条线段,分别构成2个矩形,求2个矩形相交面 ...

  7. 继续node爬虫 — 百行代码自制自动AC机器人日解千题攻占HDOJ

    前言 不说话,先猛戳 Ranklist 看我排名. 这是用 node 自动刷题大概半天的 "战绩",本文就来为大家简单讲解下如何用 node 做一个 "自动AC机&quo ...

  8. 最近点对问题 POJ 3714 Raid && HDOJ 1007 Quoit Design

    题意:有n个点,问其中某一对点的距离最小是多少 分析:分治法解决问题:先按照x坐标排序,求解(left, mid)和(mid+1, right)范围的最小值,然后类似区间合并,分离mid左右的点也求最 ...

  9. BFS(八数码) POJ 1077 || HDOJ 1043 Eight

    题目传送门1 2 题意:从无序到有序移动的方案,即最后成1 2 3 4 5 6 7 8 0 分析:八数码经典问题.POJ是一次,HDOJ是多次.因为康托展开还不会,也写不了什么,HDOJ需要从最后的状 ...

随机推荐

  1. JQuery思维导图

  2. zabbix_监控_邮件预警

      一.解决的问题:当触发器满足条件被触发时,发邮件进行通知   二.软件及方案 使用外部邮箱发送邮件 使用mailx发送邮件,版本为12.4 zabbix版本为2.2.2 zabbix中使用执行脚本 ...

  3. codevs2495 水叮当的舞步 IDA*

    我打暴力不对,于是就看看题解,,,,,,IDA*就是限制搜索深度而已,这句话给那些会A*但不知道IDA*是什么玩意的小朋友 看题解请点击这里 上方题解没看懂的看看这:把左上角的一团相同颜色的范围,那个 ...

  4. LinkedHashMap实现LRU算法

    LinkedHashMap特别有意思,它不仅仅是在HashMap上增加Entry的双向链接,它更能借助此特性实现保证Iterator迭代按照插入顺序(以insert模式创建LinkedHashMap) ...

  5. 德州扑克AI WEB版

    继续之前的德州扑克话题,上次的DOS界面确实没法看,我女朋友说这是什么鬼.哈哈,估计只有自己能玩了 这两天重构了一下界面,基于web服务器和浏览器来交互. 服务器和客户端之间用websocket通信, ...

  6. Codeforces 295A Greg and Array

    传送门 A. Greg and Array time limit per test 1.5 seconds memory limit per test 256 megabytes input stan ...

  7. KindEditor提交用jquery获取不到数据的解决方法

    http://www.douban.com/note/257795704/ 如果说用php接收的话,在HTML中这样写就可以了var editor;KindEditor.ready(function( ...

  8. shell中的循环

    shell中的循环 for循环 类似于C语言的步长控制 例如: ;i<=;i++)); ); done 将1到10,依次乘以4,然后打印出来. 这里顺便提一下,shell里面表达式的计算,可以有 ...

  9. SQL存储过程概念剖析

    一.SQL存储过程的概念,优点及语法 定义:将常用的或很复杂的工作,预先用SQL语句写好并用一个指定的名称存储起来, 那么以后要叫数据库提供与已定义好的存储过程的功能相同的服务时,只需调用execut ...

  10. Dynamic Virtual Channels

    refer http://blogs.msdn.com/b/rds/archive/2007/09/20/dynamic-virtual-channels.aspx An important goal ...