题意:有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. Qt之QToolButton

    简述 QToolButton类提供了用于命令或选项可以快速访问的按钮,通常可以用在QToolBar里面. 工具按钮和普通的命令按钮不同,通常不显示文本,而显示图标. 简述 详细描述 常用接口 更多参考 ...

  2. asm下重定向数据文件小例(使用toad工具)

    原创作品,出自 "深蓝的blog" 博客,深蓝的blog:http://blog.csdn.net/huangyanlong/article/details/46863991 场景 ...

  3. 面试题:Student s = new Student();在内存中做了哪些事情?即创建一个对象做了哪些事情

    lStudent s = new Student();在内存中做了哪些事情? •载入Student.class文件进内存(方法区) •在栈内存为s开辟空间 •在堆内存为学生对象开辟空间 •对学生对象的 ...

  4. 【Android应用开发技术:基础构建】命令行下的Android应用开发

    作者:郭孝星 微博:郭孝星的新浪微博 邮箱:allenwells@163.com 博客:http://blog.csdn.net/allenwells github:https://github.co ...

  5. 高速掌握Lua 5.3 —— I/O库 (1)

    Q:什么是"Simple Model"? A:全部的文件操作都基于一个默认的输入文件和一个默认的输出文件.这就意味着同一时间对于输入和输出来说,仅仅可操作一个文件(默认的文件). ...

  6. Innosetup

    卸载的同时删除日志,卸载的时候判断程序是否正在运行,regsvr32 1.卸载程序的时候如何判断程序是否正在运行 http://bbs.csdn.net/topics/370097914 2.强制删除 ...

  7. thinkphp5项目--个人博客(七)

    thinkphp5项目--个人博客(七) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...

  8. dns-sd._udp.<domain>. 域名发现 本质和MDNS同

    DNS Service Discovery is a way of using standard DNS programming interfaces, servers, and packet for ...

  9. hdoj--3552--I can do it!(贪心模拟)

    I can do it! Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Tot ...

  10. Visual Studio添加lib到链接依赖项的几种方法

    使用第三方库文件编写应用时经常会出现链接错误: 错误 22 error LNK2019: 无法解析的外部符号..... 该符号在函数.....在....中被引用 出现这个错误的原因很简单,链接器在將库 ...