codechef December Challenge 2012 Book Exercises 模拟题

来源:互联网 发布:如何正确对待网络暴力 编辑:程序博客网 时间:2024/05/20 14:24

Book Exercises

Problem code: BEX

  • Submit
  • My Submissions
  • All Submissions

Harry is a bright student. To prepare thoroughly for exams, he completes all the exercises in his book! Now that the exams are approaching fast, he is doing book exercises day and night. He writes down and keeps updating the remaining number of exercises on the back cover of each book.

Harry has a lot of books messed on the floor. Therefore, he wants to pile up the booksthat still have some remaining exercises into a single pile. He will grab the books one-by-one and add the books that still have remaining exercises to the top of the pile.

Whenever he wants to do a book exercise, he will pick the book with the minimum number of remaining exercises from the pile. In order to pick the book, he has to remove all the books above it. Therefore, if there are more than one books with the minimum number of remaining exercises, he will take the one which requires the least number of books to remove. The removed books are returned to the messy floor. After he picks the book, he will do all the remaining exercises and trash the book.

Since number of books is rather large, he needs your help to tell him the number of books he must remove, for picking the book with the minimum number of exercises.

Note that more than one book can have the same name.

Input

The first line contains a single integer N denoting the number of actions. ThenN lines follow. Each line starts with an integer. If the integer is -1, that means Harry wants to do a book exercise. Otherwise, the integer is number of the remaining exercises in the book he grabs next. This is followed by a string denoting the name of the book.

Output

For each -1 in the input, output a single line containing the number of books Harry must remove, followed by the name of the book that Harry must pick.

Constraints

1 ≤ N ≤ 1,000,000
0 ≤ (the number of remaining exercises of each book) < 100,000
The name of each book consists of between 1 and 15 characters 'a' - 'z'.
Whenever he wants to do a book exercise, there is at least one book in the pile.

Example

Input:69 english6 mathematics8 geography-13 graphics-1Output:1 mathematics0 graphics


题意:

有一些书  书中有些题目没有做完   把这些书分为2堆 一堆用来存有题可做的数  一堆放全部做完的书(我们称这堆为乱堆,我随便取的)

输入 数字num和字符串s 表示   书名为s的数还剩下几道题没做   

由于那一堆有题目没做的书是一本一本的放好的 

每次输入-1 表示想要做题了 要拿出一本书来做题  但是要拿那本题目最少的   拿那本书的时候要把其上面的 放进乱堆 不再放回原堆  然后问

当拿那本书的时候要搬动其上面多少本书



我错了3变 第一遍是由于英语不好,题意没搞清 。第二遍 是由于英语不好 以为其上面的书还要放回原处  第三遍是由于英语不好 不知道要分为2堆  也就是把0的给清除来

哎 总结:英语说啥也要给它提上去


#include<stdio.h>#include<queue>#include<map>using namespace std;struct haha{int vis;char s[20];int num;}que[1000000+10];int cnt;map<int,int>mp;void find_ans(int min){int i,ans=0;for(i=cnt-1;i>=0;i--){//printf("i=%d s=%s\n",i,que[i].s);if(!que[i].vis){ans++;que[i].vis=1;if(que[i].num==min){ans--;cnt=i;printf("%d %s\n",ans,que[i].s);break;}else{    mp[que[i].num]--;if(mp[que[i].num]<=0) mp.erase(que[i].num);}}}return ;}int main(){int n,min,num;char s[20];while(scanf("%d",&n)!=EOF){cnt=0;    mp.clear();map<int,int>::iterator it;while(n--){              scanf("%d",&num);  if(num!=-1)  {  scanf("%s",s);  if(num==0) continue;                  que[cnt].num=num;  que[cnt].vis=0;  strcpy(que[cnt].s,s);  mp[num]++;  cnt++;  }  else  {  it=mp.begin();  min=it->first;  mp[min]--;  if(mp[min]==0)        mp.erase(it);   // printf("min=%d\n",min);  find_ans(min);  } }}return 0;}




原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 在本地怎么办外地车牌 二手车卖了车牌怎么办 科目四预约失败怎么办 车子过户了车牌怎么办 检车没有保险怎么办 异地超速12分怎么办 驾驶证考试过期了怎么办 买了库存车怎么办 车龄长了油耗高怎么办 新车发现补过漆怎么办 魅蓝note3内存不足怎么办 汽车安全检测证怎么办 a证被扣12分怎么办 突发事作后事故单位怎么办 如果遇到突发事故怎么办? 班级遇到突发事故怎么办 高速上出车祸怎么办? 安卓车载中控大屏卡怎么办 车辆交通信息卡怎么办 成都焊工压力容器证怎么办 天车钢丝绳绞住怎么办 受伤了怎么办安全教案 复读后学籍档案怎么办 开车就是开不好怎么办 货车提不了档案怎么办 二手车档案丢了怎么办 车辆档案丢了怎么办 手续跟车都丢了怎么办 二手车无法核档怎么办 高尔夫6天窗漏水怎么办 司机违章辞职了怎么办 年检可以推迟了怎么办? 汽车年审推迟了怎么办 机动车2年年检怎么办 教育局不给退学怎么办 没上火车票丢失怎么办 劳动局被收买了怎么办 醉驾单车事故怎么办 长沙市怎么办未孕证明 违章扣分不够扣怎么办 姓名改了驾驶证怎么办