UVA Problem 109 ( SCUD Busters) Solution

UVA Problem 109 ( SCUD Busters) Solution

UVA Problem 109 ( SCUD Busters) :

This problem is UVA uhunt book chapters (Computational Geometry problem) category problem.

link: http://uva.onlinejudge.org/external/1/109.html

 

Problem Description:

Find each convex hull for each area then select that convex hull whether a Missile falls inside it.Make aggregation of the area among the selected convex hull.

 

Problem Solution:

#include <bits/stdc++.h>

#include <math.h>

using namespace std;

int main()

{

double x1,x2,x3,y1,y2,y3,d,e,h,k,r,g,f,c,a;

char selectA,selectB,selectC;

while(scanf(“%lf %lf %lf %lf %lf %lf”,&x1,&y1,&x2,&y2,&x3,&y3)==6)

{

g=((x1*x1+y1*y1-x3*x3-y3*y3)*(y1-y2)-(x1*x1+y1*y1-x2*x2-y2*y2)*(y1-y3))/(2*(x1-x2)*(y1-y3)-2*(x1-x3)*(y1-y2));

f=((x1*x1+y1*y1-x2*x2-y2*y2)*(x1-x3)-(x1*x1+y1*y1-x3*x3-y3*y3)*(x1-x2))/(2*(x1-x2)*(y1-y3)-2*(x1-x3)*(y1-y2));

c=-(x1*x1+y1*y1+2*g*x1+2*f*y1);

h=-g;

k=-f;

r=sqrt(g*g+f*f-c);

if(h<0)

{

selectA=’+’;

h=-h;

}

else

{

selectA=’-‘;

}

if(h==0)

{

selectA=’+’;

h=-h;

}

if(k<0)

{

selectB=’+’;

k=-k;

}

else selectB=’-‘;

if(k==0)

{

selectB=’+’;

k=-k;

}

printf(“(x %c %.3f)^2 + (y %c %.3f)^2 = %.3f^2\n”,selectA,h,selectB,k,r);

if(g<0)

{

selectA=’-‘;

g=-g;

}

else

{

selectA=’+’;

}

if(g==-0)

{

selectA=’+’;

g=-g;

}

if(f<0)

{

selectB=’-‘;

f=-f;

}

else

{

selectB=’+’;

}

if(f==-0){

selectB=’+’;

f=-f;

}

if(c>0) selectC=’+’;

else

{

selectC=’-‘;

c=-c;

}

printf(“x^2 + y^2 %c %.3fx %c% .3fy %c %.3f = 0\n\n”,selectA,2*g,selectB,2*f,selectC,c);

}

return 0;

}

UVA Problem 109 ( SCUD Busters) Solution

UVA Problem 476 (Points in Figures Rectangles) Solution

UVA Problem 476 (Points in Figures Rectangles) :

This problem is UVA uhunt book chapters (Computational Geometry problem) category problem.

Details link: http://uva.onlinejudge.org/external/1/476.html

 

Problem Description:

This is a straightforward problem.

#include<bits/stdc++.h>

using namespace std;

int main()

{

    double x1[10],y1[10],x2[10],y2[10],X,Y;

    char ch;

    int index=0,p_no=1,fig;

    while(1)

    {

        cin>>ch;

        if(ch=='*') break;

        cin>>x1[index]>>y1[index]>>x2[index]>>y2[index];

        index++;

    }



   while(scanf("%lf %lf",&X,&Y)==2)

   

    {

        if(X==9999.9&&Y==9999.9) break;



        bool f=false;

        for(fig=0;fig<10;fig++)

        {

            if(X>x1[fig]&&X<x2[fig]&&Y>y2[fig]&&Y<y1[fig])

            {

                printf("Point %d is contained in figure %d\n",p_no,fig+1);



            f=true;

            }

        }

        if(f==false) printf("Point %d is not contained in any figure\n",p_no);

        p_no++;

    }

    return 0;

}

 

UVA Problem 109 ( SCUD Busters) Solution

UVA Problem 640 ( Self Numbers) Solution

UVA Problem 640 ( Self Numbers): Is a basic UVa problem.

Details link:

 

Problem Details:

This is a Straightforward problem.

 

problem solution:

#include <stdio.h>

#include <math.h>



int d[1000010];



int generator(int num)

{

    int sum = num;

    while(num > 0)

    {

        sum += num%10;

        num /= 10;

    }

    return sum;

}



int main()

{

    int i;

//for(i=1;i<=100;i++)

    for(i=1;i<=1000000;i++)

    {

        if(d[i] == 0)

            printf("%d\n",i);

        d[generator(i)] = 1;

    }



    return 0;

}

 

UVA Problem 109 ( SCUD Busters) Solution

UVA Problem 10137 (The trip) Solution

 

#include <bits/stdc++.h>



using namespace std;

double arr[1020];

int main()

{

//    double P=0,N=0,F,S,T;

    int n,i,j;

    while(cin>>n && n)

    {

        double avg=0;

        for(i=0;i<n;i++)

        {

           

            scanf("%lf",&arr[i]);

            avg += arr[i];

        }

        avg /= n;

        double P = 0, N = 0;

        for( j = 0; j < n; j++)

        {

            double res = (long) ((arr[j] - avg) * 100.0) / 100.0;

            if(res> 0)

             P += res;

            else

             N += res;

        }

        N = -N;

        if(N>P)

        printf("$%.2f\n", N );

        else

        printf("$%.2f\n",P);

    }

    return 0;

}

 

UVA Problem 109 ( SCUD Busters) Solution

UVA Problem 10221 ( Satellites) Solution

#include<bits/stdc++.h>

#define PI acos(-1)

using namespace std;





int main ()

{

  double dis_of_sate ,angle,r;

   char s[4];

   while(cin>>dis_of_sate>>angle>>s) // circle (arc) length s=r*theta. (chord) length = 2*rsin(C/2)

   {

       if(s[0]=='m') angle/=60;

       if(angle>180)

       angle=360-angle; // tribhujer kono kon 180 er boro hoy na

       r=dis_of_sate + 6440;

       angle=PI*angle/180;

  

    printf("%.6lf %.6lf\n",r*angle,2*r*sin(angle/2));

}

    return 0;

}

 

UVA Problem 109 ( SCUD Busters) Solution

UVA Problem 10286 (Trouble with a Pentagon) Solution

 

#include <bits/stdc++.h>

#include <math.h>

#define pi acos(0.0)

//#define pi 3.1416

int main()

{

double n;



while(scanf("%lf",&n) != EOF )

{

    //poligon_inte_angle = (3/5)*180=(108 degree)as figure sides n=5;

    //square_inte_angle  = (2/4)*90=(63 degree) as figure sides n=4;

printf("%.10lf\n",( n*sin(108*pi/90 ) / sin(63*pi/90) ));//* pi/90



}



return 0;

}

 

UVA Problem 109 ( SCUD Busters) Solution

UVa Problem 10347 ( Medians) Solution

 

#include <bits/stdc++.h>

#include <math.h>



using namespace std;



int main()

{



 double  a,b,c,ans,s;



 while(scanf("%lf %lf %lf",&a,&b,&c) == 3 )

 {



 s=(a+b+c)/2;

 ans=sqrt(s*(s-a)*(s-b)*(s-c));

 if(ans>0)

 printf("%.3lf\n",ans*(4.0/3.0));

 else

 {

 ans=-1;

 printf("%.3lf\n",ans);

 }

 }



return 0;

}

 

UVA Problem 109 ( SCUD Busters) Solution

UVA Problem 10451 (Ancient Village Sports) Solution

 

 

#include <bits/stdc++.h>

#include<iostream>

#include<math.h>

#define pi 2*acos(0.0)



using namespace std;



int main()

{

double n,x,y,a,R,r,A,A1,A2,spect,offic;



int c=0;



while(scanf("%lf %lf",&n,&A)==2 && n>=3)

{



r=sqrt((2*A)/(n*sin(2*pi/n))); //2. Given the radius (circumradius); area(A)=((r^2)nsin(360/n)/2)

R=sqrt( A/(n*tan(pi/n))); //Given the apothem (inradius) area=a^2 ntan(180/n);

                             //printf("Case %d: %.5lf %.5lf\n",i,R,r);

A1=pi*r*r;

A2=pi*R*R;



spect = A1-A;

offic = A-A2;



printf("Case %d: %.5lf %.5lf\n",c+1,spect,offic);



c++;



}   

     return 0 ;

}

 

UVA Problem 109 ( SCUD Busters) Solution

UVA Problem 10522 Solution

 

 

#include <bits/stdc++.h>

#include <cmath>



using namespace std;



int main()

{

  int tc;

  cin>>tc;

 

  while (tc) {

     

    double ha, hb, hc,a,b,c;//s,s1,a1,b1,c1,a,b,c;

    scanf("%lf%lf%lf", &ha, &hb, &hc);

    

     

         a=1/ha,b=1/hb,c=1/hc;

      double s1=(a + b + c);

      double a1=(-a + b + c);

      double b1=(a - b + c);

      double c1=(a + b - c);

      double s=s1*a1*b1*c1;

       if (s <= 0)

        {

        printf("These are invalid inputs!\n");

        tc--;

          }

       else if (ha == 0 || hb == 0 || hc == 0)

      {

       printf("These are invalid inputs!\n");

       tc--;   

      }

      else {

        printf("%.3f\n", 1 / sqrt(s));

      }

     

     

    }

 

  return 0;

}

 

UVA Problem 109 ( SCUD Busters) Solution

UVA Problem 10573 Solution

 

 

#include <bits/stdc++.h>

#define PI 2*acos(0)



using namespace std;



int main()

{

    int n,tc,i,j;

    char t[2];

    cin>>tc;

    while(tc--)

    {

        int a,b;

        cin>>a;

        if(getchar()=='\n')

       {

        printf("%.4lf\n", (2*a*a*PI)/16);

        }

        else

        {

        cin>>b;

        printf("%.4lf\n", 2*a*b*PI);

        }

    }

    return 0;

}

 

UVA Problem 109 ( SCUD Busters) Solution

UVA Problem 10589 (Area) Solution

 

 

#include <bits/stdc++.h>



using namespace std;



int main()



{

    int N,a,M,rr;

   

    double x,y;

   

    while(scanf("%d %d",&N,&a)!=EOF && N)

    {

        bool f = true;

        M = 0;

        rr = a*a;

       

        for(int i = 0;i<N;++i)

        {

            scanf("%lf %lf",&x,&y);

           

            f = true;

           

            if((x-0)*(x-0)+(y-0)*(y-0)>rr)   //(x1,y1)(x2,y2) bindu gula: (0,0)(0,0)

            f = false;                        //(0,a)(0,a);(a,0)(a,0);(a,a)(a,a)

            if((x-0)*(x-0)+(y-a)*(y-a)>rr)

            f = false;

            if((x-a)*(x-a)+(y-0)*(y-0)>rr)

            f = false;

            if((x-a)*(x-a)+(y-a)*(y-a)>rr)

            f = false;

           

            if(f)

            {

                M++;

            }

        }

       

        printf("%.5f\n",(double)M*(a*a)/N);

    }

   

    return 0;

}

 

UVA Problem 109 ( SCUD Busters) Solution

UVA Problem 10991(Region) Solution

 

 

#include<bits/stdc++.h>

#include <iostream>

#include<math.h>



using namespace std;



int main()

{



    double c1,c2,c3,a,b,c,s,ang1,ang2,ang3,arc1,arc2,arc3,area,area1,area2;

    int tc;

    scanf("%d",&tc);

    while(tc--){



        scanf("%lf%lf%lf",&c1,&c2,&c3);



        a=c1+c2;

        b=c2+c3;

        c=c1+c3;



        s =(a+b+c)/2.0;

       area1 = sqrt(s*(s-a)*(s-b)*(s-c));





        ang1 = acos((b*b+c*c-a*a)/(2*b*c));

        ang2 = acos((c*c+a*a-b*b)/(2*c*a));

        ang3 = acos((a*a+b*b-c*c)/(2*a*b));





      arc1 =(c3*c3*ang1) ;

        arc2 =(c2*c2*ang3);//arc2 =(c3*c3*ang3) ;//arc2 =(c2*c2*ang3) ;

        arc3 =(c1*c1*ang2); //arc3 =(c2*c2*ang2);*///arc3 =(c1*c1*ang2);



        area2 = (arc1 +arc2 +arc3 )/2;



        printf("%.6lf\n",area1-area2);

    }

    return 0;

}

 

UVA Problem 109 ( SCUD Busters) Solution

UVA Problem 10254 ( The Priest Mathematician) Solution

 

 

#include <bits/stdc++.h>



using namespace std;



int main()



{

    int s,n;

    int first_term,last_term;

   

    while (scanf("%d", &s), s != -1)

    {

        int n_sum =(int)sqrt(2*s);

       

        for (n = n_sum ; n > 0; n--)

       

         {

            if ( (2 * s + n - n * n) % (2 * n) == 0 )

           

            {

           

             first_term =  (2 * s + n - n * n) / (2 * n);

              last_term  =  first_term + n - 1;

           

            break;



            }

        }

        printf("%d = %d + ... + %d\n", s, first_term, last_term);

//    return 0*    printf("%d = %d + ... + %d\n", s, a, last_term);

    }



    return 0;

}

 

UVA Problem 109 ( SCUD Busters) Solution

UVA Problem 10341 – Solve It Solution

#include <cstdio>

#include <cmath>

using namespace std;

int main()

{

int T,p,q,r,s,t,u;

double lo,hi,mi,f;

while(scanf("%d %d %d %d %d %d",&p,&q,&r,&s,&t,&u)==6)

{

if(p*exp(-1)+q*sin(1)+r*cos(1)+s*tan(1)+t+u>1e-9 || p+r+u<0)

{

printf("No solution\n");

continue;

}

lo=0.0; hi=1.0;

for(int i=0;i<30;i++){

mi=(lo+hi)/2;

f=p*exp(-mi)+q*sin(mi)+r*cos(mi)+s*tan(mi)+t*mi*mi+u;

if(f>0) lo=mi;

else hi=mi;

}

printf("%.4f\n",lo);

}

return 0;



}

 

UVA Problem 109 ( SCUD Busters) Solution

UVA Problem Uva 369 – Combinations Solution

 

 

#include <bits/stdc++.h>

using namespace std;



long double func_tion (long double n)

{

    long double i,r = 1;

    for ( i = 2; i <= n; i++)

    {

        r *= i;

    }

    return r;

}

int main ()

{

    long double M, N,r,n,m;

    while (cin>>N>>M)

    {

        if( N==0 and M==0 ) break;

        n=(func_tion(N));

        m=(func_tion(N-M)*func_tion(M));

        r = n/m;

           cout << N << " things taken " << M << " at a time is " << setprecision(0) << r << " exactly." << endl;

    }

    return 0;

}

 

UVA Problem 109 ( SCUD Busters) Solution

UVA Problem 621 ( Secret Research ) Solution

 

 

#include <bits/stdc++.h>

using namespace std;

int main()

{

int tc;

char s[2000],l;

cin>>tc;

while (tc--)

{

scanf("%s", s);

l = strlen(s);

if (strcmp(s, "1") == 0 || strcmp(s, "4") == 0 || strcmp(s, "78") == 0)

printf("+\n");

else if ( s[l - 1] == '5' && s[l - 2] == '3')

printf("-\n");

else if (s[0] == '9' && s[l - 1] == '4')

printf("*\n");

else if (s[0] == '1' && s[1] == '9' && s[2] == '0')

printf("?\n");

else

printf("+\n");

}

return 0;

}

 

UVA Problem 109 ( SCUD Busters) Solution

UVA Problem 846 Steps Solution

#include<bits/stdc++.h>

   

using namespace std;

   

int main()

{

    double n;

    int cases;

    int cont=0;

   

    while(cin>>n){

    cont=0;

    for(cases=1;;)

        {

           

        if((cases%2)==1)

        {

            n/=9;

            cont++;

           

        }

        else

        {

            n/=2;

            cont++;

        }

       

        if(n<=1)

        {

         break;   

        }

          cases++;

        }

        if(cont%2==1)

        printf("Stan wins.\n");

        else

        printf("Ollie wins.\n");

   

    }

    return 0;

    }

 

UVA Problem 109 ( SCUD Busters) Solution

UVA Problem 945 Bicoloring Solution

 

 

#include<stdio.h>

#include<string.h>

int main()

{

int l,i,j,count=0;

char s[100000];

while(gets(s))

{

l=strlen(s);

for(i=0;i<l;i++)

    {

    switch(s[i])

            {

            case 'b':

                {

                for(j=0;j<count;j++)

                printf(" ");

                count=0;    break;

                }

            case '1':

            count=count+1;      break;

            case '2':

            count=count+2;      break;

            case '3':

            count=count+3;      break;

            case '4':

            count=count+4;      break;

            case '5':

            count=count+5;      break;

            case '6':

            count=count+6;      break;

            case '7':

            count=count+7;      break;

            case '8':

            count=count+8;      break;

            case '9':

            count=count+9;      break;

            case '!':

            printf("\n");

            default:

                {

                for(j=0;j<count;j++)

                printf("%c",s[i]);

                count=0;    break;

                }

            }

        }

printf("\n");

}

return 0;

}