Pages

Tuesday, 13 January 2015

spoj solution of Break the Chocolate problem BC

 solution of Break the Chocolate problem


#include<iostream>
#include<cmath>
int knife(int);
using namespace std;
int main()
{
  long long int l,w,h,t,s1,s2,j;
  cin>>t;
  j=1;
  while(t--)
  {
  cin>>l>>w>>h;
  s1=(l*w-1)+(l*w*(h-1));
  s2=knife(l)+knife(w)+knife(h);
  cout<<"Case"<<" "<<"#"<<j<<":"<<" "<<s1<<" "<<s2<<endl;
  j++;
  }
  return 0;
}
int knife( int s)
{
int i;
i=0;
while(1)
{
if(s<=pow(2,i))
break;
else
i++;
}
return i;

}

No comments:

Post a Comment