gym-100637a Nano alarm-clocks Simulation

Source: Internet
Author: User

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

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.