Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] A A Problem about Polyline

题目中给出的函数具有周期性,总可以移动到第一个周期内,当然,a<b则无解。

假设移动后在上升的那段,则有a-2*x*n=b,注意限制条件x≥b,n是整数,则n≤(a-b)/(2*b)。满足条件的x≥(a-b)/(2*n)

假设在下降的那段,2*x-(a-2*x*n)=b,n+1≤(a+b)/(2*b),x≥(a+b)/(2*(n+1))

两者取最小值

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int a,b; scanf("%d%d",&a,&b);
    if(a<b) puts("-1");
    else {
        int t1 = a+b, t2 = a-b;
        int n1 = t1/(2*b)*2, n2 = t2/(2*b)*2;
        double a1 = t1*1./n1, a2 = t2*1./n2;
        printf("%.10lf\n",min(a1,a2));
    }
    return 0;
}
时间: 2024-11-10 22:48:18

Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] A A Problem about Polyline的相关文章

Codeforces Round #320 (Div. 2) [Bayan Thanks-Round]

一部分题解,算是自己SB了 上午的TC 也是这样 写好了代码,却一直没注意细节,然后以为错了. 此处省100字,ps 貌似紫了,作为一个老菜鸡,终于紫了 A,B 都是语文题 C: 给以一个三角形一样的图,判断点(a,b)是否在图中,我是这样判断的: 前一半是k*2*x+b=a;求最小的x,这里二分,但是注意k=0,所以你特判掉: 后一半是:2*(k+1)=a+b;二分类似 D:坐等官方题解,不靠谱系列:我试了很多方法: 做法:只可能是一个数*x^k: 之前以为是最大数*x^k ,但是错的 想想:

Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] C A Weakness and Poorness

f(x)是个凹函数,三分即可,计算方案的时候dp一下.挂精度很坑,指定循环次数正解? #include<bits/stdc++.h> using namespace std; const double eps = 1e-11; const int maxn = 2e5+5; double a[maxn]; double d1[maxn],d2[maxn]; int n; inline double cal(double x) { double a1 = 0., a2 = 0.; for(int

Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] B. Finding Team Member 排序

B. Finding Team Member time limit per test 2 seconds memory limit per test 256 megabytes There is a programing contest named SnakeUp, 2n people want to compete for it. In order to attend this contest, people need to form teams of exactly two people.

Codeforces Round #261 (Div. 2) D. Pashmak and Parmida&#39;s problem (树状数组求逆序数 变形)

题目链接 题意: 给出一些数a[n],求(i, j), i<j 的数量,使得:f(1, i, a[i]) > f(j, n, a[j]) . f(lhs, rhs, x) 指在 { [lhs, rhs]范围中,a[k]的值=x } 的数量. 1.  f(1, i, a[i]) 就是指a[i]前面包括a[i]的数中,有几个值=a[i]. 2.  f(j, n, a[j]) 就是指a[j]后面包括a[j]的数中有几个值=a[j]. 虽然a[x]范围不小,但是n的范围是1000,不是很大,所以我们可

Codeforces Round #261 (Div. 2)459D. Pashmak and Parmida&#39;s problem(求逆序数对)

题目链接:http://codeforces.com/contest/459/problem/D D. Pashmak and Parmida's problem time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Parmida is a clever girl and she wants to participate in O

Codeforces Round #261 (Div. 2) D. Pashmak and Parmida&#39;s problem (树状数组)

D. Pashmak and Parmida's problem time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Parmida is a clever girl and she wants to participate in Olympiads this year. Of course she wants her partn

Codeforces Round 261 Div.2 D Pashmak and Parmida&#39;s problem --树状数组

题意:给出数组A,定义f(l,r,x)为A[]的下标l到r之间,等于x的元素数.i和j符合f(1,i,a[i])>f(j,n,a[j]),求有多少对这样的(i,j). 解法:分别从左到右,由右到左预处理到某个下标为止有多少个数等于该下标,用map维护. 然后树状数组更新每个f(j,n,a[j]),预处理完毕,接下来,从左往右扫过去,每次从树状数组中删去a[i],因为i != j,i不能用作后面的统计,然后统计getsum(inc[a[i]]-1), (inc表示从左到右),即查询比此时的a[i]

[Codeforces] Round #320 (Div.2)

1.前言 虽然这次我依旧没有参加正式比赛,但是事后还是看了看题目的...一般不怎么刷Codeforces. A.Raising Bacteria You are a lover of bacteria. You want to raise some bacteria in a box. Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night

Codeforces Round #320 (Div. 2) &quot;Or&quot; Game(好题,贪心/位运算/前缀后缀或)

1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<iostream> 5 using namespace std; 6 typedef long long ll; 7 /* 8 n个数,你最多有k次操作,每次操作可以选择一个数乘以x,问所有数或(|)的最大值 9 贪心思路:选一个数进行k此乘以x操作; 因为x>=2 10 111 ---> 1111 11