CF Gym 100637A Nano alarm-clocks
题意:给你一些钟的时间,只可以往后调, 问最少调的时间总和是多少
题解:因为肯定是调到某个出现过时间的,只要枚举时间,在维护一个前缀和快速计算出时间总和就行了。
#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的更多相关文章
- Gym - 100637A Nano alarm-clocks 模拟
题意:有n个时钟,只能顺时针拨,问使所有时间相同的最小代价是多少 思路:将时间排序,枚举拨动到每一个点的时间就好了,容易证明最终时间一定是其中之一 #include <iostream> ...
- CF Gym 102028G Shortest Paths on Random Forests
CF Gym 102028G Shortest Paths on Random Forests 抄题解×1 蒯板子真jir舒服. 构造生成函数,\(F(n)\)表示\(n\)个点的森林数量(本题都用E ...
- 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 100637A A. Nano alarm-clocks 前缀和
A. Nano alarm-clocks Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100637/p ...
- CF gym 101933 K King's Colors —— 二项式反演
题目:http://codeforces.com/gym/101933/problem/K 其实每个点的颜色只要和父亲不一样即可: 所以至多 i 种颜色就是 \( i * (i-1)^{n-1} \) ...
- 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 ...
- CF Gym 100685A Ariel
传送门 A. Ariel time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- 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 ...
- CF GYM 100703A Tea-drinking
题意:龙要制作n个茶,每个茶的配方是一个字符串,两个字符串之间有一个差值,这个差值为两个字符串每个对应字母之间差的绝对值的最大值,求制作所有茶时获得的所有差值中的最大值. 解法:克鲁斯卡尔.将茶的配方 ...
随机推荐
- 星级评分--封装成jquery插件
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- map中根据value获取key
public static String getKeyByValue(Map map, Object value) { String keys=""; Iterator it = ...
- lung 分割论文
<4D Lung Tumor Segmentation via Shape Prior and Motion Cues > Abstract— Lung tumor segmentatio ...
- HDU - 3664 Permutation Counting 排列规律dp
Permutation Counting Given a permutation a1, a2, … aN of {1, 2, …, N}, we define its E-value as the ...
- 用VisualSVN Server创建版本库,以及TortoiseSVN的使用
介绍了VisualSVN Server和TortoiseSVN的下载,安装,汉化. SVN服务器搭建和使用(一) Subversion是优秀的版本控制工具,其具体的的优点和详细介绍,这里就不再多说. ...
- SAP中对于获取订单的状态
在SAP中对于如何获取订单的状态,提供了至少两个函数,分别是 STATUS_READ 和 STATUS_TEXT_EDIT.下面简单介绍这两个函数 1.STATUS_READ 改函数的实现原理大 ...
- ES6入门教程---解构赋值和字符串扩展
解构赋值: ES6允许按照一定模式,从数组和对象中提取值,对变量进行赋值,这被称为解构(Destructuring). 数组的解构赋值: 按照对应的顺序解构. var arr = [1,[2,3]]; ...
- X Samara Regional Intercollegiate Programming Contest DIV2
http://codeforces.com/gym/101341 其实我觉得这份题很不错的,虽然是div2,但是感觉对我挺有帮助(我比较垃圾0.0),还没补完(做的时候一直蒙逼,要补很多题)先写一点点 ...
- HDU 1027 G - Can you answer these queries?
http://acm.hdu.edu.cn/showproblem.php?pid=4027 Can you answer these queries? Time Limit: 4000/2000 M ...
- (转)linux下od命令的使用
linux下od命令的使用 原文:http://blog.csdn.net/shylock_backer/article/details/46473283 名称:od作用:格式化输出文件中的数据提要: ...