您的位置:首页 > 编程语言 > Go语言

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

2014-08-17 17:48 417 查看
刘汝佳 算法入门 第一版 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

#i
a40d
nclude <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);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息