The Ninja Turtles often battle the Foot Clan ninjas. The Turtles
celebrate each victory with a pizza party. The amount of pizza they
eat depends on the number of opponents they have defeated. Denote
the number of defeated opponents as N. Three of the four Turtles
have a moderate appetite and only consume floor(N / K) pizzas
each. The fourth Turtle is always hungry and eats floor(N / 3)
pizzas.
|
#include<iostream>
#include<cmath>
using namespace std;
class NinjaTurtles
{
public:
int countOpponents(int P , int K )
{
int x = 1;
int temp = 0 , temp1 = 0;
int y = (int)((3*K*P) / ( K + 3) );
cout<<y<<endl;
while( (x < K) || (x < 3))
{
temp = (int)floor(x/K);
temp1 = (int)floor(x/3);
temp = temp * 3;
if((temp + temp1) == P)
{
return x;
}
x++;
}
while(x <= y)
{
temp = (int)floor(x/K);
temp1 = (int)floor(x/3);
temp = temp * 3;
if((temp + temp1) == P)
{
return x;
}
x++;
}
return -1;
}
};
BY: SAURABH BHATIA
No comments:
Post a Comment