Uva 10792 The Laurel-Hardy Story

Link To The Problem


Solution : Math 


Code:

// UVa 10792 The Laurel Hardy Story
// Math


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>

using namespace std;
#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define DOR(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)

#define oo 1e6
#define eps 1e-4
#define nMax 1010

//{ 
#define pb push_back
#define dbg(x) cerr << __LINE__ << ": " << #x << " = " << x << endl

#define F first
#define S second

#define bug puts("OOOOh.....");
#define zero(x) (((x)>0?(x):-(x))<eps)

#define LL long long
#define DB double 

#define sf scanf
#define pf printf
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)

double const pi = acos(-1.0);
double const inf = 1e9;
double inline sqr(double x) { return x*x; }

int dcmp(double x){
    if(fabs(x)<eps) return 0;
    return x>0?1:-1;
}
//}

// Describe of the 2_K Geomtry
// First Part : Point and Line
// Second Part Cicle
// Third Part Polygan

// First Part:
// ****************************** Point and Line *******************************\\
//  {  

class point {
public:
    double x,y;
    point (double x=0,double y=0):x(x),y(y) {}
    void make(double _x,double _y) {x=_x;y=_y;}
    void read() { scanf("%lf%lf",&x,&y); }
    void out() { printf("%.3lf %.3lf\n",x,y);}
    double len() { return sqrt(x*x+y*y); }

    point friend operator - (point const& u,point const& v) { return point(u.x-v.x,u.y-v.y); }
    point friend operator + (point const& u,point const& v) { return point(u.x+v.x,u.y+v.y); }
    double friend operator * (point const& u,point const& v){ return u.x*v.y-u.y*v.x; }
    double friend operator ^ (point const& u,point const& v) { return u.x*v.x+u.y*v.y; }
    point friend operator * (point const& u,double const& k) { return point(u.x*k,u.y*k); }
	point friend operator / (point const& u,double const& k) { return point(u.x/k,u.y/k); }
	
	friend bool operator < (point const& u,point const& v){
		if(dcmp(v.x-u.x)==0) return dcmp(u.y-v.y)<0;
		return dcmp(u.x-v.x)<0;
	}
	friend bool operator != (point const& u,point const& v){
		return dcmp(u.x-v.x) || dcmp(u.y-v.y);
	}

	point rotate(double s) {
		return point(x*cos(s) + y*sin(s),\
					-x*sin(s) + y*cos(s));
	}
};

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
#endif

	double r,d,h1;
	int T;
	cin >> T;
	for(int cas=1; cas<=T; cas++){
		cin >> r >> d >> h1;
		point O(0,r);
		point B(sqrt(sqr(r)-sqr(r-h1)),h1);
		double alfa = acos((r-d)/r);
		point A = (B-O).rotate(alfa*2)+O;
		pf("Case %d: %.4lf\n",cas,A.y);
	}
	return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章