HDOJ 1050 Moving Tables (classic greedy)

Source: Internet
Author: User

Moving Tables Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)Total submission (s): 24553 Accepted Submission (s): 8116

problem DescriptionThe famous ACM (Advanced computer Maker) company have rented a floor of a building whose shape are in the following Figu Teh



The floor has a rooms each of the side and South side along the corridor. Recently the company made a plan to reform its system. The reform includes moving a lot of tables between rooms. Because the corridor is narrow and all the tables was big, only one table can pass through the corridor. Some plan is needed to make the moving efficient. The manager figured out of the following plan:moving a table from a hostel to another the can is done within minutes. When moving a table from the class I to the Class J, the part of the corridor between the front of the class I and the front of the class J is Used. So, during each minutes, several moving between and rooms not sharing the same part of the corridor would be done Simult aneously. To make it clear the manager illustrated the possible cases and impossible cases of simultaneous moving.



For each of the either, at the most one table would be a moved in or moved out. Now, the manager seeks out a method to minimize the time to move all the tables. Your job is-to-write a program to solve the manager ' s problem.
 
InputThe input consists of T test cases. The number of test cases) (T is given in the first line of the input. Each test case begins with a line containing an integer N, 1<=n<=200, which represents the number of tables to move . Each of the following N lines contains-positive integers s and t, representing that a table was to move from the hostel numbe R S to the guest number T (each of the number appears at a once in the N lines). From the N+3-rd line, the remaining test cases is listed in the same manner as above.
 
Outputthe output should contain the minimum time in minutes to complete the moving, one per line.
 
Sample Input
 
Sample Output
102030
 
for several days did not do ACM Steps, sleep before the water.
This is a 1.3 greedy topic, the use of greedy ideas of the classic type of topic.

Test instructions: Moving a table from one room to another in a narrow corridor, the width of the corridor only allows one table to pass. Given t, indicates that there is a T set of test data. Give n again, which means to move n tables. n There are n rows, two numbers per line, which means moving the table from room A to room B. Corridor distribution map as shown, it takes 10 minutes for each table to move to the destination room, asking for the time it takes to move n tables.
problem-solving idea: If you move multiple tables, the corridor you need to pass is not coincident, that is, you can move at the same time.       If there is a corridor with m tables to pass through, only one table at a time, you need to m*10 to move the table. Set an array, and the subscript value is the room number. When the table passes through the room, the room number is the array value corresponding to the subscript plus 10. Finally, the largest array value is found, which is the shortest time required to move the table.
The specific code is as follows:
<span style= "FONT-SIZE:14PX;" > #include <cstdio> #include <cstring> #include <algorithm>using namespace Std;int main () {int t,n, COUNT[410],I,START,END,K;SCANF ("%d", &t), while (t--) {scanf ("%d", &n), memset (Count,0,sizeof (count)); n--) {scanf ("%d%d", &start,&end), if (start>end)//possible departure location larger than the destination room. {            //No matter the size, we can be seen from the small room moved to the big Room k=start;start=end;end=k;} if (start%2==0)//To consider the actual situation, the departure room for even is minus one, can refer to the picture given in the title    start-=1;if (end%2==1)//destination room for odd time plus a    end+=1;for (i=start;i <=end;++i)   count[i]+=10;} printf ("%d\n", *max_element (count,count+400)),//stl in the search for the number of sequence maximum function}return 0;} </span>


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDOJ 1050 Moving Tables (classic greedy)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.