#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-EasyUI学习~

    为了回顾,简单记录下EasyUI如何使用: 先来张效果图: 这张图是从后台获取数据,然后进行展示的. 我这里利用的是EF-MVC. 先说下View视图里面的HTML代码是如何写的: @{ ViewBa ...

  2. 某表含有N个字段超精简模糊查询方法

    我们在做多个字段模糊查询时,是不是觉得非常麻烦?比如我要模糊查询某表多个字段存在某数据时,如下 select * from table where a like '%key%' or b  like ...

  3. JavaScript、CSS、JSP 实现用户注册页面与信息校验

    参考:http://blog.csdn.net/fightfaith/article/details/50277337 需求:实现用户注册页面并作出逻辑校验.要求: (1)完成注册页面样式如下: (2 ...

  4. (Struts)ActionForm类及表单数据验证

    LoginForm代码: /* * Generated by MyEclipse Struts * Template path: templates/java/JavaClass.vtl */ pac ...

  5. 快速安装 GitLab 并汉化

    转载:http://www.jianshu.com/p/7a0d6917e009

  6. MVC4学习笔记(一)

    1.查询 1)Controllers /// <summary> /// 数据上下文对象 /// </summary> OumindBlogEntities db = new ...

  7. xcode7 __weak 导致报错 is unavailable

    Build Settings Apple LLVM7.1 Laguage-Object-c Weak References in Manual Retain Release 选 Yes;

  8. HTML5的拖拽时间 ondragstart

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  9. 【CSU 1556】Pseudoprime numbers

    题 Description Jerry is caught by Tom. He was penned up in one room with a door, which only can be op ...

  10. 【BZOJ-3172】单词 AC自动机

    3172: [Tjoi2013]单词 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 2567  Solved: 1200[Submit][Status ...