51C - Three Base Stations - CodeForces Solution


binary search greedy *1800

Please click on ads to support us..

C++ Code:

//" إنّ إله السّماء يعطينا النّجاح، ونحن عبيده نقوم ونبني" (سفر نحميا 20:2)
#include <bits/stdc++.h>

#define ll long long
using namespace std;
const int N = 2e5 + 5;
const ll mod = 1e9 + 7;
#define el "\n"
#define _3en_7oras_ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

void do_it()
{


    int n;
    cin>>n;
    int a[n];
    for(int i = 0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    double s = 0,e = 1e9,mid,ret;
    vector<double> ans;
    while(e-s>1e-7)
    {
        mid = (s+e)/2;
        double last = a[0] + mid ;
        int cnt = 1;
        vector<double> temp;
        temp.push_back(last);
        for(int i = 1;i<n;i++)
        {
            if(abs(a[i]-last)-1e-7>mid)
            {
                last = a[i] + mid;
                temp.push_back(last);
                cnt++;
            }
        }
        if(cnt<=3)
        {
            ret = mid ;
            e = mid - 1e-8;
            ans = temp;;

        }
        else s = mid + 1e-8;

    }
    while(ans.size()<3)
        ans.push_back(1);
    cout<<fixed<<setprecision(6)<<ret<<el;
    for(auto j:ans)
        cout<<j<<" ";


}

int main()
{

    _3en_7oras_
    int T = 1;
  //  cin >> T;
    for (int i = 1; i <= T; i++)
        do_it();


    return 0;
}

 	 	  	 	  		 		 						 		  	 	


Comments

Submit
0 Comments
More Questions

Cost of balloons
One String No Trouble
Help Jarvis!
Lift queries
Goki and his breakup
Ali and Helping innocent people
Book of Potion making
Duration
Birthday Party
e-maze-in
Bricks Game
Char Sum
Two Strings
Anagrams
Prime Number
Lexical Sorting Reloaded
1514A - Perfectly Imperfect Array
580A- Kefa and First Steps
1472B- Fair Division
996A - Hit the Lottery
MSNSADM1 Football
MATCHES Playing with Matches
HRDSEQ Hard Sequence
DRCHEF Doctor Chef
559. Maximum Depth of N-ary Tree
821. Shortest Distance to a Character
1441. Build an Array With Stack Operations
1356. Sort Integers by The Number of 1 Bits
922. Sort Array By Parity II
344. Reverse String