Codeforces 579 C. A Problem about Polyline(Codeforces Round #320 (Div. 2) )
来源:互联网 发布:matlab语言编程.pdf 编辑:程序博客网 时间:2024/05/01 02:14
C. A Problem about Polyline
time limit per test
1 secondmemory limit per test
256 megabytesinput
standard inputoutput
standard outputThere is a polyline going through points (0, 0) – (x, x) – (2x, 0) – (3x, x) – (4x, 0) – ... - (2kx, 0) – (2kx + x, x) – ....
We know that the polyline passes through the point (a, b). Find minimum positive value x such that it is true or determine that there is no such x.
Input
Only one line containing two positive integers a and b (1 ≤ a, b ≤ 109).
Output
Output the only line containing the answer. Your answer will be considered correct if its relative or absolute error doesn't exceed 10 - 9. If there is no such x then output - 1 as the answer.
Sample test(s)
input
3 1
output
1.000000000000
input
1 3
output
-1
input
4 1
output
1.250000000000
Note
You can see following graphs for sample 1 and sample 3.
/**2015 - 09 - 22 晚上Author: ITAKMotto:今日的我要超越昨日的我,明日的我要胜过今日的我,以创作出更好的代码为目标,不断地超越自己。**/#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>#include <vector>#include <queue>#include <algorithm>#include <set>using namespace std;typedef long long LL;typedef unsigned long long ULL;const int maxn = 1000;const int mod = 1e9+7;const double eps = 1e-7;struct node{ int x, y, node;} arr[maxn*maxn];bool cmp(node a, node b){ return a.node > b.node;}int main(){ int a, b; cin>>a>>b; int k = a/b; if(a < b) puts("-1"); else { if(k%2 == 1) k++; double ans = 1.0*(a+b)/(double)k; printf("%.10lf\n",ans); } return 0;}
0 0
- Codeforces Round #320 (Div. 2)C. A Problem about Polyline
- Codeforces Round #320 (Div. 2) C. A Problem about Polyline
- Codeforces Round #320 (Div. 2) C - A Problem about Polyline
- Codeforces Round #320 (Div. 2) C - A Problem about Polyline
- Codeforces Round #320 (Div. 2) C. A Problem about Polyline
- Codeforces 579 C. A Problem about Polyline(Codeforces Round #320 (Div. 2) )
- Codeforces Round #320 (Div. 2) 579C A Problem about Polyline(数学)
- Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] C. A Problem about Polyline 精度控制
- Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] C. A Problem about Polyline
- Codeforces Round #320 (Div. 1) A. A Problem about Polyline
- Codeforces Round #320 (Div. 2) 578A. A Problem about Polyline
- [CodeForces 579C]A Problem about Polyline[数学]
- CodeForces 579C A Problem about Polyline[数学]
- 【26.09%】【codeforces 579C】A Problem about Polyline
- codeforces 320c A Problem about Polyline(数学)
- cf#320 Div.2 Problem C A Problem about Polyline
- cf#320 Div.2 Problem C A Problem about Polyline
- Codeforces 579C A Problem about Polyline【数学啊】【好不擅长啊】
- Android 开发第二弹:通讯录
- eclipse:报错信息The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path
- 不同时间复杂度实现最大子段和
- System.arraycopy() vs. Arrays.copyOf() in Java
- 变参数的解决方法,使用stdarg中的VA宏
- Codeforces 579 C. A Problem about Polyline(Codeforces Round #320 (Div. 2) )
- 从尾到头打印链表
- Palindrome Partitioning II
- OpenGL通过读取Z Buffer深度值将屏幕2D坐标转化为场景3D坐标(含完整源码)
- python 基础
- iOS开发之UIActivityIndicatorView(二)
- 移动产品分析案例
- 冒泡排序及优化
- list初学