The Yellow Brick Road
Link to the question : YELBRICK
HINTS :
Very simple ad-hoc question. Just find the gcd of the length, breadth and height of the stones, and then find the number of stones that can be produced.
RECOMMENDED QUESTION :
Try solving this question as even this requires some application of gcd.
SOURCE CODE :
#include <iostream>
using namespace std;
int gcd(int x,int y)
{
while(x!=y){
if(x>y)
return gcd(x-y,y);
else
return gcd(x,y-x);
}
return x;
}
int main()
{
int n,i;
while(1)
{
cin>>n;
if(n==0)
break;
int a[n][3];
long long vol=0;
for(i=0;i<n;i++)
{
cin>>a[i][0]>>a[i][1]>>a[i][2];
}
int hcf =a[0][0];
for(i=0;i<n;i++)
{
hcf = gcd(hcf,a[i][0]);
hcf = gcd(hcf,a[i][1]);
hcf = gcd(hcf,a[i][2]);
}
for(i=0;i<n;i++)
{
vol+=(long long)((a[i][0]/hcf)*(a[i][1]/hcf)*(a[i][2]/hcf));
}
cout<<vol<<"\n";
}
return 0;
}
Sir can you tell me the meaning of ad-hoc ? Very nice solution sir :)
ReplyDeleteThis comment has been removed by the author.
ReplyDelete