题意:有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. 这两道题目很相似 最优还钱方式 & 除法推导

    http://www.cnblogs.com/grandyang/p/6108158.html http://www.cnblogs.com/grandyang/p/5880133.html 都是根据 ...

  2. Hibernate_9_Person和IdCard实例_一对一关系:基于主键

    1)建立Person类:(与8同样) 2)建立IdCard类:(与8同样) 3)建立持久化类:  1>保存方法(与8同样)  2>获取方法(与8同样)  3>删除方法(与8同样)   ...

  3. 【POJ 2750】 Potted Flower(线段树套dp)

    [POJ 2750] Potted Flower(线段树套dp) Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4566   ...

  4. svn服务器的搭建过程 主要为服务端

    yum -y install subversion 查看版本信息 svnserve --version 创建svn仓库目录 mkdir -p /var/svn/svnrepos 创建svn仓库 svn ...

  5. [Atcoder Grand 006 C] Rabbit Exercise 解题报告 (期望)

    题目链接:https://www.luogu.org/problemnew/show/AT2164 https://agc006.contest.atcoder.jp/tasks/agc006_c 题 ...

  6. 安卓开发--HttpDemo02

    package com.cnn.httpdemo02; import android.app.Activity; import android.os.Bundle; import android.vi ...

  7. 状态压缩dp初学__$Corn Fields$

    明天计划上是要刷状压,但是作为现在还不会状压的\(ruoruo\)来说是一件非常苦逼的事情,所以提前学了一下状压\(dp\). 鸣谢\(hmq\ juju\)的友情帮助 状态压缩动态规划 本博文的大体 ...

  8. codeforces 401 B Sereja and Contests【贪心】

    题意:给出最后的时间n,div 1必须和div2一起举行,并且div2的时间总是比div1大1 给出Sereja(只能参加div2)参加过的k场比赛的时间,问他最少错过了多少场div2,最多错过了多少 ...

  9. 使用物化视图解决GoldenGate不能使用中文表名问题

    源端: conn sh/sh create table "学生" ("学号" number primary key,"姓名" varchar ...

  10. 关于common.js里面的module.exports与es6的export default的思考总结

    背景 公司项目需要裁切功能,基于第三方图片裁切组件vue-cropper(0.4.0版本),封装了图片裁切组件(picture-cut)(放在公司内部组件库,仅限于公司内部使用) 在vue-cropp ...