Translate

Showing posts with label geometry. Show all posts
Showing posts with label geometry. Show all posts

Tuesday, 3 February 2015

TRICENTR(Triangle From Centroid) spoj problem solution

HII this is geometry based problem u can use simple formula
to solve this

here is my ac c++ soluiton is


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include<iostream>
#include<cmath>
#include<stdio.h>
#include<stdlib.h>
#include <iomanip>
using namespace std;

int main(){
    int n;
    long double a,b,c,ga,gb,gc,S,R,HG,s;
    cin>>n;
    cout<<fixed;
    for(int i=0;i<n;i++){
        cout<<setprecision(11);
        cin>>a>>ga>>gb>>gc;
        b=a*ga/gb;
        c=a*ga/gc;
        s=(a+b+c)/2;
        S=sqrt(s*(s-a)*(s-b)*(s-c));
        R=a*b*c/4/S;
        HG=2*(sqrt(9*R*R-a*a-b*b-c*c))/3;
        cout<<setprecision(3);
        cout<<S<<" "<<HG<<endl;
    }
    return 0;
}

STONE(Lifting the Stone) spoj problem soluiton

HII guys this is totally geometry based problem there is nothing to code just use formula 
 LOGIC::how to find centroid of a polygon u can this concept or formula given below

The centroid of a non-self-intersecting closed polygon defined by n vertices (x0,y0), (x1,y1), ..., (xn−1,yn−1) is the point (CxCy), where
C_{\mathrm x} = \frac{1}{6A}\sum_{i=0}^{n-1}(x_i+x_{i+1})(x_i\ y_{i+1} - x_{i+1}\ y_i)
C_{\mathrm y} = \frac{1}{6A}\sum_{i=0}^{n-1}(y_i+y_{i+1})(x_i\ y_{i+1} - x_{i+1}\ y_i)
and where A is the polygon's signed area,
A = \frac{1}{2}\sum_{i=0}^{n-1} (x_i\ y_{i+1} - x_{i+1}\ y_i)\;.[13]
In these formulas, the vertices are assumed to be numbered in order of their occurrence along the polygon's perimeter, and the vertex ( xnyn ) is assumed to be the same as (x0y0 ). Note that if the points are numbered in clockwise order the area A, computed as above, will have a negative sign; but the centroid coordinates will be correct even in this case






IF still u have problem to implement this u can refer my solution given below::::








 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include<bits/stdc++.h>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
 int t;
 scanf("%d",&t);
 while(t--)
 {
  int n,i;
  scanf("%d",&n);
  int x[n+1],y[n+1];
  double ans1=0,ans2=0;
  for(i=0;i<n;i++)
  {
   scanf("%d %d",&x[i],&y[i]);
  }
  double A=0,cx=0,cy=0,p;
         x[n]=x[0];
        y[n]=y[0];
  for(i=0;i<=n-1;i++)
  {
  p=(x[i]*y[i+1])-(x[i+1]*y[i]);
  cx+=p*(x[i]+x[i+1]);
  cy+=p*(y[i]+y[i+1]);
  A+=p;
  }
  A/=2;
  cx/=(6*A);
  cy/=(A*6);
  
  if (fabs(cx) < 0.005 - 1e-9) cx = 0;
  if (fabs(cy) < 0.005 - 1e-9) cy = 0;

  printf("%.2f %.2f\n",
    cx + 1e-9 * (cx >= -1e-9 ? 1 : -1),
    cy + 1e-9 * (cy >= -1e-9 ? 1 : -1));
 }
}

TETRA(Sphere in a tetrahedron) spoj solution

HII GUYS  this is the Geometry based problem.......
Here are some important points regarding tetrahedron.
1.there are total 4 faces of a tetrahedron
2.how to find area of one face so u know that this is a triangle
u can find its area by Hero's formula
Hero's formula is ::::
let sides of a triangle are a,b,c
then perimeter(s)  is equal to 2*s=(a+b+c)
area of triangle =sqrt(s*(s-a)*(s-b)*(s-c))

3.BY this u can find area of every triangle 
then let total area of all faces is equal to T=area1+area2+area3+area4


4.how to find volume for this i m giving u a link there u can find out
that how to calculate volume in terms of sides
link::http://en.wikipedia.org/wiki/Tetrahedron

5.after calculating volume u can use formula for radius of insphere is
=V*3/T
where V is volume
and T is surface area as i mentioned above..........

6.for volume u can also use this formula
       vol=sqrt(4*u*u*v*v*w*w- u*u*(v*v+w*w - U*U)*(v*v+w*w-U*U) - v*v*(w*w+u*u - V*V)*(w*w+u*u-V*V) - w*w*(u*u + v*v - W*W)*(u*u+v*v-W*W) + (v*v +w*w - U*U)*(w*w+u*u- V*V)*(u*u+v*v - W*W))/12
where u,v,w,W,V,U are sides of tetrahedron.....




if still u have u can see my AC SOLUTION>>>>>>>>>
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include<bits/stdc++.h>
using namespace std;
double area(double ,double ,double );
int main()
{
        int t;
        scanf("%d",&t);
        while(t--)
        {
        double u,v,w,U,V,W;
        scanf("%lf %lf %lf %lf %lf %lf",&u,&v,&w,&W,&V,&U);
        double vol;
        double S=0;
        S+=area(u,V,w);
        S+=area(W,u,v);
        S+=area(W,V,U);
        S+=area(U,v,w);
       
        vol=sqrt(4*u*u*v*v*w*w- u*u*(v*v+w*w - U*U)*(v*v+w*w-U*U) - v*v*(w*w+u*u - V*V)*(w*w+u*u-V*V) - w*w*(u*u + v*v - W*W)*(u*u+v*v-W*W) + (v*v +w*w - U*U)*(w*w+u*u- V*V)*(u*u+v*v - W*W))/12;
        printf("%.4lf\n",vol*3.0/S);
        }
        return 0;
}
double area(double a1,double a2,double a3)
{
        double s=(a1+a2+a3)/2.0;
        return sqrt(s*(s-a1)*(s-a2)*(s-a3));
}

Working With Java Collections