CF Gym 100637A Nano alarm-clocks

题意:给你一些钟的时间,只可以往后调, 问最少调的时间总和是多少

题解:因为肯定是调到某个出现过时间的,只要枚举时间,在维护一个前缀和快速计算出时间总和就行了。

#include<cstdio>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#define first fi
#define second se
using namespace std;
typedef long long ll;

const int maxn = 100005;
const int hmod = 12;
const ll mmod = 1e6;
const ll Fac = 1e12;
const ll tmod = 12e12;//ll

ll sum[maxn];
ll times[maxn];
int main()
{
    int n;
    scanf("%d",&n);

    for(int i = 1; i <= n; i++){
        int th,tm,ts;
        scanf("%d%d%d",&th,&tm,&ts);
        times[i] = th*Fac+tm*mmod+ts;
    }
    sort(times+1,times+1+n);
    for(int i = 1; i <= n; i++)
        sum[i] = sum[i-1]+times[i];
    ll ans = 0x7fffffffffffffffll;
    for(int i = 1; i <= n; i++){
        ll tmp = i*times[i] - sum[i];   //前面的钟拨到time(i)
        tmp += (tmod+times[i])*(n-i)-sum[n]+sum[i];//后面的钟拨到time(i)
        ans = min(ans,tmp);
    }

    int ansH,ansM,ansS;
    ansH = ans/Fac; ans -= ansH*Fac;
    ansM = (ans/mmod); ans -= ansM*mmod;
    ansS = ans;
    printf("%d %d %d",ansH,ansM,ansS);
    return 0;
}
时间: 2025-01-03 10:21:19

CF Gym 100637A Nano alarm-clocks的相关文章

Gym - 100637A Nano alarm-clocks 模拟

题意:有n个时钟,只能顺时针拨,问使所有时间相同的最小代价是多少 思路:将时间排序,枚举拨动到每一个点的时间就好了,容易证明最终时间一定是其中之一 1 #include <iostream> 2 #include <cstdio> 3 #include <fstream> 4 #include <algorithm> 5 #include <cmath> 6 #include <deque> 7 #include <vector

CF gym 101933 K King&#39;s Colors —— 二项式反演

题目:http://codeforces.com/gym/101933/problem/K 其实每个点的颜色只要和父亲不一样即可: 所以至多 i 种颜色就是 \( i * (i-1)^{n-1} \),设为 \( f(i) \),设恰好 i 种颜色为 \( g(i) \) 那么 \( f(i) = \sum\limits_{j=0}^{i} C_{i}^{j} * g(j) \) 二项式反演得到 \( g(i) = \sum\limits_{j=0}^{k} (-1)^{k-j} * C_{k}

Codeforces Gym 100637A A. Nano alarm-clocks 前缀和处理

A. Nano alarm-clocks Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100637/problem/A Description An old watchmaker has n stopped nano alarm-clocks numbered with integers from 1 to n. Nano alarm-clocks count time in hours, and

Codeforces Gym 100637A A. Nano alarm-clocks 前缀和

A. Nano alarm-clocks Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100637/problem/A Description An old watchmaker has n stopped nano alarm-clocks numbered with integers from 1 to n. Nano alarm-clocks count time in hours, and

CF Gym 101955G Best ACMer Solves the Hardest Problem

链接:https://codeforces.com/gym/101955/problem/G 题意:在二维平面上四种操作: 1,加一个带权的点: 2,删去一个点: 3,给一个点周围欧几里得距离为sqrt(k)的存在的点点权都加w: 4,查询一个到点欧几里得距离为sqrtk的点权和. x, y<6000, k<1e7, sigma(询问次数)<1e6,time:12s 题解:原本以为是数据结构,发现距离为k的x,y其实不多,直接存vector<pii>dis[maxk]暴力即可

CF Gym 102059E Electronic Circuit (set存图删点)

链接:https://codeforces.com/gym/102059/problem/E 题意:n个点, m条线,问这个电路是否合法,合法:可以确定一个起点和一个终点. 题解:不断的删点,删除度数为2的点,再相连,看最终度数为1的点的个数是否为2.set存图 #include <bits/stdc++.h> using namespace std; const int maxn=3e5+5; set<int> S[maxn]; int n, m; void del_edge()

cf Gym 101086M ACPC Headquarters : AASTMT (Stairway to Heaven)

题目: Description standard input/output As most of you know, the Arab Academy for Science and Technology and Maritime Transport in Alexandria, Egypt, hosts the ACPC Headquarters in the Regional Informatics Center (RIC), and it has been supporting our r

cf gym 100960 G. Youngling Tournament set+树状数组

G. Youngling Tournament time limit per test 2 seconds memory limit per test 256 mebibytes input standard input output standard output Yoda, the Grand Master of the Jedi Order, hit on the idea to hold a tournament among younglings. He has not chosen t

CF Gym 100187A Potion of Immortality

根据兔子试药情况可以缩小范围,如果死了,不在试过的药里面,如果活着,在试过的药里. 最糟的情况: 两个原则 1.能确定药所在的范围的尽量大,2.死得兔子尽量多. 如果当前不知道情况的药n为k的二倍以上,那么基于上面两个原则,试过药的兔子肯定会死. 没死:范围k,损失的兔子0 死了:范围n-k,损失的兔子1 (n>2*k) 设r=n%k,经过上述过程,损失了n/k-1只兔子,转移到了当前状态范围w = k+r, 1.r == 0 那么可以补充一个毒药,变成w=k+1,根据鸽巢原理再死一个就可以确定