1011C Codeforces - Fly


1011C Codeforces - Fly






Solution in C++


#include <bits/stdc++.h>

using namespace std;

#define pii pair<int,int>
typedef long long int lli;

int n;
double m;
double fuel,acc;
int pla,sta,lol;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n>>m;
    int nn[n],mm[n];
    for(int i=0;i<n;i++)cin>>nn[i];
    for(int i=0;i<n;i++)cin>>mm[i];
    while(1)
    {
        if(pla==0)lol++;
        if(lol==3)break;
        if(sta==0)
        {
            fuel+=(m+acc)/((mm[pla]-1) );
            acc=fuel;
            sta=1;
            if(pla==0)pla=n-1;
            else pla--;
        }
        else
        {
            fuel+=(m+acc)/((nn[pla]-1) );
            acc=fuel;
            sta=0;
        }

    }
    if(fuel==INFINITY)cout<<-1;
    else
     cout<<fixed<<setprecision(10)<<fuel<<"\n";

    return 0;
}
Share on Google Plus

About Mohamed Sobhi

My name is Mo.Sobhy ,I study at School excelling high school in Ain Shams ,Cairo
My hobbies is programming ,and web development ,playing chess and writing horror stories.
    Blogger Comment
    Facebook Comment

0 التعليقات:

إرسال تعليق