Volume 1. Elementary Problem Solving :: Maths - Simple Geometry Uva 10250,579,375,10387,10112


刘汝佳 算法入门 第一版 Uva题目集合(七)


Uva 10250

#include <stdio.h>
main(){
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
	double x1,y1,x2,y2,x3,y3,x4,y4,cx,cy;
	while(scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2)!=EOF){
		if(x1==x2 && y1==y2)
			printf("Impossible.\n");
		else{
			cx=(x1+x2)/2;cy=(y1+y2)/2;
			x1-=cx;
			x2-=cx;
			y1-=cy;
			y2-=cy;
			x3=-y1;
			y3=x1;
			x4=-x3;
			y4=-y3;
			printf("%lf %lf %lf %lf\n",x3+cx,y3+cy,x4+cx,y4+cy);
		}
	}
}


Uva 579

#include <stdio.h>
#include <stdlib.h>

main(){
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
	int H,M;
	while ( scanf("%d:%d",&H,&M) && H+M ) {
		double m = M*6.0;
		double h = H*30.0+M*0.5;
		double a = h-m;
		if ( a <  0  ) a += 360.0;
		if ( a > 180 ) a = 360.0-a;
		printf("%.3lf\n",a);
	}

}


Uva 375

#include <math.h>
#include <stdio.h>
main( ){
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    int t;
    double x,y,r,sum;
    const double pi = 4.0 * atan( 1.0 );

    scanf("%d",&t);
    while( t-- ){
        scanf("%lf%lf",&x,&y);
        sum = 0;
        r = tan( atan( y/x*2 ) /2 ) * x/2;
        while( r >= 0.000001 ){
            sum += r;
            x = x/y*( y-2*r );
            y -= 2*r;
            r = tan( atan( y/x*2 ) /2 ) * x/2;
        }
        printf("%13.6lf\n",sum*2*pi);
        if( t ) puts("");
    }
}


Uva 10387

#include <stdio.h>
#include <math.h>

#define PI acos(-1)

main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
	double a, b, s, m, n;
	double angle, velocity;

	while (scanf ("%lf%lf%lf%lf%lf", &a, &b, &s, &m, &n) != EOF) {
		if (a == 0 && b==0 && s==0 && m==0 && n==0)
		break;
		angle = atan( (b*n)/(a*m) ) * 180 / PI;
		velocity = sqrt(b*n*b*n+a*m*a*m) / s;
		printf ("%.2lf %.2lf\n", angle, velocity);
	}
}


Uva 10112

#include <stdio.h>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <ctime>
using namespace std;
#define eps 1e-8

struct Point
{
    char num;
    double x;
    double y;
}po[20];

double xmul(Point a, Point b, Point c) {
    return (c.y-a.y)*(b.x-a.x)-(b.y-a.y)*(c.x-a.x);
}
double area(Point a, Point b, Point c)
{
    return fabs(0.5*xmul(a, b, c));
}
bool isin(Point a, Point b, Point c, Point p) {
    return fabs(area(a, b, p)+area(a, c, p)+area(b, c, p)-area(a, b, c)) < eps;
}
main(){
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    Point a, b, c;
    bool flag;
    int n;
    double tar;
    while(EOF != scanf("%d", &n)) {
        if(n == 0) break;
        tar = -1;
        for(int i = 0; i < n; ++i) {
            scanf("%*c%c %lf %lf", &po[i].num, &po[i].x, &po[i].y);
         //   printf("%c %lf %lf\n", po[i].num, po[i].x, po[i].y);
        }
        for(int i = 0; i < n; ++i)
            for(int j = i+1; j < n; ++j)
                for(int k = j+1; k < n; ++k) {
                    flag = true;
                    for(int t = 0; t < n; ++t)
                        if(t != i && t != j && t != k && isin(po[i], po[j], po[k], po[t])) {
                            flag = false;
                            break;
                        }
                    if(flag && fabs(area(po[i], po[j], po[k]) > tar+eps)) {
                        a = po[i], b = po[j], c = po[k];
                        tar = area(po[i], po[j], po[k]);
                    }
                }
        printf("%c%c%c\n", a.num, b.num, c.num);
    }
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值