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

暴力也WA,太汗了。路过的大牛救命!

Posted by yogafrank at 2008-08-23 13:59:50 on Problem 2051
#include <iostream>
#include <algorithm>
using namespace std;

class Request
{
public:
	int id;
	int interval;
};

Request reqs[1000];
int n, k;

void read ()
{
	n = 0;
	char seq[9];

    	while ( scanf ( "%s", seq) != -1 )
	{
		if ( strcmp ( seq, "#" ) == 0 )
			break;
		scanf ( "%d%d", &reqs[n].id, &reqs[n++].interval ); 
	}

	scanf ( "%d", &k );
}

bool cmp ( Request a, Request b )
{
	if ( a.interval == b.interval )
		return a.id < b.id;

	return a.interval < b.interval;
}

int main ()
{
	read ();
	sort ( reqs, reqs + n, cmp );

	int num = 0;

	while ( true )
	{
		for ( int i = 1; ; i++ )
		{
			for ( int j = 0; j < n; j++ )
			{	
				if ( i % reqs[j].interval == 0 )
				{
					num++;
					printf ( "%d\n", reqs[j].id );

					if ( num == k )
						goto leave;
				}
			}
		}
	}

leave:
	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