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[ ...
随机推荐
- mariadb 视图 事务 索引 外键
视图 对于复杂的查询,在多个地方被使用,如果需求发生了改变,需要更改sql语句,则需要在多个地方进行修改,维护起来非常麻烦 假如因为某种需求,需要将user拆房表usera和表userb,该两张表 ...
- pandas 4 处理缺失数据nan
from __future__ import print_function import pandas as pd import numpy as np np.random.seed(1) dates ...
- 优秀Swift开源项目推荐
工具类 SwiftyJSON:GitHub上最为开发者认可的JSON解析类 Safe.ijaimi:源码漏洞分析检测工具,一键完成 Dollar.swift:Swift版Lo-Dash(或unders ...
- jstack命令dump线程信息
jstack命令dump线程信息 D:\Java\jdk1.8.0_05\bin>jstack.exe 6540 > dump17 6540为java 线程pid: 出来的dump17文件 ...
- xml布局内容总结(四)--Android
(1)对于xml编写界面较复杂的情况下,使用include会使得编写和查看更清楚 <LinearLayout android:layout_width="mat ...
- Java排序之直接选择排序
public class SelectSort { public static void selectSort(int [] a){ int min; int temp; if(a==null || ...
- metasploit.meterpreter学习笔记(博主推荐)
Metasploit学习笔记(博主推荐) 继续上面的博客 metasploit.meterpreter的基本使用: 首先来获取当前系统(即xp)下的正在运行的一些进程 获得进程之后,我们通过migra ...
- 基于opencv的手写数字字符识别
摘要 本程序主要参照论文,<基于OpenCV的脱机手写字符识别技术>实现了,对于手写阿拉伯数字的识别工作.识别工作分为三大步骤:预处理,特征提取,分类识别.预处理过程主要找到图像的ROI部 ...
- C#篇(一)——字段与属性
字段和属性有什么区别? class Student { private int age; public int Age { get { return age; } set { age = value; ...
- 为什么越来越少的开源项目使用 GPL 协议
原文出处: opensource 译文出处:oschina/王练 前段时间,我在 RedMonk 上看到了一篇来自 Stephen O’Grady 的有趣推文,介绍了开源许可证目前的状态,以 ...