题目链接

题目

题目描述

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

输入

3
2 2
4 3
2 1

输出

0.50
0.22
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)\)

代码

#include <bits/stdc++.h>
using namespace std;
using ll = long long; bool solve() {
int k, x;
cin >> k >> x;
if (k <= x) cout << fixed << setprecision(2) << 1 - (long double)k * k / 2 / x / x << '\n';
else if (k <= 2 * x) cout << fixed << setprecision(2) << (long double)(2 * x - k) * (2 * x - k) / 2 / x / x << '\n';
else cout << fixed << setprecision(2) << 0 << '\n';
return true;
} int main() {
std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while (t--) {
if (!solve()) cout << -1 << '\n';
}
return 0;
}

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. 玩转 Helm 之 upgrade

    0. 前言 在 玩转 Helm 一文中,简略提到了 Helm upgrade 的策略. 在实际项目开发上,upgrade 多是调研的重点.基于此,这里对 upgrade 继续展开. 1. basic ...

  2. Cortex-M3 MCU的技术特点

    1.Cortex-M3 MCU的技术特点 MCU简单来说就是一个可编程的中央处理器(CPU)加上一些必要的外设.不管是中央处理器还是整个MCU都是复杂的时序数字电路,根据程序或者指令来完成特定的任务. ...

  3. 电子科技大学--ARM实验Keil uvison5 安装以及S3C2440A芯片包下载

    1.简介 本教程主要服务于电子科技大学软工嵌入式新生,节省一些查找资料的时间 2.过程 请按如下顺序安装: 1,安装mdk_514.exe (主体文件) 2,安装Keil.STM32F1xx_DFP. ...

  4. C++封装数据结构

    1.概论 C++ STL 之所以得到广泛的赞誉,也被很多人使用,不只是提供了像vector, string, list等方便的容器,更重要的是STL封装了许多复杂的数据结构算法和大量常用数据结构操作. ...

  5. 媒体查询常用 - 移动端和PC端尺寸

    /* 移动端 */ @media all and (max-width: 768px) { } /* PC端 */ @media all and (min-width: 769px) { }

  6. JS - 兼容到 IE 8

    使用 jQuery可以有效的兼容IE 浏览器 , 但jQuery从2.0开始不兼容IE8,最低支持IE9,所以需要引入更低的jQuery版本来兼容 <script type="text ...

  7. 00.Oracle 11g安装

    通过Docker安装Oracle 1.搜索镜像 先使用指令搜素远程仓库中的Oracle镜像 sudo docker search docker-oracle-xe-11g 2.拉取镜像 选择一个sta ...

  8. Matplotlib.pyplot.scatter 散点图绘制

    Matplotlib.pyplot.plot 绘图 matplotlib.pyplot.scatter(x, y, s=None, c=None, marker=None, cmap=None, no ...

  9. [转帖]金仓数据库KingbaseES表空间(tablespace)知多少

    金仓数据库KingbaseES表空间定义 金仓数据库KingbaseES中的表空间允许在文件系统里定义那些代表数据库对象的文件存放位置,比如表和索引等.一旦表空间被创建,那么就可以在创建数据库对象时通 ...

  10. [转帖]《Linux性能优化实战》笔记(24)—— 动态追踪 DTrace

    使用 perf 对系统内核线程进行分析时,内核线程依然还在正常运行中,所以这种方法也被称为动态追踪技术.动态追踪技术通过探针机制来采集内核或者应用程序的运行信息,从而可以不用修改内核和应用程序的代码就 ...