Codeforces Round #320 (Div. 1) [Bayan Thanks-round] a problem about Polyline

Source: Internet
Author: User
Tags polyline

The functions given in the topic are periodic, can always be moved to the first period, of course, a<b is no solution.

Assuming that the ascending segment is moved, then there is a-2*x*n=b, and note that the limiting condition X≥b,n is an integer, then n≤ (A-B)/(2*B). X≥ (A-B)/(2*N) satisfying the condition

Assumed in the descending segment, 2*x-(a-2*x*n) =b,n+1≤ (a+b)/(2*b), x≥ (a+b)/(n+1)

Take the minimum value of both

#include <bits/stdc++.h>using namespacestd;intMain () {intb; scanf"%d%d",&a,&b); if(A<b) puts ("-1"); Else {        intT1 = a+b, t2 = A-b; intN1 = t1/(2*B) *2, N2 = t2/(2*B) *2; DoubleA1 = T1*1./n1, a2 = t2*1./N2; printf ("%.10lf\n", Min (a1,a2)); }    return 0;}

Codeforces Round #320 (Div. 1) [Bayan Thanks-round] a problem about Polyline

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.