In this problem we need to just find a equation,
a equation called conic frustrum volume:
V = (pi*h /3) *(R*R + R*r + r*r)
code(c++):
/*
Author : Mohammad Morsalin Hossain
Dept of ICE,NSTU
*/
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define ms(x) memset(x,0,sizeof(x))
#define ins insert
#define pi acos(-1)
#define IOS ios::sync_with_stdio(false);
using namespace std;
int main()
{
IOS
int test,to=0;
cin>>test;
while(test--)
{
int r1,r2,h,p;
cin>>r1>>r2>>h>>p;
double pr= r2 +(r1-r2)*((double)p/h);
double v;
v = (pi*p)*(((double)pr*(double)pr)+((double)pr*(double)r2)+((double)r2*(double)r2))/3.0;
printf("Case %d: %lf\n",++to,v);
}
return 0;
}
This site solely purposed on personal improvement. Consists my concepts and idea of several problem from well known online judges like LightOj, Leetcode, Codeforces, UVA, SPOJ etc.
Tuesday, 16 April 2019
Juice in the Glass LightOj 1216
Intersection of Cubes LightOj 1211
To calculate intersection volume of n cubes, we need to find maximum value of first corner coordinates (x1,y1,z1) and minimum value of another corner coordinates(x2,y2,z2). There will be intersection between these cubes if and only if the difference between (x2-x1),(y2-y1),(z2-z1) is positive.
Code(c++):
/*
Author : Mohammad Morsalin Hossain
Dept of ICE,NSTU
*/
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define ms(x) memset(x,0,sizeof(x))
#define ins insert
#define IOS ios::sync_with_stdio(false);
using namespace std;
int main()
{
IOS
int test,tc=0;
cin>>test;
while(test--)
{
int n,a=0,b=0,c=0,d=INT_MAX,e=INT_MAX,f=INT_MAX;
cin>>n;
for(int i = 0;i<n;i++)
{
int x1,y1,z1,x2,y2,z2;
cin>>x1>>y1>>z1>>x2>>y2>>z2;
a = max(a,x1);
b = max(b,y1);
c = max(c,z1);
d = min(d,x2);
e = min(e,y2);
f = min(f,z2);
}
if(d>a && e>b && f>c)
{
ll res = (d-a)*(e-b)*(f-c);
cout << "Case "<< ++tc<< ": "<<res <<endl;
}
else
cout << "Case "<< ++tc <<": 0\n";
}
return 0;
}
Code(c++):
/*
Author : Mohammad Morsalin Hossain
Dept of ICE,NSTU
*/
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define ms(x) memset(x,0,sizeof(x))
#define ins insert
#define IOS ios::sync_with_stdio(false);
using namespace std;
int main()
{
IOS
int test,tc=0;
cin>>test;
while(test--)
{
int n,a=0,b=0,c=0,d=INT_MAX,e=INT_MAX,f=INT_MAX;
cin>>n;
for(int i = 0;i<n;i++)
{
int x1,y1,z1,x2,y2,z2;
cin>>x1>>y1>>z1>>x2>>y2>>z2;
a = max(a,x1);
b = max(b,y1);
c = max(c,z1);
d = min(d,x2);
e = min(e,y2);
f = min(f,z2);
}
if(d>a && e>b && f>c)
{
ll res = (d-a)*(e-b)*(f-c);
cout << "Case "<< ++tc<< ": "<<res <<endl;
}
else
cout << "Case "<< ++tc <<": 0\n";
}
return 0;
}
Sunday, 14 April 2019
Bishops LightOj 1202
In this problem you just have to find out some conditions relevant to row and column differences.
One important thing is maximum move will be two(where one bishop can reach another but they are not in same diagonal)
so, you have to just find out conditions for each output(1,2 and impossible)
code:
/*
Author : Mohammad Morsalin Hossain
Dept of ICE,NSTU
*/
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define ms(x) memset(x,0,sizeof(x))
#define ins insert
#define IOS ios::sync_with_stdio(false);
using namespace std;
int main()
{
IOS
int test;
cin>>test;
int to=0;
while(test--)
{
int row1,col1,row2,col2;
cin>>row1>>col1>>row2>>col2;
if((row1+col2 == row2+col1)||(abs(row1-row2)==abs(col1-col2)))
cout << "Case "<<++to<<": 1\n";
else if((row1+col2)==abs(row2-col1)||(abs(row1-col2)==row2+col1)||(row1+row2)%2==(col1+col2)%2)
cout << "Case "<<++to<<": 2\n";
else
cout <<"Case "<<++to<<": impossible\n";
}
return 0;
}
One important thing is maximum move will be two(where one bishop can reach another but they are not in same diagonal)
so, you have to just find out conditions for each output(1,2 and impossible)
code:
/*
Author : Mohammad Morsalin Hossain
Dept of ICE,NSTU
*/
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define ms(x) memset(x,0,sizeof(x))
#define ins insert
#define IOS ios::sync_with_stdio(false);
using namespace std;
int main()
{
IOS
int test;
cin>>test;
int to=0;
while(test--)
{
int row1,col1,row2,col2;
cin>>row1>>col1>>row2>>col2;
if((row1+col2 == row2+col1)||(abs(row1-row2)==abs(col1-col2)))
cout << "Case "<<++to<<": 1\n";
else if((row1+col2)==abs(row2-col1)||(abs(row1-col2)==row2+col1)||(row1+row2)%2==(col1+col2)%2)
cout << "Case "<<++to<<": 2\n";
else
cout <<"Case "<<++to<<": impossible\n";
}
return 0;
}
Subscribe to:
Posts (Atom)
Monkey Banana Problem lightoj 1004
In this problem we will check which adjacent cell will benefits the monkey best. For this, we will check all possible solution of this pro...
-
Problem link In this problem you will be given two integer number a and b. You need to make a and b equal in exactly k operation(s). In one...
-
In this problem we will check which adjacent cell will benefits the monkey best. For this, we will check all possible solution of this pro...