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

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

#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. 使用VSTO写的一个工作证打印软件

    转行做HR近2年.最近公司要做工牌,工牌上要打印照片,姓名,工号和部门等信息.一共1000多人,如果手工排版手工打印的话,估计要死人. 于是coding的老毛病又犯了,想写个程序来打印工牌.还是拿最近 ...

  2. 1. md5 collision(50)

    md5 collision(50)      ------南京邮电大学ctf: http://chinalover.sinaapp.com/web19/ 发现了一串代码 <?php $md51 ...

  3. Image Processing - Pseudo(False) Color Processing

    最近在一个项目中有需要用到将图片从GrayScale转为FalseColor,然而百度了一下Halcon 伪彩色等关键字均找不到相关答案,倒是有很多OpenCV和Matlab的...后来在搜索中看到了 ...

  4. Find First and Last Position of Element in Sorted Array

    问题:给定一个有序数组和一个目标值,输出目标值在数组中的起始位置和终止位置,如果目标值不在数组中,则输出[-1,-1] 示例: 输入:nums = [1,2,3,5,5,7] target = 5 输 ...

  5. android实现简单计算器

    前台代码如下 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:andro ...

  6. Python实现二叉树的前序、中序、后序、层次遍历

      有关树的理论部分描述:<数据结构与算法>-4-树与二叉树:   下面代码均基于python实现,包含: 二叉树的前序.中序.后序遍历的递归算法和非递归算法: 层次遍历: 由前序序列.中 ...

  7. Untiy ShaderLab 随手记录

    最基本形式 (先不考虑Fog) Shader "Nafio/TUnlit"{ Properties { _MainTex("TT",2D) = "wh ...

  8. 利用外部协议让chrome启动外部应用程序

    http://bbs.kafan.cn/thread-1254526-1-1.html 原理:很简单,标题写的很明确了,不懂的google去. 步骤:举个例子,我要启动D:\Programe file ...

  9. Linux ssh 密钥对登陆设置

    SSH通过密钥连接 ssh -i ~/miyao.pem root@server_ip 密钥权限要设置为仅root用户读写 chmod 600 ~/miyao.pem 密钥可添加到系统里,以后连接可除 ...

  10. 【VueJS】windows环境安装vue-cli及webpack并创建VueJS项目

    1. 安装node.js, Node.js安装包及源码下载地址为:https://nodejs.org/en/download/. 这次node.js不是主角,默认已安装好了,通过npm –v查看no ...