Codeforces Gym 100637A A. Nano alarm-clocks 前缀和处理
A. Nano alarm-clocks
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/gym/100637/problem/A
Description
An old watchmaker has n stopped nano alarm-clocks numbered with integers from 1 to n. Nano alarm-clocks count time in hours, and in one hour there are million minutes, each minute lasting a million seconds. In order to repair them all the watchmaker should synchronize the time on all nano alarm-clocks. In order to do this he moves clock hands a certain time forward (may be zero time). Let’s name this time shift a transfer time.
Your task is to calculate the minimal total transfer time required for all nano alarm-clocks to show the same time.
Input
The first line contains a single integer n — the number of nano alarm-clocks (2 ≤ n ≤ 105). In each i-th of the next n lines the time h, m,s, shown on the i-th clock. Integers h, m and s show the number of hours, minutes and seconds respectively. (0 ≤ h < 12, 0 ≤ m < 106,0 ≤ s < 106).
Output
Output three integers separated with spaces h, m and s — total minimal transfer time, where h, m and s — number of hours, minutes and seconds respectively (0 ≤ m < 106, 0 ≤ s < 106).
Sample Input
2
10 0 0
3 0 0
Sample Output
5 0 0
HINT
题意
给你n个时钟,只可向前拨 问你总计拨多少时间,可以使得所有表的时间一样
题解:
排序+维护前缀和,暴力出最小的就OK
代码
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef __int64 ll;
using namespace std;
inline ll read()
{
ll x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
//**************************************************************************************
ll t=;
int n;
ll sum[];
ll a[];
int main()
{ scanf("%d",&n);
for(int i=; i<=n; i++)
{
ll h,m,s;
cin>>h>>m>>s;
a[i]=s+m*t+t*t*h;
}
sort(a+,a+n+);
for(int i=;i<=n;i++)
sum[i]=sum[i-]+a[i];
ll tt=*t*t;
ll ans=tt*;//此处无穷大就好了 for(int i=n;i>=;i--)
{
ll xx=(a[i]*(i-)-sum[i-]+(a[i]+tt)*(n-i)-(sum[n]-sum[i]));
ans=min(xx,ans);
}
printf("%I64d %I64d %I64d\n",(ans/t)/t,(ans/t)%t,ans%t);
return ;
}
Codeforces Gym 100637A A. Nano alarm-clocks 前缀和处理的更多相关文章
- 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 ... 
- Codeforces gym 101343 J.Husam and the Broken Present 2【状压dp】
		2017 JUST Programming Contest 2.0 题目链接:Codeforces gym 101343 J.Husam and the Broken Present 2 J. Hu ... 
- Codeforces Gym 101252D&&floyd判圈算法学习笔记
		一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ... 
- Codeforces Gym 101190M Mole Tunnels - 费用流
		题目传送门 传送门 题目大意 $m$只鼹鼠有$n$个巢穴,$n - 1$条长度为$1$的通道将它们连通且第$i(i > 1)$个巢穴与第$\left\lfloor \frac{i}{2}\rig ... 
- Codeforces Gym 101623A - 动态规划
		题目传送门 传送门 题目大意 给定一个长度为$n$的序列,要求划分成最少的段数,然后将这些段排序使得新序列单调不减. 考虑将相邻的相等的数缩成一个数. 假设没有分成了$n$段,考虑最少能够减少多少划分 ... 
- 【Codeforces Gym 100725K】Key Insertion
		Codeforces Gym 100725K 题意:给定一个初始全0的序列,然后给\(n\)个查询,每一次调用\(Insert(L_i,i)\),其中\(Insert(L,K)\)表示在第L位插入K, ... 
- codeforces gym 100553I
		codeforces gym 100553I solution 令a[i]表示位置i的船的编号 研究可以发现,应是从中间开始,往两边跳.... 于是就是一个点往两边的最长下降子序列之和减一 魔改树状数 ... 
- CodeForces Gym 100213F Counterfeit Money
		CodeForces Gym题目页面传送门 有\(1\)个\(n1\times m1\)的字符矩阵\(a\)和\(1\)个\(n2\times m2\)的字符矩阵\(b\),求\(a,b\)的最大公共 ... 
- Codeforces GYM 100876 J - Buying roads 题解
		Codeforces GYM 100876 J - Buying roads 题解 才不是因为有了图床来测试一下呢,哼( 题意 给你\(N\)个点,\(M\)条带权边的无向图,选出\(K\)条边,使得 ... 
随机推荐
- Jquery中的 height(), innerHeight() outerHeight()区别
			jQuery中的 height innerHeight outerHeight区别 标准浏览器下: height:高度 innerHeight:高度+补白 outerHeight:高度+补白+边框,参 ... 
- Linux常用命令  查看进程信息时  copy的-----温故而知新
			1.查进程 ps命令查找与进程相关的PID号: ps a 显示现行终端机下的所有程序,包括其他用户的程序. ps -A 显示所有程序. ps c 列出程序时,显示每个程序真正的 ... 
- CSS2-3常见的demo列子总结
			CSS2-3常见的demo列子总结 阅读目录 1. css超过一行或者多行后显示省略号. 2. css图片未知高度垂直居中完美解决方案. 3. 学习使用 :before和 :after伪元素 回到顶部 ... 
- Android 源码编译错误
			参考文章:http://blog.csdn.net/brightming/article/details/49763515/ Building with Jack: out/target/common ... 
- [Effective JavaScript 笔记]第2章:变量作用域--个人总结
			前言 第二章主要讲解各种变量作用域,通过这章的学习,接触到了很多之前没有接触过的东西,比如不经常用到的eval,命名函数表达式,with语句块等,下面是一个列表,我对各节的一点点个人总结,很多都是自己 ... 
- Unity3D Optimizing Graphics Performance for iOS
			原地址:http://blog.sina.com.cn/s/blog_72b936d801013ptr.html icense Comparisons http://unity3d.com/unity ... 
- python学习之最简单的获取本机ip信息的小程序
			文章是从我的个人博客粘贴过来的,大家可以直接访问我的个人博客哦 http://www.iwangzheng.com 获取本机ip信息的命令ifconfig总是在用,这次拿到pyhton代码里,感觉py ... 
- [Educational Codeforces Round 16]E. Generate a String
			[Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ... 
- [NOIP2015]推销员
			[NOIP2015]推销员 试题描述 阿明是一名推销员,他奉命到螺丝街推销他们公司的产品.螺丝街是一条死胡同,出口与入口是同一个,街道的一侧是围墙,另一侧是住户.螺丝街一共有 N 家住户,第 i 家住 ... 
- nginx学习(二):初识配置文件
			nginx的配置文件默认在nginx安装目录中的conf子目录中,主配置文件为nginx.conf, root@mgmserver conf]# pwd/usr/local/nginx/conf一.配 ... 
