Gym - 100637A Nano alarm-clocks 模拟
题意:有n个时钟,只能顺时针拨,问使所有时间相同的最小代价是多少
思路:将时间排序,枚举拨动到每一个点的时间就好了,容易证明最终时间一定是其中之一
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#define LL long long
#define eps 1e-8
#define INF 0x3f3f3f3f
#define MAXN 200005
#define U 1000000
using namespace std;
LL t[MAXN], sum1[MAXN], sum2[MAXN];
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // OPEN_FILE
int n;
memset(t, , sizeof(t));
memset(sum1, , sizeof(sum1));
memset(sum2, , sizeof(sum2));
LL x, y, z;
scanf("%d", &n);
for(int i = ; i <= n; i++){
scanf("%I64d%I64d%I64d", &x, &y, &z);
t[i] = (x * U + y) * U + z;
}
sort(t + , t + n + );
for(int i = ; i <= n; i++){
sum1[i] = sum1[i - ] + t[i];
}
for(int i = n; i >= ; i--){
sum2[i] = sum2[i + ] + t[i];
}
LL ans;
bool flag = false;
LL ALL = 1000000LL * 1000000LL * 12LL;
for(int i = ; i <= n; i++){
LL res = (i - ) * t[i] - sum1[i - ] + ALL * (n - i) - (sum2[i + ] - (n - i) * t[i]);
if(!flag){
ans = res;
flag = true;
}
else{
ans = min(ans, res);
}
}
LL s = ans % U;
ans = ans / U;
LL m = ans % U;
ans = ans / U;
LL h = ans;
printf("%I64d %I64d %I64d\n", h, m, s);
}
Gym - 100637A Nano alarm-clocks 模拟的更多相关文章
- CF Gym 100637A Nano alarm-clocks
题意:给你一些钟的时间,只可以往后调, 问最少调的时间总和是多少 题解:因为肯定是调到某个出现过时间的,只要枚举时间,在维护一个前缀和快速计算出时间总和就行了. #include<cstdio& ...
- 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 ...
- Gym 100646 Problem C: LCR 模拟题
Problem C: LCR 题目连接: http://codeforces.com/gym/100646/attachments Description LCR is a simple game f ...
- Codeforces Gym 100269B Ballot Analyzing Device 模拟题
Ballot Analyzing Device 题目连接: http://codeforces.com/gym/100269/attachments Description Election comm ...
- codeforces gym 100286 I iSharp (字符串模拟)
题目链接 给定一个字符串.输入是int& a*[]&, b, c*; 输出是 int&&[]* a;int& b;int&* c; 输入格式里逗号后面一 ...
- Educational Codeforces Round 63 (Rated for Div. 2) C. Alarm Clocks Everywhere gcd
题意:给出一个递增的时间序列a 给出另外一个序列b (都是整数) 以b中任选一个数字作为间隔 自己从1开始任选一个时间当成开始时间 输出选择的数字标号以及 开始时间 思路 直接求间隔的公共gc ...
- Gym 100633G Nano alarm-clocks
题目,给定n个时钟,要求把他们调成一样的时间.求最小的步数 思路:肯定是有一个时钟作为标准的啦,要找到这个时钟,怎么找呢?没其他方便的方法,暴力枚举.那么枚举后,怎么能快速地算到其他时钟转到这个时钟的 ...
- Gym - 100203G Good elements 水+模拟
题意:good element的定义是a[i]在1~i-1中任取三个数(可以重复)的和能等于a[i] 思路:vis[x]标记一下任两个数的和,处理a[i]时枚举1~i-1判断vis[a[i] - a[ ...
随机推荐
- 关于 Error: No PostCSS Config found in 的错误
问题描述: 项目在本地运行不报错,上传到 GitHub 之后,再 clone 到本地, npm install 安装完成之后再执行 npm run dev 这时报错 Error: No PostCSS ...
- fileOP
public void getFileDir(String filePath) { try{ this.tv.setText("当前路径:"+filePath);// 设置当前所在 ...
- ASP.NET-缓存基本知识点
asp.net cache是一种缓存技术,然而,我们在asp.net程序中还可以使用其他的缓存技术,这些不同的缓存也各有所长.由于asp.net cache不能提供对外访问能力,因此,它不可能取代以m ...
- jsp urlrewrite 中正則表達式不包括某个字符串写法
因在程序中须要做城市间跳转,可是页面中包括的css.scripts和图片等路径是要排除在外的. 这就须要在正则中指定当遇到哪些 字符时须要略过. 正则例如以下: /((? !css)(?!script ...
- python批量下载色影无忌和蜂鸟的图片 爬虫小应用
有些冗余信息.由于之前測试正則表達式.所以没有把它们给移走.只是不影响使用. # -*- coding:utf-8 -*- import re,urllib,sys,os,time def getAl ...
- iOS 9 适配,我咋还没遇到这么多坑呢呀
iOS 9 适配,我咋还没遇到这么多坑呢呀 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途-保持一致"创作公用协议 ...
- ubuntu 非长期支持版升级系统版本号(ssh登录情况适用)
(1)当前系统为非长期支持版.而且已被废弃,仅仅能逐版本号升级 以当前系统版本号为11.10为例 改动source.list更新源为通用old源,由于原来的源已经不可用 deb http://old- ...
- Android面试精华
SIM卡的EF文件有什么作用? SIM卡里的全部文件按树来组织: 主文件MF(Master File)--主文件仅仅有文件头,里面存放着整个SIM卡的控制和管理信息 专用文件DF(Dedicated ...
- Mysql-in查询问题
Mysql-in查询问题 标签(空格分隔): mysql 问题:mysql用in语法查询出来的数据少了好多! 我的实际情况: 数据表: content字段记录着一些选项的id,多个选项用逗号隔开,比如 ...
- 微信公众平台开发学习笔记2--获取access token
access_token是公众号的全局唯一票据,公众号调用各接口时都需使用access_token.获取的access_token过期时间为2小时.获取access token具体说明请参考官方文档. ...