Está en la página 1de 9

Handle:

Algorithm Tutorials http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=g...


1 of 9 9/8/2014 12:15 AM
Algorithm Tutorials http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=g...
2 of 9 9/8/2014 12:15 AM
Let N denot e t he number of act i vi t i es and
{I } t he act i vi t y I ( 1 <= I <= N )
For each {I }, consi der S[ I ] and F[ I ] i t s st ar t i ng and f i ni shi ng t i me
Sor t t he act i vi t i es i n t he i ncr easi ng or der of t hei r f i ni shi ng t i me
- t hat i s, f or ever y I < J we must have F [ I ] <= F [ J ]
/ / A denot es t he set of t he act i vi t i es t hat wi l l be sel ect ed
A = {1}
/ / J denot es t he l ast act i vi t y sel ect ed
J = 1
For I = 2 t o N
/ / we can sel ect act i vi t y ' I ' onl y i f t he l ast act i vi t y
/ / sel ect ed has al r eady been f i ni shed
I f S [ I ] >= F [ J ]
/ / sel ect act i vi t y ' I '
A = A + {I }
/ / Act i vi t y ' I ' now becomes t he l ast act i vi t y sel ect ed
J = I
Endi f
Endf or
Ret ur n A
Algorithm Tutorials http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=g...
3 of 9 9/8/2014 12:15 AM
Algorithm Tutorials http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=g...
4 of 9 9/8/2014 12:15 AM
Best = - I nf i ni t y
For S [ 1] = 1 t o 10
For S [ 2] = 1 t o 10
For S [ 3] = 1 t o 10
For S [ 4] = 1 t o 10
I f ( S [ 1] + S [ 2] + S [ 3] + S [ 4] ) mod 2 = 0
S [ 5] = S[ 6] = 10
S [ 7] = 10 - ( S [ 1] + S [ 2] + S [ 3] + S[ 4] ) / 2
S [ 8] = S [ 9] = S [ 10] = - 10
/ / i n Best we save t he gr eat est aver age homol ogy scor e
Best = max ( Best , scor e ( F, S) )
/ / obt ai ned so f ar .
Endi f
Endf or
Endf or
Endf or
Endf or
Ret ur n Best
Algorithm Tutorials http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=g...
5 of 9 9/8/2014 12:15 AM
Algorithm Tutorials http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=g...
6 of 9 9/8/2014 12:15 AM
Gr oups = 0
Repeat
/ / sor t s t he ar r ay i n decr easi ng or der
Sor t ( A)
Mi n= A[ K]
I f Mi n > 0 Gr oups = Gr oups + 1
For I = 1 t o K
A[ I ] = A[ I ] - 1
Endf or
Unt i l Mi n = 0
Ret ur n Gr oups
Gr oups = 0
Repeat
/ / sor t s t he ar r ay i n decr easi ng or der
Sor t ( A)
Mi n= A[ K]
Gr oups = Gr oups + Mi n
For I = 1 t o K
A[ I ] = A[ I ] - Mi n
Endf or
Unt i l Mi n = 0
Ret ur n Gr oups
Gr oups = 0
Repeat
/ / sor t s t he ar r ay i n decr easi ng or der
Sor t ( A)
Mi n= A[ K]
Al l owance = ( Mi n+999) / 1000
Gr oups = Gr oups + Al l owance
For I = 1 t o K
A[ I ] = A[ I ] - Al l owance
Endf or
Unt i l Mi n = 0
Ret ur n Gr oups
Algorithm Tutorials http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=g...
7 of 9 9/8/2014 12:15 AM
Algorithm Tutorials http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=g...
8 of 9 9/8/2014 12:15 AM
Get Connected
Your email address Submit
Algorithm Tutorials http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=g...
9 of 9 9/8/2014 12:15 AM

También podría gustarte