题意:给你一些钟的时间,只可以往后调, 问最少调的时间总和是多少

题解:因为肯定是调到某个出现过时间的,只要枚举时间,在维护一个前缀和快速计算出时间总和就行了。

#include<cstdio>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#define first fi
#define second se
using namespace std;
typedef long long ll; const int maxn = ;
const int hmod = ;
const ll mmod = 1e6;
const ll Fac = 1e12;
const ll tmod = 12e12;//ll ll sum[maxn];
ll times[maxn];
int main()
{
int n;
scanf("%d",&n); for(int i = ; i <= n; i++){
int th,tm,ts;
scanf("%d%d%d",&th,&tm,&ts);
times[i] = th*Fac+tm*mmod+ts;
}
sort(times+,times++n);
for(int i = ; i <= n; i++)
sum[i] = sum[i-]+times[i];
ll ans = 0x7fffffffffffffffll;
for(int i = ; i <= n; i++){
ll tmp = i*times[i] - sum[i]; //前面的钟拨到time(i)
tmp += (tmod+times[i])*(n-i)-sum[n]+sum[i];//后面的钟拨到time(i)
ans = min(ans,tmp);
} int ansH,ansM,ansS;
ansH = ans/Fac; ans -= ansH*Fac;
ansM = (ans/mmod); ans -= ansM*mmod;
ansS = ans;
printf("%d %d %d",ansH,ansM,ansS);
return ;
}

CF Gym 100637A Nano alarm-clocks的更多相关文章

  1. Gym - 100637A Nano alarm-clocks 模拟

    题意:有n个时钟,只能顺时针拨,问使所有时间相同的最小代价是多少 思路:将时间排序,枚举拨动到每一个点的时间就好了,容易证明最终时间一定是其中之一 #include <iostream> ...

  2. CF Gym 102028G Shortest Paths on Random Forests

    CF Gym 102028G Shortest Paths on Random Forests 抄题解×1 蒯板子真jir舒服. 构造生成函数,\(F(n)\)表示\(n\)个点的森林数量(本题都用E ...

  3. Codeforces Gym 100637A A. Nano alarm-clocks 前缀和处理

    A. Nano alarm-clocks Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100637/p ...

  4. Codeforces Gym 100637A A. Nano alarm-clocks 前缀和

    A. Nano alarm-clocks Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100637/p ...

  5. CF gym 101933 K King's Colors —— 二项式反演

    题目:http://codeforces.com/gym/101933/problem/K 其实每个点的颜色只要和父亲不一样即可: 所以至多 i 种颜色就是 \( i * (i-1)^{n-1} \) ...

  6. cf Gym 101086M ACPC Headquarters : AASTMT (Stairway to Heaven)

    题目: Description standard input/output As most of you know, the Arab Academy for Science and Technolo ...

  7. CF Gym 100685A Ariel

    传送门 A. Ariel time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  8. CF Gym 100685E Epic Fail of a Genie

    传送门 E. Epic Fail of a Genie time limit per test 0.5 seconds memory limit per test 64 megabytes input ...

  9. CF GYM 100703A Tea-drinking

    题意:龙要制作n个茶,每个茶的配方是一个字符串,两个字符串之间有一个差值,这个差值为两个字符串每个对应字母之间差的绝对值的最大值,求制作所有茶时获得的所有差值中的最大值. 解法:克鲁斯卡尔.将茶的配方 ...

随机推荐

  1. Fluuter常遇到的问题

    The ADB binary found at XX is obsolete and has seriousperformance problems with the Android Emulator ...

  2. HDU - 6400 多校8 Parentheses Matrix(构造)

    Parentheses Matrix Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Oth ...

  3. Linux+ant+jmeter+Jenkins接口持续集成自动化框架搭建

    Linux下安装ant并配置环境变量 1.从http://ant.apache.org 上下载tar.gz版ant 2.复制到/usr下 3.tar -vxzf apache-ant-1.10.1-b ...

  4. shell初级-----构建基本脚本

    使用多个命令 如果想要多个命令同时运行,可以把它们放在一行,用分号隔开. date;who 创建shell脚本文件 创建shell脚本时,必须在文件第一行指定要使用的shell #!/bin/bash ...

  5. OVN架构翻译

    概述 ovn-controller是OVN在虚拟机上的agent,北向连接OVN的南向数据库,学习OVN的配置和状态,并使用虚拟机的状态来填充PN表以及Binding表的Chassis列:南向连接op ...

  6. lower_bound和upper_bound使用说明

    #include <bits/stdc++.h> using namespace std; int main() { ]; ;i<=;i++) { a[i] = i*; } ;i&l ...

  7. [UE4]C++设置AnimInstance的相关问题

    注意:ue4 4.17调用LoadObject<UAnimBlueprintGeneratedClass>直接崩 http://aigo.iteye.com/blog/2285001 UA ...

  8. ue4 motage

    Montage是什么 一个(可以自由拼接动画的)动画剪辑,通过slot,在任意时候由玩家主动向动画系统push自己制作的动画剪辑 Montage用途 上图是一个近身攻击动画,含有 3 个片段 [开始. ...

  9. python3编程技巧二——如何在列表、字典、集合 中根据条件筛选数据

    一.列表筛选数据 # coding=utf-8 from random import randint # 创建随机列表 l = [randint(-10, 10) for i in range(10) ...

  10. Mac用brew安装MySQL

    1.先安装brew 网址:https://brew.sh/ 复制命令:/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent ...