| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
怎么会是WA呢?帮忙看下啦,是不是精度不够的问题啊?#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
struct point
{
double x;
double y;
};
struct ipoint
{
int x;
int y;
};
struct ipoint p1,p2,p3,p4;
void getP(struct point *p)
{
//计算交点的坐标
double d1,d2,d3,d4;
d1 = p1.x * ((double)p2.y - p1.y) / (p2.x - p1.x);
d2 = p3.x * ((double)p4.y - p3.y) / (p4.x - p3.x);
d3 = ((double)p2.y - p1.y) / (p2.x - p1.x);
d4 = ((double)p4.y - p3.y) / (p4.x - p3.x);
p->x = (p3.y - p1.y + d1 - d2) / (d3 - d4);
p->y = (p2.y - p1.y) * (p->x - p1.x) / (p2.x - p1.x) + p1.y;
}
void getUVE(struct point *p)
{
//计算切点的坐标
double len = sqrt(((double)p3.x - p4.x) * (p3.x - p4.x) + (p3.y - p4.y) * (p3.y - p4.y));
p->x = (p4.x - p3.x) / len;
p->y = (p4.y - p3.y) / len;
}
double getLen(struct point p)
{
return sqrt(sqrt((((double)p.x - p1.x) * (p.x - p1.x) + (p.y - p1.y) * (p.y - p1.y)) * ((p.x - p2.x) * (p.x - p2.x) + (p.y - p2.y) * (p.y - p2.y))));
}
double getL(struct point sp1,struct ipoint sp2)
{
//切割线定理p^2=a*b
return sqrt((sp1.x - sp2.x) * (sp1.x - sp2.x) + (sp1.y - sp2.y) * (sp1.y - sp2.y));
}
double getL(struct ipoint sp1,struct ipoint sp2)
{
//算两点间距离
return sqrt(((double)sp1.x - sp2.x) * (sp1.x - sp2.x) + (sp1.y - sp2.y) * (sp1.y - sp2.y));
}
int isnumber(char c)
{
if(c>='0' && c<='9')
return 1;
else
return 0;
}
int getin()
{
char buffer[100];
char nbuffer[10];
if(gets(buffer) == NULL)
{
return EOF;
}
int i;
int j;
int len = strlen(buffer);
j = 0;
i = -1;
while(isnumber(buffer[++i])==0);
for(;i < len;i++)
{
if(isnumber(buffer[i])==0)
break;
nbuffer[j++] = buffer[i];
}
nbuffer[j] = 0;
p1.x = atoi(nbuffer);
j = 0;
while(isnumber(buffer[++i])==0);
for(;i < len;i++)
{
if(isnumber(buffer[i])==0)
break;
nbuffer[j++] = buffer[i];
}
nbuffer[j] = 0;
p1.y = atoi(nbuffer);
j = 0;
while(isnumber(buffer[++i])==0);
for(;i < len;i++)
{
if(isnumber(buffer[i])==0)
break;
nbuffer[j++] = buffer[i];
}
nbuffer[j] = 0;
p2.x = atoi(nbuffer);
j = 0;
while(isnumber(buffer[++i])==0);
for(;i < len;i++)
{
if(isnumber(buffer[i])==0)
break;
nbuffer[j++] = buffer[i];
}
nbuffer[j] = 0;
p2.y = atoi(nbuffer);
j = 0;
while(isnumber(buffer[++i])==0);
for(;i < len;i++)
{
if(isnumber(buffer[i])==0)
break;
nbuffer[j++] = buffer[i];
}
nbuffer[j] = 0;
p3.x = atoi(nbuffer);
j = 0;
while(isnumber(buffer[++i])==0);
for(;i < len;i++)
{
if(isnumber(buffer[i])==0)
break;
nbuffer[j++] = buffer[i];
}
nbuffer[j] = 0;
p3.y = atoi(nbuffer);
j = 0;
while(isnumber(buffer[++i])==0);
for(;i < len;i++)
{
if(isnumber(buffer[i])==0)
break;
nbuffer[j++] = buffer[i];
}
nbuffer[j] = 0;
p4.x = atoi(nbuffer);
j = 0;
while(isnumber(buffer[++i])==0);
for(;i < len;i++)
{
if(isnumber(buffer[i])==0)
break;
nbuffer[j++] = buffer[i];
}
nbuffer[j] = 0;
p4.y = atoi(nbuffer);
if(i >= len)
return EOF;
else
return 1;
}
int main()
{
freopen("3223.in","r",stdin);
while(getin() != EOF)
{
struct point p;
struct point e;
struct point g;
double len;
double a,b,c;
double Cos;
//得到交点
getP(&p);
//得到交点到切点的距离
len = getLen(p);
//得到单位向量
getUVE(&e);
//计算切点坐标
g.x = p.x + len * e.x;
g.y = p.y + len * e.y;
//利用余弦定理计算余弦值
a = getL(g,p2);
b = getL(g,p1);
c = getL(p1,p2);
Cos = (a * a + b * b - c * c) / (2 * a * b);
//反余弦后进行弧度单位转化
Cos = acos(Cos) * 180 / 3.1415926535897932384626433832795;
//输出结果
printf("%.3f\n", Cos);
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator