PROBLEM LINK: Disc Tower | CodeChef
Problem Code: Disc Tower | CodeChef
Practise: CodeChef | Competitive Programming | Participate & Learn | CodeChef
Contest : Campus Code October Edition Coding Competition | CodeChef
Author: Codechef Adgitm Chapter : https://www.codechef.com/users/test_account_9
Tester: Codechef Adgitm Chapter : https://www.codechef.com/users/test_account_9
Editorialist: Codechef Adgitm Chapter : https://www.codechef.com/users/test_account_9
DIFFICULTY:
Medium
PROBLEM:
There are many towers made up of circular discs of height 1 unit. You can think of discs as Circles. (consider the top view).
Tower’s description:
- A tower is made up of discs stacked on top of each other (from top view it will look like circles inside of circles).
- Each disc can only have one disc directly on top (the tower has only one peak).
- The disc on top is completely inside the bottom disc ( no circles intersect each other).
- The disc on top must be smaller than the bottom disc.
The discs are placed in a 2D - coordinate plane. You are given the center position and radius of each disc.
Find the height of the tallest tower.
EXPLANATION:
find height of tallest tower according to the conditions given.
SOLUTION:
C++:
#include<bits/stdc++.h>
using namespace std;
#define loop(i,l,h) for(int i=l;i<h;i++)
#define endl “\n”
typedef long long int ll;
typedef long double ld;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t=0;
do{
int n;cin>>n;
int arr[3][n];
for(int i=0;i<n;i++){
int x,y,r;cin>>x>>y>>r;
arr[0][i]=x;
arr[1][i]=y;
arr[2][i]=r;
}
int res=1;
for(int i=0;i<n;i++){
int tmp=1;
for(int j=0;j<n;j++){
int x=0;
if(i !=j){
if((arr[0][i]+arr[2][i]) > (arr[0][j]+arr[2][j]) && (arr[0][i]-arr[2][i]) < (arr[0][j]-arr[2][j]) ){
x++;
}
if((arr[1][i]+arr[2][i]) > (arr[1][j]+arr[2][j]) && (arr[1][i]-arr[2][i]) < (arr[1][j]-arr[2][j])){
x++;
}
}
if(x==2)tmp++;
}
res=max(tmp,res);
}
cout<<res<<endl;
}while(t--);
return 0;
}