Disk Schedule
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 153 Accepted Submission (s): 86
Problem Description has many requirements for reading data from a disk, including sequential reading and random reading. To improve efficiency, You need to manually read the disk. However, in reality, this approach is complicated. We consider a relatively simple scenario.
A disk has many tracks, and each track has many sectors for data storage. When we want to read data in a specific sector, the head needs to jump to a specific track and sector for read operations. For simplicity, we assume that the head can rotate at a clockwise or counter-clockwise speed in a certain orbit. The rotation time for one week is 360 units of time. The head can also be freely moved to a certain track for reading. The time for each jump to an adjacent track is 400 units of time, and the position of the front and back of the head remains unchanged. The time for reading data at a time is 10 units, and the position of the sector of the front and back heads remains unchanged. The head can only do one thing at the same time: Jump to the track, rotate or read.
Now, you need to read a set of data on the disk. Assume that each track has at most one read request. The read sector is an integer sector distributed between 0 and 359 on the track, that is, a certain 360-level sub-point of the track. The starting point of the head is 0-track and 0-sector. No data is read at this time. After all the reads are completed, the head must return to the starting point of the 0-sector Sector of the zero track. The minimum time required to complete the specified read.
The first line of Input contains an integer M (0 For each group of test data, the first row contains an integer N (0
Output outputs an integer for each group of test data, indicating the time required to complete all read operations.
Sample Input
311 1031 203 305 1021 102 11
Sample Output
83040901642
Source 2014 Baidu STAR Program Design Competition-qualifying
Recommendliuyiding
Thought [turn]: Euclidean Traveling Salesman Problem is the problem of determining the shortest closed journey of each point connected to n points given on the plane. (A) a solution of seven points is given. The general form of this problem is NP-complete, so the solution requires more time than polynomial.
J. l. bentley suggests simplifying the problem by only considering bitonic tour, which is a journey from the leftmost point to the rightmost point, strictly from left to right, then strictly from right to left to start point. (B) shows the shortest double-adjustment routes of the same seven points. In this case, polynomial algorithms are possible. In fact, there is an O (n * n) Time Algorithm for determining the optimal dual-tuning route.
Figure a figure B <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + kernel/Uyr61xMa9w + bJz7XExt + kernel/Ivau4 + kernel + pgltzybzcm9 "http://www.2cto.com/uploadfile/Collfiles/20140526/20140526091425235.png" alt = "\">
For any point I, there are two connection methods, one is (a), I is connected to the I-1, the other is (B ), I is not connected to the I-1.
Based on the double-tuning journey, we know that node n must be connected to n. Then, if we want d [n] [n-1], simply add p [n-1] [n] to it is the shortest double-adjustment closed route.
According to, it is easy to write an equation:
Dp [I] [j] = dp [I-1] [j] + dist [I] [I-1];
Dp [I] [I-1] = min (dp [I] [I-1], dp [I-1] [j] + dist [j] [I]);
/*************************************************************************> File Name: hdu-4824-Disk_Schedule.cpp> Author: nealgavin> Mail: nealgavin@126.com > Created Time: Sun 25 May 2014 07:38:59 PM CST ************************************************************************/#include
#include
#include
using namespace std;const int mm = 1000+9;const int oo = 1e9;int dp[mm][mm],d[mm];int n;int dis(int x,int y){ if(d[x] < d[y]) x^=y^=x^=y; int distance = d[x]-d[y]; return min(distance,360-distance);}void init(){ dp[1][0] = dis(0,1);}int DP(){ for(int i=2;i<=n;++i) { dp[i][i-1] = oo; for(int j=0;j