题意:有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 模拟的更多相关文章

  1. CF Gym 100637A Nano alarm-clocks

    题意:给你一些钟的时间,只可以往后调, 问最少调的时间总和是多少 题解:因为肯定是调到某个出现过时间的,只要枚举时间,在维护一个前缀和快速计算出时间总和就行了. #include<cstdio& ...

  2. 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 ...

  3. 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 ...

  4. Gym 100646 Problem C: LCR 模拟题

    Problem C: LCR 题目连接: http://codeforces.com/gym/100646/attachments Description LCR is a simple game f ...

  5. Codeforces Gym 100269B Ballot Analyzing Device 模拟题

    Ballot Analyzing Device 题目连接: http://codeforces.com/gym/100269/attachments Description Election comm ...

  6. codeforces gym 100286 I iSharp (字符串模拟)

    题目链接 给定一个字符串.输入是int& a*[]&, b, c*; 输出是 int&&[]* a;int& b;int&* c; 输入格式里逗号后面一 ...

  7. Educational Codeforces Round 63 (Rated for Div. 2) C. Alarm Clocks Everywhere gcd

    题意:给出一个递增的时间序列a  给出另外一个序列b  (都是整数) 以b中任选一个数字作为间隔  自己从1开始任选一个时间当成开始时间 输出选择的数字标号以及 开始时间 思路  直接求间隔的公共gc ...

  8. Gym 100633G Nano alarm-clocks

    题目,给定n个时钟,要求把他们调成一样的时间.求最小的步数 思路:肯定是有一个时钟作为标准的啦,要找到这个时钟,怎么找呢?没其他方便的方法,暴力枚举.那么枚举后,怎么能快速地算到其他时钟转到这个时钟的 ...

  9. Gym - 100203G Good elements 水+模拟

    题意:good element的定义是a[i]在1~i-1中任取三个数(可以重复)的和能等于a[i] 思路:vis[x]标记一下任两个数的和,处理a[i]时枚举1~i-1判断vis[a[i] - a[ ...

随机推荐

  1. 【CS-4476-project 6】Deep Learning

    AlexNet / VGG-F network visualized by mNeuron. Project 6: Deep LearningIntroduction to Computer Visi ...

  2. django 之数据库模块

    前提ajango的 数据库主要是为了存取网站的一些内容,数据库的设置一般放在model.py 下   目录下 我们设置如下的数据库:具体的代码如下面所示: # -*- coding: utf-8 -* ...

  3. Linux系统之间文件传输 scp 命令

    个人使用记录 scp /home/liwm/Downloads/mysql-5.5.32-linux2.6-x86_64.tar.gz root@192.168.122.3:/home/oldboy/ ...

  4. Vue style里面使用@import引入外部css, 作用域是全局的解决方案

    问题描述 使用@import引入外部css,作用域却是全局的 <template> </template> <script> export default { na ...

  5. python基础8(装饰器)

    1.装饰器本质 装饰器的本质:一个闭包函数 装饰器的功能:在不修改原函数及其调用方式的情况下对原函数功能进行扩展 2.装饰器函数 假设要写一个输出函数执行时间的装饰器 def timer(func): ...

  6. 【codeforces 20B】Equation

    [题目链接]:http://codeforces.com/contest/20/problem/B [题意] 给你一个方程,让你输出这个方程的解的情况. [题解] a==0,b==0,c==0时,为恒 ...

  7. Dubbo分布式服务框架入门(附project)

    要想了解Dubbo是什么,我们不防先了解它有什么用. 使用场景:比方我想开发一个网上商城项目.这个网上商城呢,比較复杂.分为pc端web管理后台.微信端销售公众号,那么我们分成四个项目,pc端站点,微 ...

  8. 10.29 工作笔记 ndk编译C++,提示找不到头文件(ndk-build error: string: No such file or directory)

    ndk编译C++.提示找不到头文件(ndk-build error: string: No such file or directory) 被这个问题弄得愁眉苦脸啊.心想为啥一个string都找不到呢 ...

  9. MPI搭建简要教程

    具体安装部署,能够參考 http://www.ibm.com/developerworks/cn/linux/l-cn-mpich2/,该教程将的比較具体. 注:不同版本号的 MPICH2对编译器以及 ...

  10. hdoj--2709--Sumsets(数位dp)

    Sumsets Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Su ...