Time Limit: 1sec memory limit: 32 MB descriptionjohn is moving to the penthouse of a tall sky-scraper. he packed all his stuff in boxes and drove them to the entrance of the building on the ground floor. unfortunately the elevator is out of order, so the boxes have to be moved up the stairs. Luckily John has a lot of friends that want to help carrying his boxes up. they all walk the stairway at the same speed of 1 floor per minute, regardless of whether they carry a box or not. the stairway however is so narrow that two persons can't pass each other on it. therefore they deciced to do the following: someone with a box in his hands is always moving up and someone empty-handed is always moving down. when two persons meet each other somewhere on the stairway, the lower one (with a box) hands it over to the higher one (without a box ). (and then the lower one walks down again and the higher one walks up .) the box exchange is instantaneous. when someone is back on the ground floor, he picks up a box and starts walking up. when someone is at the penthouse, he drops the box and walks down again.
After a while the persons are scattered into ss the stairway, some of them with boxes in their hands and some. there are still a number of boxes on the ground floor and John is wondering how much more time it will take before all the boxes are up. help him to find out! Inputone line with a positive number: the number of test cases. Then for each test case:
- One line with three numbers N, F, B with 1 ≤ n, F ≤ 1000 and 1 ≤ B ≤ 1000000: the number of persons, the number of floors (0 = Ground floor, F = penthouse) and the number of boxes that are still on the ground floor.
- N lines with two numbers Fi and Bi with 0 ≤ fi ≤ F and Bi = 0 or bi = 1: the floors where the persons are initially and whether or not they have a box in their hands (1 = Box, 0 = No box ).
Outputone line with the amount of time (in minutes) it will take to get all the remaining boxes to the penthouse. sample input copy sample input to clipboard23 10 50 00 00 02 5 12 13 0 Sample output308 |
First, it can be seen that a group of people are moving, because the exchange of items and directions is the same as that of those without exchange. Another consideration is that moving a new item is always slower than people already on the stairs. So before the last trip, the number of parcels is the same, so it can be used (boxnum/personnum-1) * 2 is used to calculate the time during this period. The rest is the initial state on the stairs and the last trip time.
# Include <iostream> # include <algorithm> using namespace STD; int main (INT argc, char const * argv []) {int testcase, personnum, floornum, boxnum, floor, cally; int person [1001]; CIN> testcase; while (testcase --) {CIN> personnum> floornum> boxnum; For (INT I = 0; I! = Personnum; ++ I) {CIN> floor> cally; If (Cally = 0) person [I] = floornum + floor; else person [I] = floornum * 3-floor;} Sort (person, person + personnum); int remain = boxnum % personnum; int minute = 0; if (remain = 0) {minute = (boxnum/personnum-1) * 2 * floornum + person [personnum-1]; // you do not need to go down to the top, so-1} else {minute = (boxnum/personnum) * 2 * floornum + person [remain-1]; // you need to move the remaining cout <minute <Endl;} return 0;} to the top ;}
Sicily 1193. Up the stairs