题目链接

题目

题目描述

Happy Running, an application for runners, is very popular in CHD.

In order to lose weight, fdf decides to run k meters per day with Happy Running. Let’s regard the school as a circular runway with total length of x meters, and fdf could start running clockwise at a random point on the runway. Then Happy Running will randomly show two punching-card points (打卡点). Because of the poor physical strength, fdf decides to finish running only by completing the punch, whether or not complete the goal of k meters.

One day, before running, fdf wants to know whether he can achieve the goal today, and he asks you to help him to calculate the probability of completing the goal running k meters.

Note that, fdf should punch card one by one which means that he will punch card at the first point before the second, even if he reaches the second point first.

It is guaranteed that punching-card points and the point fdf starts running will appears randomly with equal probability and the three points won’t be coincide.

输入描述

The first line contains an integer number T, the number of test cases.

ith of each next T lines contains two integer numbers k,x(1 ≤ k,x ≤ 10^9).

输出描述

For each test case print the probability of completing the goal, round to two decimal places.

示例1

输入

  1. 3
  2. 2 2
  3. 4 3
  4. 2 1

输出

  1. 0.50
  2. 0.22
  3. 0.00

题解

知识点:概率论。

考虑固定起点,因为起点在哪都一样,只需要考虑 \(a,b\) 的相对位置。接下来,利用几何概型分类讨论:

  1. 当 \(k\leq x\) 时,概率为 \(1- \dfrac{k^2}{2x^2}\) 。
  2. 当 \(x < k \leq 2x\) 时,概率为 \(\dfrac{(2x-k)^2}{2x^2}\) 。
  3. 当 \(2x < k\) 时,概率为 \(0\) 。

时间复杂度 \(O(1)\)

空间复杂度 \(O(1)\)

代码

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. using ll = long long;
  4. bool solve() {
  5. int k, x;
  6. cin >> k >> x;
  7. if (k <= x) cout << fixed << setprecision(2) << 1 - (long double)k * k / 2 / x / x << '\n';
  8. else if (k <= 2 * x) cout << fixed << setprecision(2) << (long double)(2 * x - k) * (2 * x - k) / 2 / x / x << '\n';
  9. else cout << fixed << setprecision(2) << 0 << '\n';
  10. return true;
  11. }
  12. int main() {
  13. std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  14. int t = 1;
  15. cin >> t;
  16. while (t--) {
  17. if (!solve()) cout << -1 << '\n';
  18. }
  19. return 0;
  20. }

NC15532 Happy Running的更多相关文章

  1. Crystal Clear Applied: The Seven Properties of Running an Agile Project (转载)

    作者Alistair Cockburn, Crystal Clear的7个成功要素,写得挺好. 敏捷方法的关注点,大家可以参考,太激动所以转载了. 原文:http://www.informit.com ...

  2. Running Dubbo On Spring Boot

    Dubbo(http://dubbo.io/) 是阿里的开源的一款分布式服务框架.而Spring Boot则是Spring社区这两年致力于打造的简化Java配置的微服务框架. 利用他们各自优势,配置到 ...

  3. Android PopupWindow Dialog 关于 is your activity running 崩溃详解

    Android PopupWindow Dialog 关于 is your activity running 崩溃详解 [TOC] 起因 对于 PopupWindow Dialog 需要 Activi ...

  4. IntelliJ运行下载的Servlet时报错 Error running Tomcat 8.5.8: Unable to open debugger port (127.0.0.1:49551): java.net.SocketException

    学习Java Servlet时,从Wrox上下载了示例代码,准备run/debug时发现以下错误: Error running Tomcat 8.5.8: Unable to open debugge ...

  5. teamviewer "TeamViewer Daemon is not running

    执行下面的命令问题解决: # teamviewer --daemon enable enable Sat Jan :: CST Action: Installing daemon () for 'up ...

  6. mysql 有报错  ERROR! MySQL is not running, but lock file (/var/lock/subsys/mysql) exists

    sh-4.1# /etc/init.d/mysqld status ERROR! MySQL is not running, but lock file (/var/lock/subsys/mysql ...

  7. Errors occurred during the build. Errors running builder 'JavaScript Validator' on project

    1.问题:Errors occurred during the build. Errors running builder 'JavaScript Validator' on project 2.解决 ...

  8. The network bridge on device VMnet0 is not running

    The network bridge on device VMnet0 is not running. The virtual machine will not be able to communic ...

  9. ERROR! MySQL is running but PID file could not be found

    /etc/init.d/mysql status提示ERROR! MySQL is running but PID file could not be found先打印MYSQL进程ps aux | ...

  10. 问题解决:psql: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

    错误提示: psql: could not connect to server: No such file or directory Is the server running locally and ...

随机推荐

  1. NewStarCTF 2023 公开赛道 WEEK5|CRYPTO WP

    last_signin from Crypto.Util.number import * flag = b'?' e = 65537 p, q = getPrime(1024), getPrime(1 ...

  2. Shell-表达式-比较-文件判断-权限判断-条件-逻辑

  3. [转帖]MySQL联合索引(复合索引)

    Mysql联合唯一索引添加相同数据插入报错 联合索引在两个字段都存在唯一,将报错. 1.添加联合索引 alter table "表名" add unique index(`字段1` ...

  4. [转帖]TiDB 6.1 单机环境 On openEular 2003 SP3

    https://tidb.net/book/book-rush/best-practice/other-practice/tidb61-on-openEular2003 背景​ 最近对国产操作系统很感 ...

  5. [转帖]Tail Latency学习

    https://www.cnblogs.com/Rohn/p/15123758.html Latency,中文译作延迟,Tail Latency即尾延迟. 实际生产中的Latency是一种(概率)分布 ...

  6. 解锁前端新潜能:如何使用 Rust 锈化前端工具链

    ​ 前言 近年来,Rust的受欢迎程度不断上升.首先,在操作系统领域,Rust 已成为 Linux 内核官方认可的开发语言之一,Windows 也宣布将使用 Rust 来重写内核,并重写部分驱动程序. ...

  7. 华为云DTSE携手“灵康宜”构造一站式智慧健康检测云平台

    本文分享自华为云社区<华为云DTSE携手"灵康宜"构造一站式智慧健康检测云平台>,作者: HuaweiCloudDeveloper. 打破传统健康监测方式桎梏--非接触 ...

  8. 【分享一个工具】根据 /metrics 路径下的文本信息,自动生成包含所有 metrics 的 grafana 报表

    作者:张富春(ahfuzhang),转载时请注明作者和引用链接,谢谢! cnblogs博客 zhihu Github 公众号:一本正经的瞎扯 在做某个服务对应的 grafana 监控报表的时候发现,一 ...

  9. 【笔记】macbook m2 芯片中使用 gcc docker 镜像来交叉编译

    作者:张富春(ahfuzhang),转载时请注明作者和引用链接,谢谢! cnblogs博客 zhihu Github 公众号:一本正经的瞎扯 一个 c 程序,如何在 macbook m2 芯片的笔记本 ...

  10. SqlSugar导航查询/多级查询

    1.导航查询特点 作用:主要处理主对象里面有子对象这种层级关系查询 1.1 无外键开箱就用 其它ORM导航查询 需要 各种配置或者外键,而SqlSugar则开箱就用,无外键,只需配置特性和主键就能使用 ...