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

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;
}

相关文章:

  • 神经网络-Day42
  • 针对 Harmony-Cordova 性能优化,涵盖原生插件开发、线程管理和资源加载等关键场景
  • Codeforces Round 1028 (Div. 2)(ABC)
  • MMRL: Multi-Modal Representation Learning for Vision-Language Models(多模态表示学习)
  • 【MFC】初识MFC
  • Redis缓存落地总结
  • 2025年计算机领域年度主题:融合创新与技术突破
  • 如何使用 Docker 部署grafana和loki收集vllm日志?
  • Flask文件处理全攻略:安全上传下载与异常处理实战
  • 使用Docker-NVIDIA-GPU开发配置:解决 Docker NVIDIA 运行时错误方法
  • 基于微信小程序的scratch学习系统
  • Redis分布式锁实现指南
  • 软考-数据库系统工程师-程序设计语言知识要点
  • 【Go】2、Go语言实战
  • Rust 学习笔记:自定义构建和发布配置
  • AUTOSAR图解==>AUTOSAR_SWS_DIODriver
  • 【渲染】拆解三国:谋定天下场景渲染技术
  • linux 后记
  • GCC 下载安装
  • DAY18C语言笔记
  • 中国免费素材网站/搜索引擎有哪些网站
  • 工程建设标准最新查询网站/搜狗网站收录入口
  • vue 做电商网站/怎么在百度上发布信息
  • 怎么在ps做网站首页/google推广专员招聘
  • 忒低网站长怎么做/成都seo优化排名公司
  • 手机网站复制功能实现/成都seo优化