当前位置: 首页 > ops >正文

CCPC dongbei 2025 F

题目链接:https://codeforces.com/gym/105924
题目背景:

        给出一个时间区间和当前时间,在时间区间内选择一个时间使得该时间与当前时间的时针夹角与分针夹角之和最小。

思路:

       暴力枚举区间内的所有时间,计算与当前时间夹角的度数即可。

        注:由于时针上的一分钟为0.5度,需要取浮点数,可以将一圈定义为720度,这样一分钟就为1度。

数据范围:

        T <= 1e4。

时间复杂度:

        O(720T)

ac代码: 
#include <bits/stdc++.h>#define ioscc ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define endl '\n'
#define me(a, x) memset(a, x, sizeof a)
#define all(a) a.begin(), a.end()
#define sz(a) ((int)(a).size())
#define pb(a) push_back(a)
using namespace std;typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<bool> vb;const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
const int MAX = (1ll << 31) - 1;
const int MIN = 1 << 31;
const int MOD = 1e9 + 7;
const int N = 1e5 + 10;template <class T>
ostream &operator<<(ostream &os, const vector<T> &a) noexcept
{for (int i = 0; i < sz(a) - 10; i++)std::cout << a[i] << ' ';return os;
}template <class T>
istream &operator>>(istream &in, vector<T> &a) noexcept
{for (int i = 0; i < sz(a) - 10; i++)std::cin >> a[i];return in;
}/* ----------------- 有乘就强转,前缀和开ll ----------------- */void solve()
{int x0, y0, x1, y1, x2, y2;cin >> x0 >> y0 >> x1 >> y1 >> x2 >> y2;auto cost = [&](int a, int b) -> int{return min(abs(a - b), 720 - abs(a - b));};ll minn = MAX;ll ans1 = MIN, ans2 = MIN;int dh0 = x0 * 60 + y0;int dm0 = y0 * 12;int l = x1 * 60 + y1;int r = x2 * 60 + y2;for (int i = l; i <= r; ++i){int h = i / 60;int m = i % 60;int dh1 = h * 60 + m;int dm1 = m * 12;ll cnt = cost(dh0, dh1) + cost(dm0, dm1);if (cnt < minn || (cnt == minn && (h < ans1 || (h == ans1 && m < ans2)))){minn = cnt;ans1 = h;ans2 = m;}}cout << ans1 << ' ' << ans2 << endl;
}int main()
{ioscc;int T;cin >> T;while (T--)solve();return 0;
}

http://www.xdnf.cn/news/10365.html

相关文章:

  • 组件化:软件工程化的基础
  • 接口安全SOAPOpenAPIRESTful分类特征导入项目联动检测
  • 树莓派3B小练习
  • IT技术文章汇总
  • 美业+智能体,解锁行业转化新密码(2/6)
  • 大白话 Seata 分布式事务浅析,详解TCC模式
  • 腾讯位置商业授权行政区划开发指南
  • Codeforces Round 1028 (Div. 2) B. Gellyfish and Baby‘s Breath
  • Nginx反向代理
  • NodeJS全栈开发面试题讲解——P12高性能场景题
  • Chorme如何对于youtube视频进行画中画背景播放?
  • 多模态AI的企业应用场景:视觉+语言模型的商业价值挖掘
  • 8天Python从入门到精通【itheima】-62~63
  • 结合源码分析Redis的内存回收和内存淘汰机制,LRU和LFU是如何进行计算的?
  • 深度学习|pytorch基本运算-乘除法和幂运算
  • 初识PS(Photoshop)
  • 【Oracle】安装单实例
  • 【Go】2、Go语言实战
  • python打卡day42@浙大疏锦行
  • 动态库导出符号与extern “C“
  • 2025年05月总结及随笔之家电询价及以旧换新
  • 剪枝中的 `break` 与 `return` 区别详解
  • APM32主控键盘全功能开发实战教程:软件部分
  • 【论文解读】Deformable DETR | Deformable Transformers for End-to-End Object Detection
  • 题单:最大公约数(辗转相除法)
  • 安全漏洞修复导致SpringBoot2.7与Springfox不兼容
  • 爬虫工具链的详细分类解析
  • 力扣刷题Day 66:分割回文串(131)
  • 【Redis】数据类型补充
  • t018-高校宣讲会管理系统 【含源码!】