Friday, April 5, 2019

ACM ICPC Regional Problem

ACM ICPC Regional lineSiti Nazihah Binti Sarpin (L)Nurul Aini Binti Mohd Hisan confuse of Contents (Jump to)Introduction hassle commentary trouble StatisticsProblem DetailsACM ICPC Regional Problem rationalness to Choose This Problem previous depth psychologyMathematical manikin political campaign Case 1 ( judge stimulus and fruit from the conundrum)Test Case 2 (New input and output)potential Algorithm Design Technique living creature ForceDynamic Programming0-1 packsacksReferencesIntroductionProblem DescriptionBessie has gone on a trip, and shes ride a roll coaster Bessie really likes riding the cast coaster, but unfortunately she often gets dizzy.The roller coaster has a number of distinct sections that Bessie rides in order. At the tooth root of the ride, Bessies vertigo and play aims argon both at 0. For each section of the roller coaster, Bessie understructure all keep her eyeball dedicate or keep them closed (and must(prenominal) keep them that way for the full section). If she keeps her look open for a section, her sum of money fun increases by a sportsman factor for that section, and her vertigo increases by a vertigo factor for that section. Howalways, if she keeps her eyeball closed for the section, her impart fun entrust non change, but her silliness go out decrease by a value thats constant for the full(a) roller coaster. (Note that her vertigo can never go below 0.)If, at either point, Bessies silliness is higher up a certain fixate, Bessie ordain get sick. Write a program to find the supreme substance of fun Bessie can build without getting sick.InputThere will be several scrutiny cuticles in the input. Each test case will begin with a line with three integersN K LWhere N (1 N 1,000) is the number of sections in this point roller coaster, K (1 K 500) is the centre that Bessies dizziness take aim will go down if she keeps her eyes closed on any section of the ride, and L (1 L 300,000) is the li mit of dizziness that Bessie can tolerate if her dizziness ever becomes larger than L, Bessie will get sick, and thats not funEach of the next N lines will describe a section of the roller coaster, and will gull two integersF DWhere F (1 F 20) is the increase to Bessies get along fun that shell get if she keeps her eyes open on that section, and D (1 D 500) is the increase to her dizziness take if she keeps her eyes open on that section. The sections will be listed in order. The input will end with a line with three 0s.OutputFor each test case, output a single integer, representing the maximal amount of fun Bessie can have on that roller coaster without particular(a) her dizziness limit. Print each integer on its own line with no spaces. Do not print any blank lines between answers.Sample Input3 1 22 13 15 210 5 120 212 43 310 620 319 919 71 50015 54 20 0 0Sample Output70Problem StatisticsAccording to ACM-ICPC archive website, the impart deference of this problem is 2226 . There are 183 users have lapd this problem while 246 users that tried this problem (last modify on 10 Dec 2014).This problem can be found at https//icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudgeItemid=8category=410page=show_problemproblem=2871.Problem DetailsACM ICPC Regional ProblemRegion ACM ICPC Regionals 2010 North America sou-east USAYear 2010Problem H, 4870 Roller Coaster 4.500 secondsLinkhttps//icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudgeItemid=8category=410page=show_problemproblem=2871Source Code https//github.com/depstein/programming-competitions/blob/master/problems/04-10-14%20intro/4870%20(Roller%20Coaster)/rollercoaster.javaProgrammer N/A.Reason to Choose This ProblemThis problem is chosen to fulfill a requirement of CSC750, Advance Algorithm and Analysis that needed the problem that can be solved using Dynamic Programming. This problem belongs to 0-1 Knapsack problem which require us to find the maximum amount of fun can Bessie have wit hout making her sick.Preliminary AnalysisThis problem is to persist the maximum amount of fun Bessie can have when riding a roller coaster without getting sick, in which case without particular(a) her dizziness limit.The constraints of the problem includeThe roller coaster has a distinct number of sections that Bessie rides in order.Bessies fun and dizziness levels are both at 0 at the beginning of the ride.For each section, Bessie has two options either to keeps her eyes open or close and she must keep them that way for the whole section.At any section, when Bessie keeps her eyes open, her total dizziness increases by a dizziness factor and her total fun too increases by a fun factor. *At any section, when Bessie keeps her eyes closed, her total dizziness will be subtracted by a value that is constant for the undefiled roller coaster, but her total fun is maintain. *Bessies dizziness can never go below 0.Bessie will get sick if her dizziness is above a given limit. ** Tricky c onstraint.The parameters for this problem are listed as belowN (1 N 1000), the number of sections in a particular roller coaster.K (1 K 500), the amount that Bessies dizziness level will be subtracted if she keeps her eyes closed on any section of the ride.L (1 L 300,000), limit of dizziness that Bessie can stand.F (1 F 20), the increases to Bessies total fun if she keeps her eyes open on that section.D (1 D 500), the increases to her dizziness level if she keeps her eyes open on that section.000, the c fixed command line for tenia the test cases.This problem belongs to 0-1 Knapsack problem. This is due to the same properties this problem had as with a Knapsack problem in which it contains a great deal of full stops where each item consists of weight and value, the total weight must be less than or decent to the given limit, and a maximum total value (in which case it must consider the given limit of the sack can carry) 1. Thus, for this Roller Coaster problem, the pro perties listed below have adapted the knapsack firmnessThe item in this problem consists of Bessies dizziness level (weight) and fun level (value).Her dizziness is how much she can carries in her sack (total weight of the items she carries in the sack).Her fun is what she would like to maximize (total value of the items she carries).Now, we want to get the maximum total fun she could have without making her too dizzy (maximum total fun = maximum total value in her sack) (limit of dizziness = weight limit for the sack).Furthermore, this problem is tied with another tricky constraints in which it affected the dizziness level and fun level at each distinct section, in which case Bessie has two options either to open or close her eyes during riding that roller coaster (in Knapsack problem, whether an item is in the sack or not). If she keeps her eyes open, both dizziness and fun level will increase. Meanwhile, if she keeps her eyes close, her fun level will remain the same as with the previous section, but her dizziness level will increase.In conjunction with these tricky constraints, it can be broken down into many sub-problems 2, and then the Knapsack solution to this problem does not have to perform back course of actioning or recursion. This is because the previously solved sub-problems are stored in tables and can be used again instead of re-computing the solution each time 2. In summary, this Knapsack problem is more suitable if it is solve by using Dynamic Programming proficiency compare with brute force algorithm.Mathematical ModelingInputThe number of sections in a particular roller coaster.The amount that Bessies dizziness level will be subtracted if she keeps her eyes closed on any section of the ride.The limit of dizziness that Bessie can stand.The increases to Bessies total fun if she keeps her eyes open on that section.The increases to her dizziness level if she keeps her eyes open on that section.The fixed command line for stopping the test cases. Output The maximum amount of fun Bessie can have on that roller coaster without runing her dizziness limit.Let,the number of sections in a particular roller coaster = N, where N 1 and N 1000,the amount that Bessies dizziness level will be subtracted if she keeps her eyes closed on any section of the ride = K, where K 1 and K 500,the limit of dizziness that Bessie can stand = L, where L 1 and L 300000,the increases to Bessies total fun if she keeps her eyes open on that section = F, where F 1 and F 20,the increases to her dizziness level if she keeps her eyes open on that section = D, where D 1 and D 500, andthe fixed command line for stopping the test cases = 000.To mathematically model this problem, it uses array tables to maintain the maximum total fun Bessie could have without getting sick 4.It is important to make sure total dizziness (DTotal) can never go below zero and must not exceed the given limit. Hence, DTotal 0 and DTotal L.Moreover, depending on Bessies ey es stipulate (either open or close), it will affect each of the total fun and total dizziness. Hence,F unresolved = F + Ffun at ordinal section,D control surface = D + Ddizzy at nth section,F close-fitting = Ffun at nth section,DClose = Ddizzy at nth section K,where F inconsiderate, D unfastened, FClose, DClose N.Thus a solution for the problem is to find the minimum dizziness Bessie could have with the maximum fun 4.DPNF is the minimum dizziness Bessie can have, with fun = F.DPNF = max(DPN 1F (fun at the nth section) + (dizziness at the nth section), DPN 1F K).First table is to store the sections number N and the other one is to store the total fun F. Note that both initial arrays of fun and dizziness level are set to 0.The track of the roller coaster must pass all section meaning to move to the next section both table will become N-1 F gaietyN. By using those tables, for each section, we can obtain the maximum fun Bessie can have. When move to the next section, it just re trieves the previously stored result in order to get the sunrise(prenominal) result for the new section.Test Case 1 (Sample input and output from the problem)Sample inputSample output3 1 22 13 15 27 gameboard 1 Sample input and output of test case 1Table 2 illustrates the best solution for test case 1 from the sample input given by the Roller Coaster problem. This roller coaster track has a total of 3 sections, the amount that Bessies dizziness level will be subtracted if she keeps her eyes closed on any section of the ride is 1, and the limit of dizziness that Bessie can stand is 2. The maximum total fun Bessie could have without getting sick is 7 and her dizziness is 2. During riding that roller coaster, Bessie had her eyes open in section 1 and 3, and close her eyes in section 2.Eyes powerLevel of entertainmentDizziness sign00Open segment 12 10 + 2 = 20 + 1 = 1CloseSection 23 121 1 = 0OpenSection 35 25 + 2 = 70 + 2 = 2Table 2Optimal solution for test case 1 from sample input Roller Coaster problemTest Case 2 (New input and output)InputOutput12 3 85 43 28 26 112 518 212 310 415 216 510 36 180Table 3 input and output from test case 2This roller coaster track has a total of 12 sections, the amount that Bessies dizziness level will be subtracted if she keeps her eyes closed on any section of the ride is 3, and the limit of dizziness that Bessie can stand is 8. The maximum total fun Bessie could have without getting sick is 80 and her dizziness is 6. During riding that roller coaster, Bessie had her eyes close in section 2 5, 8 and 10, and open her eyes in other sections. Meanwhile, Table 4 shows how the solution is achieved.Eyes ConditionLevel ofFunDizzinessInitial00OpenSection 15 40 + 5 = 50 + 4 = 4CloseSection 23 254 3 = 1OpenSection 38 25 + 8 = 131 + 2 = 3OpenSection 46 113 + 6 = 193 + 1 = 4CloseSection 512 5194 3 = 1OpenSection 618 219 + 18 = 371 + 2 = 3OpenSection 712 337 + 12 = 493 + 3 = 6CloseSection 810 4496 3 = 3OpenSection 915 249 + 15 = 643 + 2 = 5CloseSection 1016 5645 3 = 2OpenSection 1110 364 + 10 = 742 + 3 = 5OpenSection 126 174 + 6 = 805 + 1 = 6Table 4 An example of input for Roller Coaster problemPossible Algorithm Design TechniqueRoller coaster problem can be solved using brute force technique or dynamic programming. There is no mistrust that this problem can be solved using brute force and it can produce the rectify output but it will caused an exponential time to the program. Therefore, Dynamic Programming is the better approach to solve Roller Coaster problem.Brute ForceBrute force technique is not recommended to solve this problem because it will result in an exponential solution 3 as we have to modify the physical body (either Bessies eyes open or close) and compare each result every time in order to obtain the optimal solution. In addition, if the number of test cases is getting bigger, it is quite impossible to get a in short period of time taken as to calculate every sub-problem. Since there is no lim it on the test case, user can state their input as much as they want. Lets take sample test case 1 as an example shown in Table 1.3 1 22 13 15 23 1 2 N = 3, K = 1, and L = 2.2 1, 3 1, and 5 2 F = 2, 3, 5 and D = 1, 1.Table 5 Sample test case 1 from the Roller Coaster problemBrute force algorithm will test all the possibilities of Bessies eyes condition, either she had her eyes unfastened or closed.Eyes ConditionLevel ofFunDizzinessInitial00OpenSection 12 10 + 2 = 20 + 1 = 1OpenSection 23 12 + 3 = 51 + 2 = 3OpenSection 35 25 + 5 = 103 + 2 = 5Table 6 First conditionThe first condition fails because Bessies dizziness level exceeds her limit even though she got so much fun.Eyes ConditionLevel ofFunDizzinessInitial00CloseSection 12 100OpenSection 23 10 + 3 = 30 + 1 = 1OpenSection 35 23 + 5 = 81 + 2 = 3Table 7 Second conditionThe second condition also fails because her dizziness level exceeds her limit.Eyes ConditionLevel ofFunDizzinessInitial00OpenSection 12 10 + 2 = 20 + 1 = 1CloseSect ion 23 121 1 = 0OpenSection 35 25 + 2 = 70 + 2 = 2Table 8 Third conditionThe third condition is a success because of her dizziness level does not exceed her limit and she got so much fun.Eyes ConditionLevel ofFunDizzinessInitial00OpenSection 12 10 + 2 = 20 + 1 = 1OpenSection 23 12 + 3 = 51 + 1 = 2CloseSection 35 252 1 = 1Table 9 Fourth condition til now though this condition can be considered as a success because of Bessies dizziness level does not exceed her limit but the fun she got is not much.Eyes ConditionLevel ofFunDizzinessInitial00CloseSection 12 100CloseSection 23 100OpenSection 35 20 + 5 = 50 + 2 = 2Table 10 Fifth conditionEven though this condition can be considered as a success because of Bessies dizziness level does not exceed her limit but she does not have much fun.Eyes ConditionLevel ofFunDizzinessInitial00OpenSection 12 10 + 2 = 20 + 1 = 1CloseSection 23 121 1 = 0CloseSection 35 220Table 11 Sixth conditionEven though this condition can be considered as a success because of Bessies dizziness level does not exceed her limit but she does not have much fun.Eyes ConditionLevel ofFunDizzinessInitial00CloseSection 12 100OpenSection 23 10 + 3 = 30 + 1 = 1CloseSection 35 231 1 = 0Table 12 Seventh conditionEven though this condition can be considered as a success because Bessies dizziness level does not exceed her limit but she does not have much fun.Eyes ConditionLevel ofFunDizzinessInitial00CloseSection 12 100CloseSection 23 100CloseSection 35 200Table 13 Eighth conditionThis condition fails because Bessies does not have fun at all.Therefore, Table 8 which illustrates the third condition is the most optimal solution where it satisfies as the maximum amount of fun Bessie can have when riding a roller coaster without getting sick.Dynamic Programming0-1 KnapsacksThe key idea to solve this problem is by adapting the Knapsack solution in which total amount of dizziness as the total weight she carries in her sack without stupendous the given limit and maximum fun as the maximum total value carries in that sack. To obtain the most optimal solution, we have to select the most maximum of total fun. However, in selecting the maximum total fun, we need to consider the total amount of dizziness because if it exceeds the limit, Bessie will get sick and thus we should avoid it.References1 Knapsack Problem, http//en.m.wikipedia.org/wiki/Knapsack_problem2 Slide 4 in Dynamic Programming 1, CSC752 Advanced Algorithms Analysis, Syed Ahmad Aljunid.3 Brute Force Search, en.wikipedia.org/wiki/Brute-force_search4 Southeast Regionals 2010 Solutions, https//sites.google.com/site/ubcprogrammingteam/news

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.