Clock HDU-6551 analog

There is a clock in wls, and the current clock points to a certain time.
There are also some very important moments that wls wants to reproduce on the clock (does not need to reproduce in sequence). We can turn the second hand clockwise or counterclockwise. Both the minute hand and the hour hand will follow the second hand according to the rules. wls wants to know at least how many angles the second hand can rotate so that every moment can be accessed at least once.
Note that a combination of hour, minute, and second hands on the clock can represent two different times. An integer n in the first line of
Input
represents how many moments to visit.
The three integers h, m, and s in the second line represent the hour, minute, and second of the current moment, respectively.
Three integers hi, mi, si in each of the last n lines represent the hour, minute, and second of each time to be accessed.
1 ≤ n ≤ 86, 400
0 ≤ h, hi <24
0 ≤ m, mi, s, si <60
Output
Output a line with a number representing the angle of rotation in seconds, and the answer should be two decimal places.
Sample Input
1
0 1 0
0 1 1
Sample Output
6.00

Problem solution:
simulate in four situations
① only go clockwise
② only go counterclockwise
③ first go clockwise and then counterclockwise
④ first go counterclockwise and then clockwise The
following definition circle is the degree to be turned in 12 hours. The
general simulation idea is , First save the time required for clockwise travel in an array, and then sort by sort. The first element is the minimum value of clockwise travel, and circle minus the minimum value of the last element even if it travels counterclockwise. Then we will simulate ③ and ④ situations:
first clockwise and then counterclockwise is to traverse to reach each point
. The distance traveled clockwise to reach the i-th point 2+the distance traveled counterclockwise to reach the i+1th point is
first counterclockwise and then clockwise The hour hand is the
counterclockwise distance of traversing to each point to reach the i-th point 2 + the clockwise distance of reaching the i-1th point.
Keep updating the minimum value at each step.

Code:

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cctype>
#include<iomanip>
#include<map>
#include<vector>
#include<list>
#include<deque>
#include<stack>
#include<queue>
#include<set>
#include<cctype>
#include<string>
#include<stdexcept>
#include<fstream>
#define mem(a,b) memset(a,b,sizeof(a))
#define mod 10000007
#define debug() puts("what the fuck!")
#define dedebug() puts("what the fuck!!!")
#define ll long long
#define speed {
    
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); };
using namespace std;
const double PI = acos(-1.0);
const int maxn = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const double esp_0 = 1e-6;
int gcd(int x, int y) {
    
    
	return y ? gcd(y, x % y) : x;
}
int n;
ll h, m, s, t;
ll hh, mm, ss, tt;
ll clockwise[maxn];
const ll circle = 360 * 60 * 12;
int main() {
    
    
	mem(clockwise, 0);
	scanf("%d", &n);
	scanf("%lld%lld%lld", &h, &m, &s);
	if (h > 12)h -= 12;
	t = h * 3600 + m * 60 + s;
	for (int i = 1; i <= n; ++i) {
    
    
		scanf("%lld%lld%lld", &hh, &mm, &ss);
		if (hh > 12)hh -= 12;
		tt = hh * 3600 + mm * 60 + ss;
		clockwise[i] = (tt - t) * 6;
		if (clockwise[i] < 0)clockwise[i] += circle;
	}
	sort(clockwise + 1, clockwise + n + 1);
	ll minn = INF + circle;
	clockwise[0] = circle;
	clockwise[n + 1] = circle;
	minn = min(minn, clockwise[n]);
	minn = min(minn, circle - clockwise[1]);
	for (int i = 1; i <= n; ++i) {
    
    
		minn = min(minn, clockwise[i] * 2 + (circle - clockwise[i + 1]));
	}
	for (int i = 1; i <= n; ++i) {
    
    
		minn = min(minn, (circle - clockwise[i]) * 2 + clockwise[i - 1]);
	}
	printf("%lld.00\n", minn);
	return 0;
}

Guess you like

Origin blog.csdn.net/qq_40924271/article/details/109663244