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个茶,每个茶的配方是一个字符串,两个字符串之间有一个差值,这个差值为两个字符串每个对应字母之间差的绝对值的最大值,求制作所有茶时获得的所有差值中的最大值. 解法:克鲁斯卡尔.将茶的配方 ...
随机推荐
- Ext.net Calendar 控件在有模板页的时候,模板页定义了TD的样式造成日历控件的样式丢掉
Ext.net Calendar 控件在有模板页的时候,模板页定义了TD的样式造成日历控件的样式丢掉 解决方案 在本页面添加下面的样式 <style type="text/css&qu ...
- MS SQL PIVOT数据透视表
以前曾经做过练习<T-SQL PIVOT 行列转换>https://www.cnblogs.com/insus/archive/2011/03/05/1971446.html 今天把拿出来 ...
- 51nod1060(反素数&dfs)
题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1060 题意:中文题诶- 思路: 这里用到了反素数的性质: 对 ...
- CF360E Levko and Game【贪心+dijsktra】
先把所有边可动设为r[i]又这些边不是l就是r(如果想一个方向改变能更优的话就尽量多的改变),每次跑dijsktra,对于可动边(x,y),如果dis1[x]<=dis2[x],那么就把这条边改 ...
- Ubuntu下安装wine plsql
在电脑上安装了第二系统Ubuntu,但面临各种Linux不支持的开发软件也是束手无策.比如常用的Eclipse,PlSQl,Oracle,QQ等等,于是,上网查阅各种资料,最终的解决方案还是要依赖于w ...
- hadoop是什么?新手自学hadoop教程【附】大数据系统学习教程
Hadoop是一个由Apache基金会所开发的分布式系统基础架构. Hadoop是一个专为离线和大规模数据分析而设计的,并不适合那种对几个记录随机读写的在线事务处理模式. Hadoop=HDFS(文件 ...
- Oracle .NET Core
Oracle .NET Core Beta驱动已出,自己动手写EF Core Oracle https://www.cnblogs.com/yanweidie/p/9064609.html 使用.ne ...
- Hart协议
官方https://fieldcommgroup.org/technologies/hart/documents-and-downloads-hart 参考网页http://www.eeworld.c ...
- #1369 : 网络流一·Ford-Fulkerson算法 模板题
http://hihocoder.com/problemset/problem/1369?sid=1108721 别人都说先学网络流再学二分图,但是我先学了二分图的,感觉网络流好高端啊. 首先对于原图 ...
- UIcollectionView 实现 轮番图
UICollectionView 用作轮番图的实现,demo 地址:https://github.com/SummerHH/YJCYCleCollectionVIew #import <UIKi ...