Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

0ms STL 一次AC 爽!

Posted by zhu_yifan at 2010-06-06 01:20:55 on Problem 1338
#include<list>
#include<iostream>
using namespace std;

int count = 0;
list<long long> queue;
long long table[1500];

void pushback(long long val)
{
	for(list<long long>::iterator it = queue.begin(); it != queue.end(); ++it)
		if((*it) == val) return;
	queue.push_back(val);
}

int main()
{
	long long min;
	list<long long>::iterator index;
	queue.push_back(1);
	while(count != 1500)
	{
		min = (*queue.begin());
		index = queue.begin();
		for(list<long long>::iterator it = queue.begin(); it != queue.end(); ++it)
		{
			if((*it) < min)
			{
				min = (*it);
				index = it; 
			}
		}
		queue.erase(index);
		table[count] = min;
		++count;
		pushback(min * 2);
		pushback(min * 3);
		pushback(min * 5);
	}
	int num;
	while(cin>>num && num != 0) 
		cout<<table[num - 1]<<endl;
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator