x] http://jsfiddle.net/9f64m2tu/ - nested loop approach, calculate maximum value of array segment
x] http://jsfiddle.net/a33goL3s/ - another approach - arrary slices, sum function,
*] inline loops execute
*]
] http://jsfiddle.net/a33goL3s/5/
] MISC / NOTE / LEARN
//FAIL - var Blocks = parseInt(data[0].split(" ")); // CANT do the parse on the same line
[notes]
] PROBLEM - Parade - place your security forces to minimize threat risks
] list of ints , rep threat of vandalism occuring on the city blocks along the parade route, 0=no vandalism, 1 = greater vandalism,
] parade moves in a straight line, passes by every block once
] given several security forces, each of which can control a number of adjacent blocks, nullifying the threats on the blocks they patrol
] forces come in different types(forceType), the types affect their patrolLength
] typeBike > patrolLengh then typeFoot
] forces repped by a list of pairs of integers, first int is # of adjacent blocks a type of force can control, 2nd int is how many forces of that type
] num forces is limited, place them strategically to minimize the sum of threat levels of all blocks that are not patrolled,
] because the minimum threat level may be achieved by multiple arrangements of security, output only the min total threat level that can be achieved and not the positions of the forces
] INPUTS -
] line 1 - 2 space sep integers, B (# of city blocks parade passes through, P # of different patrolLengths available among all avail forces
] line 2 - B space sep ints between 0 - 10 ^7, with the i-th int repping the threat level of vandalism occuring on the i-th block
] line 3 - 2P space seperated integers, meant to be read 2 at a time, total of P pairs, each pair first int reps # of adj blocks, that a specific type of force can patrol, 2nd int reps # of forces of that type, you have availabel
] F = total # of forces across all patrol types,
] TEST CASE SETS
] A - code correctness - 0<=B<=100; P = 1, F=1
] B - advanced cs - 0<=B<=10000; P=1; 0<=F<=100
] C - advanced cs - 0<= B <=1000; 0<=P<=3; 0<=F<=100 ;
*] score will increase in proportion to size of test cases
] PROCESS -
] get inputs
x] line1 = ] # blocks, ] patrol lengths
x] line 2 = threatLevels - array of int, for each block, ] threatLevel
x] line 3 = pairs of ints, ] adjBlocks ] #forces
] calculateSegmentRisk()
] calculateAllSegments()
] calcualteRiskBalance()
] OUTPUT -
] single int rep min possible threat level to achieve
[process]
x] VAR inputs
x] get input from stdin, set global variables, test input to see if its read,
] function readPairs()
] get # of pairs,
] get values of pairs
] load into pairs array
] function setthreatLevelOnBlock()
]
] function maxThreatLevel()
] using nested loop to read in values of threat levels from each segment
] function calculateSegmentRisk()
] take a slice of the array, slice size determined by ajdBlocks var
] sum elements to calculate risk
] function calculateAllSegments()
] loop thru, call callSegmentRisk for
] function getIndexRiskiestBlock()
]
] function calculateRiskBalance(arr)
] var maxRisk =
] var totalRisk =
*] use arr line2,
] function main()
]
status
[previously]
[2015-11-06] NEW task IN
] # # - ] start level2 after level1 locked out, ?? too many fails ??
[00:00] NEW task IN
x] # # - this page to document PRB, PROGRESS
[00:00] NEW task
] # # - trying to use nested loop to calculate the ,
x] SEE REF # 5 (fiddle)
] PRB - lenght/iterations on inner loop
[2015-11-07] NEW task CREATE functions - multiple(#)