Click here to Skip to main content
16,009,057 members
Home / Discussions / Algorithms
   

Algorithms

 
GeneralRe: Calculating a width and height, not square root. Pin
Cloughy7-Mar-09 6:04
Cloughy7-Mar-09 6:04 
GeneralRe: Calculating a width and height, not square root. [modified] Pin
0x3c07-Mar-09 7:05
0x3c07-Mar-09 7:05 
GeneralRe: Calculating a width and height, not square root. Pin
Cloughy7-Mar-09 13:07
Cloughy7-Mar-09 13:07 
GeneralRe: Calculating a width and height, not square root. Pin
Yusuf7-Mar-09 13:39
Yusuf7-Mar-09 13:39 
GeneralRe: Calculating a width and height, not square root. Pin
Luc Pattyn7-Mar-09 14:46
sitebuilderLuc Pattyn7-Mar-09 14:46 
GeneralRe: Calculating a width and height, not square root. Pin
Yusuf7-Mar-09 15:50
Yusuf7-Mar-09 15:50 
GeneralRe: Calculating a width and height, not square root. Pin
CPallini10-Mar-09 4:29
mveCPallini10-Mar-09 4:29 
GeneralRe: Calculating a width and height, not square root. Pin
Pete O'Hanlon10-Mar-09 4:34
mvePete O'Hanlon10-Mar-09 4:34 
GeneralRe: Calculating a width and height, not square root. Pin
Luc Pattyn10-Mar-09 8:19
sitebuilderLuc Pattyn10-Mar-09 8:19 
GeneralRe: Calculating a width and height, not square root. Pin
PIEBALDconsult22-Mar-09 17:52
mvePIEBALDconsult22-Mar-09 17:52 
GeneralRe: Calculating a width and height, not square root. [modified] Pin
Yusuf7-Mar-09 13:37
Yusuf7-Mar-09 13:37 
GeneralRe: Calculating a width and height, not square root. Pin
0x3c08-Mar-09 1:40
0x3c08-Mar-09 1:40 
GeneralRe: Calculating a width and height, not square root. Pin
Yusuf8-Mar-09 1:50
Yusuf8-Mar-09 1:50 
GeneralHow to calculate width and height under constraints Pin
73Zeppelin7-Mar-09 19:53
73Zeppelin7-Mar-09 19:53 
GeneralRe: Calculating a width and height, not square root. Pin
Cloughy8-Mar-09 4:37
Cloughy8-Mar-09 4:37 
GeneralRe: Calculating a width and height, not square root. Pin
73Zeppelin9-Mar-09 0:12
73Zeppelin9-Mar-09 0:12 
QuestionVery advanced Computer Graphics library Pin
markweber5-Mar-09 5:08
markweber5-Mar-09 5:08 
AnswerRe: Very advanced Computer Graphics library Pin
Mark Churchill9-Mar-09 13:57
Mark Churchill9-Mar-09 13:57 
GeneralRe: Very advanced Computer Graphics library Pin
markweber10-Mar-09 3:26
markweber10-Mar-09 3:26 
Questiona parellel program problem Pin
JackPuppy2-Mar-09 1:49
JackPuppy2-Mar-09 1:49 
AnswerRe: a parellel program problem Pin
JackPuppy2-Mar-09 2:43
JackPuppy2-Mar-09 2:43 
AnswerRe: a parellel program problem Pin
JackPuppy2-Mar-09 2:44
JackPuppy2-Mar-09 2:44 
QuestionGreedy problem with filling sequence Pin
proggged26-Feb-09 4:23
proggged26-Feb-09 4:23 
Problem:
------------------------------------------------------------------------------------------------------
Let have a sequence of K positive finite integers, starting with 1 and ending with K (each element of this sequence represents a free slot) and an arbitrary multiset of L integers of size 1..K.

Using a greedy algorithm, try to fill slots of this sequence with multiset elements, so that the sequence will be the most similar to entered multiset. Similarity is defined as a minimal sum of
absolute values of subtraction of filled sequence slots and elements, which were put in sequence slots.

Examples:

K=3
Multiset = {1,1,1}
Filled_sequence= 1[1] 2[1] 3[1]
Minimal sum = abs(1-1) + abs(2-1) + abs(3-1)= 3

K=5
Multiset = {1,2,3,4,5}
Filled_sequence= 1[1] 2[2] 3[3] 4[4] 5[5]
Minimal sum = abs(1-1) + abs(2-2) + abs(3-3) + abs(4-4) + abs(5-5) = 0

K=7
Multiset = {2,2,4,4,6,6,6}
Filled_sequence= 1[2] 2[2] 3[4] 4[4] 5[6] 6[6] 7[6]
Minimal sum = abs(1-2) + abs(2-2) + abs(3-4) + abs(4-4) + abs(5-6) + abs(6-6) + abs(7-6) = 4

K=7
Multiset = {1,1,7,7}
Filled_sequence= 1[1] 2[1] 3[-] 4[-] 5[-] 6[7] 7[7]
Minimal sum = abs(1-1) + abs(2-1) + abs(6-7) + abs(7-7) = 2
------------------------------------------------------------------------------------------------------

I could think of some greedy approaches, but cannot really determine if they really work, or even if they really are greedy. Could you write me a way, or at least idea how to implement this?
AnswerRe: Greedy problem with filling sequence Pin
Perisic, Aleksandar28-Feb-09 5:38
Perisic, Aleksandar28-Feb-09 5:38 
GeneralRe: Greedy problem with filling sequence Pin
Perisic, Aleksandar1-Mar-09 3:45
Perisic, Aleksandar1-Mar-09 3:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.