PPR - Pizza Prize Spoj solution or Editorial - UCS - Unleash-Coding-Skills

Tuesday, 26 June 2018

PPR - Pizza Prize Spoj solution or Editorial - UCS





PPR - Pizza Prize Editorial SPOJ

The link to the problem is: 

https://www.spoj.com/problems/PPR/ 


 The solution is staring farward this is form of series in which it will expand as follows.
 Initial = 5
2*5 =10+5(previous sum)
2*10 = 20 + 15(previous sum)
2*20 = 40 + 35(previous sum)

The series start again with "Asad" at points 1,6,16,36  the series get expanded as every new entry set will be doubled as mentioned in question and it will be added in the queue end.

Note: The input must be read until the end.The test cases count is not given in input.

The CPP solution for PPR - Pizza Prize is:


#include <iostream>
using namespace std;

int main()
{
    long long int n,i,j,k;
    while(cin>>n)
    {
        long long r=5,li;
        long long m=1;
        int l=1;
        if(r<5)
        {
            li=n;   
        }
        else{
        while(r<n)
        {
            m=m*2;
            l=0;
            r+=5*m;
        }
        r=r-5*m;
        long long p= n-r;
        li = p/m;
        if(li*m-p<0)
        {
            li++;
        }
        }
       if(li==1)
       {
        cout<<"Asad"<<endl;
        }
        else if(li==2)
            cout<<"Foyj"<<endl;
        else if(li==3)
        {
            cout<<"Juwel"<<endl;
        }
        else if(li==4)
        {
            cout<<"Mijan"<<endl;
        }
        else
        {
            cout<<"Tanmay"<<endl;
        }
    }
    return 0;
}


Happy Coding.......


Tags:
PPR,PPR SPOJ,PPR - Pizza,PPR - Pizza SPOJ,ppr,ppr spoj,ppr - pizza,ppr - pizza spoj,ppr pizza spoj,PPR editorial spoj,PPR SPOJ editorial,Brute force,adhoc solution,ppr pizz cpp solution,ppr pizza C++ solution,editorial spoj,spoj ppr editorial,ppr spoj solution,PPR SPOJ,PPR -Pizza solution spoj.

No comments:

Post a comment