codechef December Challenge 2012 Book Exercises 模拟题

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 books that 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. Then N 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:
6
9 english
6 mathematics
8 geography
-1
3 graphics
-1

Output:
1 mathematics
0 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;
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值