codechef December Challenge 2012 Book Exercises 模拟题
来源:互联网 发布:如何正确对待网络暴力 编辑:程序博客网 时间:2024/05/20 14:24
Book Exercises
Problem code: BEX
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;}
- codechef December Challenge 2012 Book Exercises 模拟题
- codechef December Challenge 2012
- codechef December Challenge 2012
- codechef December Challenge 2012
- codechef December Challenge 2012 Granama Recipes 大水题
- codechef December Challenge 2014
- codechef December Challenge 2012 Pizza Delivery 完全背包求最小值 这道很重
- [线段树] Codechef December Challenge 2017. Red and blue points
- [点分树] Codechef December Challenge 2017. Chef, Leonardo And Queries
- 【codechef】Arush Challenge(灵活题)
- codechef May challenge A
- codechef May challenge B
- codechef May challenge C
- CodeChef May Challenge 2014
- codechef July Challenge 2014
- Codechef February Challenge坑
- CodeChef March Challenge 2015
- Codechef September Challenge 2015
- Ubuntu 12.04环境下iNodeClient设置
- ARCGIS viewer入门(8)flex viewer定制
- java日志组件介绍(common-logging,log4j,slf4j,logback )
- 文本文件与二进制文件区别
- 好的Java编码七条好习惯
- codechef December Challenge 2012 Book Exercises 模拟题
- SQLServer2008 安装过程中遇到“性能计数器注册表配置单元一致性”检查失败
- 高效代码审查的十个经验
- jQuery load()方法用法
- spring注入示例
- QBASIC+dosbox成功实现声卡输出
- Climbing Stairs
- 黑马程序员--Collection接口下各种子接口和类
- java中的 FileWriter类 和 FileReader类的一些基本用法