Test instructions: There are n clocks that can only be dialed clockwise, asking what is the minimum cost of making all the same time
Idea: Sort the time, enumerate the time at each point, and easily prove that the final time must be one of them.
1#include <iostream>2#include <cstdio>3#include <fstream>4#include <algorithm>5#include <cmath>6#include <deque>7#include <vector>8#include <queue>9#include <string>Ten#include <cstring> One#include <map> A#include <stack> -#include <Set> - #defineLL Long Long the #defineEPS 1e-8 - #defineINF 0x3f3f3f3f - #defineMAXN 200005 - #defineU 1000000 + using namespacestd; - LL T[MAXN], SUM1[MAXN], SUM2[MAXN]; + intMain () A { at #ifndef Online_judge -Freopen ("In.txt","R", stdin); - //freopen ("OUT.txt", "w", stdout); - #endif //Open_file - intN; -memset (T,0,sizeof(t)); inmemset (SUM1,0,sizeof(SUM1)); -memset (sum2,0,sizeof(sum2)); to LL x, y, Z; +scanf"%d", &n); - for(inti =1; I <= N; i++){ thescanf"%i64d%i64d%i64d", &x, &y, &z); *T[i] = (x * U + y) * U +Z; $ }Panax NotoginsengSort (T +1, T + N +1); - for(inti =1; I <= N; i++){ theSum1[i] = sum1[i-1] +T[i]; + } A for(inti = n; I >=1; i--){ theSum2[i] = sum2[i +1] +T[i]; + } - LL ans; $ BOOLFlag =false; $LL all = 1000000LL * 1000000LL *12LL; - for(inti =1; I <= N; i++){ -LL res = (I-1) * T[i]-sum1[i-1] + all * (n-i)-(Sum2[i +1]-(n-i) *t[i]); the if(!flag) { -Ans =Res;WuyiFlag =true; the } - Else{ WuAns =min (ans, res); - } About } $LL s = ans%U; -Ans = ans/U; -LL m = ans%U; -Ans = ans/U; ALL h =ans; +printf"%i64d%i64d%i64d\n", H, M, s); the}
gym-100637a Nano alarm-clocks Simulation