Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
暴力也WA,太汗了。路过的大牛救命!#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator