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个茶,每个茶的配方是一个字符串,两个字符串之间有一个差值,这个差值为两个字符串每个对应字母之间差的绝对值的最大值,求制作所有茶时获得的所有差值中的最大值. 解法:克鲁斯卡尔.将茶的配方 ...
随机推荐
- Image Processing - Pseudo(False) Color Processing
最近在一个项目中有需要用到将图片从GrayScale转为FalseColor,然而百度了一下Halcon 伪彩色等关键字均找不到相关答案,倒是有很多OpenCV和Matlab的...后来在搜索中看到了 ...
- element ui 修改默认样式
修改element ui默认的样式 如果要组件内全局修改 首先在浏览器里F12找到element默认的UI类名 找到要修改的默认类名以后 在文件中修改代码,重写属性 <style> .el ...
- ue4 修改3dui内容
修改text内容1 修改text内容2 上面的方法是对外公开某个控件,然后再蓝图中直接改控件内容 另一种更好的方法时,在控件上新建public变量,控件绑定到这个变量上,由蓝图直接改变这个public ...
- 分享微信h5支付经验
<?php //use Flight; /** * 微信支付服务器端下单 * 微信APP支付文档地址: https://pay.weixin.qq.com/wiki/doc/api/app.ph ...
- Etherscan API 中文文档-账号
本文原文链接 点击这里获取Etherscan API 中文文档(完整版) 完整内容排版更好,推荐读者前往阅读. 账号(Account) 账号及地址相关的 API,接口的参数说明请参考Etherscan ...
- [Android]HttpClient和HttpURLConnection的区别
转载:http://blog.csdn.net/guolin_blog/article/details/12452307 最近在研究Volley框架的源码,发现它在HTTP请求的使用上比较有意思,在A ...
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) C
Helen works in Metropolis airport. She is responsible for creating a departure schedule. There are n ...
- MySQL数据库(4)
子查询,MYSQL创建用户和授权,可视化工具N啊vicat的使用,pymysql模块的使用
- JavaScript实现一个简单的密码输入功能
常见的密码输入框当输入字符后会被替换成‘*’,而且旁边会有个小眼睛可以查看原本的字符,虽然input标签有这个功能,但这只是自己正在看正则表达式的时候突然想到的,就当做个练习,自己手动实现下: < ...
- 算法导论课后习题解答 第一部分 练习1.1-1->1.1-5
很高兴能和大家一起共同学习算法导论这本书.笔者将在业余时间把算法导论后面的题解以博文的形式展现出来希望能得到大家的支持谢谢.如果有可能我会做一些教学视频免费的供大家观看. 练习题选自算法导论中文第三版 ...