Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
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;

{
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 ()
{
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: