1780--2019 year I can become strong field team training match eighteenth

Title Description

wls have a watch, current watch point to a certain time.
There are some very important moments, wls want to watch on the reproduction of these times (not required in order to reproduce). We can rotate the second hand clockwise, counterclockwise rotation can be second hand, minute and hour hands will rotate with the second hand by the rules, wls like to know what the angle of rotation of the second hand at least each time will be visited at least once.
Note that a combination of the minute hand on the clock hour of the second hand, can represent two different times.

 

Entry

The first line an integer n represents the number of time you want to access.
The second line three integers h, m, s respectively represent the current time of minutes and seconds.
N the last line of each row represents three integers hi, mi, si each time you want to access the minutes and seconds.
1≤n≤86,400
0 ≤ h, Hi <24
0 ≦ m, mi The, S, Si <60

 

Export

Output line a second number represents the angle of rotation, the answer to two decimal places.

 

Sample input

1
0 1 0
0 1 1

Sample Output

6.00

Contest1780 - 2019 year I can become strong field team training match eighteenth clock

Solution: violent clockwise and counterclockwise after the time to re-sorted;

For example clockwise violence: enumerate every point, so that the start time to this point first clockwise, then counterclockwise at a point from this point to this point;

Violence and counter clockwise, only in the directions like a change, time to start is to let counterclockwise to a point, and then clockwise from this point to the next

 
#include <bits / STDC ++ H.> 
the using namespace STD; 
typedef Long Long LL; 
const int = 1e6 + MAXN. 7; 
int Min = 1,000,000,007; 
struct Node 
{ 
    int Hi, mi The, Si, Miao; // time conversion is to Miao seconds to calculate 
} time [100005], Start; 
BOOL CMP (Node a, Node B) 
{ 
    return a.miao <b.miao; 
} 
int atoB (a Node, Node B, F int) a // time to time b, f = 0 representative of counter-clockwise, f = 1 Representative clockwise 
{ 
    IF (F == 0) 
    { 
        IF (b.miao> a.miao) 
        { 
            return (43200-b.miao a.miao +) *. 6; 
        } 
        return (a.miao-b.miao) *. 6; 
    } 
    IF (b.miao <a.miao) 
        return (43200-a.miao b.miao +) *. 6; 
    return (b.miao-a.miao). 6 ;; * 
} 
int main () 
{ 
    int n-; 
    Scanf ( "% D", & n-); 
    Scanf ( "% D% D% D", & start.hi, & start.mi , & start.si); 
    IF (start.hi> = 12 is) = start.hi-12 is start.hi; 
    start.miao start.hi = 60 * 3600 * + + start.mi start.si; 
    for (int I = . 1; I <= n-; I ++) 
    { 
        Scanf ( "% D% D% D", & Time [I] .hi, & Time [I] .mi, & Time [I] .si); 
        IF (Time [I ] .hi> = 12 is) Time [I] = .hi Time [I]-12 is .hi; 
        Time [I] .miao Time = [I] * 3600 + Time .hi [I] .mi Time * 60 + [ I] .si; 
    } 
    Sort (Time +. 1, n-+ Time +. 1, CMP); // sort by miao 
    int. 1 = Z, = len. 1; 
    for (; Z <= n-; Z ++) // find the first and start time is not the same, is the first step to re-sort the 
        if (time [z] .miao! = start.Miao) 
        {
            Time [. 1] = Time [Z]; 
        min = min (min, atoB (Start, Time [len],. 1));
            break;
        } 
    For (int I = Z +. 1; I <= n-; I ++) // Sort deduplication 
        !! If (Time [i] .miao = Time [len] .miao && Time [i] .miao = start.miao ) time [len ++] = time [I]; 
    int POI = 0; 
    for (int I =. 1; I <= len; I ++) // find the start of a time of greater than 
        if (time [i] .miao> start.miao) 
        { 
            POI = I; 
            BREAK; 
        } 
    IF (POI == 0) // if all times less than the start time of 
    { 
        min = min (min, atoB (start, time [. 1], 0)) ; 
        for (int I =. 1; I <len; I ++) 
        { 
            min = min (min, atoB (Start, Time [I],. 1) + atoB (Time [I], Time [I +. 1], 0 )); 
        } 
        for (int I = len; I>. 1; - I) { 
            min = min (min, atoB (Start, Time [I], 0) + atoB (Time [I], Time [I. 1- ],1));
        }
        printf("%d.00\n",Min);
        return 0;
    }
    for(int i=poi-1; i<=len; ++i)
    {
        if(i==poi-1)
        {
            int temp=atob(start,Time[poi],0);
            Min=min(Min,temp);
        }
        else if(i==len&&poi==1)
        {
            int temp=atob(start,Time[len],1);
            Min=min(Min,temp);
        }
        else
        {
            int temp=atob(start,Time[i],1),x=i+1;
            if(i==len)x=1;
            temp + = atob (Time [i] Time [x], 0); 
            My = min (Min, temp); 
        } 
    }
    for(int i=1; i<poi; ++i)
    { 
        If (i == POI 1) 
        { 
            int temp = atob (Start, Time [poi-1], 1); 
            My = min (Min, temp); 
        } 
        Else 
        { 
            int temp = atob (Start, Time [i], 1); 
            temp + = atob (Time [i], time [i + 1], 0); 
            My = min (Min, temp); 
        } 
    } 
    For (int i = poi-1; i> = 1; - i) { 
        if (i-1 == 0) 
            MIN = minimum (Min, atob (Start, Time [i], 0) + atob ( h [i], h [len], 1)); 
        presence MIN = minimum (Min, atob (Start, Time [i], 0) + atob (Time [i], time [i-1], 1)); 
    }
    for (int i = len; i> poi; - i) { 
        MIN = minimum (Min, atob (Start, Time [i], 0) + atob (Time [i], time [i-1], 1) ); 
    }
    printf("%d.00\n",Min);
    return 0;
}

  

Guess you like

Origin www.cnblogs.com/lengsong/p/11563848.html