您的位置:首页 > 其它

promise me a medal

2016-06-23 14:04 183 查看

promise me a medal

时间限制:1000 ms  |  内存限制:65535 KB

难度:2

描述
  you all know that creat2012 will go to a regional. and i want you all pray for us. thx.

  for this problem, you need judge if two segments is intersection(相交的). if intersect(相交), print yes and the point. else print no.

  easy ? ac it.

输入T <= 100 cases

8 real numbers (double)

promise two segments is no coincidence.输出no

or yes and two real number (one decimal)样例输入
2
0 0 2 2 1 0 3 2
0 0 2 2 0 2 2 0

样例输出
no
yes 1.0 1.0


#include<stdio.h>
double we(double a,double b)
{
return a>b?a:b;
}
double ni(double a,double b)
{
return a<b?a:b;
}
int main()
{
int t;
double a,b,c,d,e,f,g,h;
scanf("%d",&t);
while(t--)
{
scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f,&g,&h);
double w,m;
w=(d-b)/(c-a);
m=(h-f)/(g-e);
double s,l;
s=d-w*c;
l=h-m*g;
if(a==c&&e!=g)//第一个平行于y轴
{
double y;
y=m*a+l;
if(y>=ni(b,d)&&y<=we(b,d))
printf("yes %.1lf %.1lf\n",a,y);
else
printf("no\n");
}
if(e==g&&a!=c)//第二个平行于y轴
{
double y;
y=w*e+s;
if(y>=ni(f,h)&&y<=we(f,h))
printf("yes %.1lf %.1lf\n",e,y);
else
printf("no\n");
}
if(a==c&&e==g)//另个都平行于y轴
{
if(a!=e)
printf("no\n");
else
{
if(we(f,h)>=ni(b,d)&&we(f,h)<=we(b,d))
printf("yes %.1lf %.1lf\n",a,we(f,h));
else if(we(b,d)>=ni(f,h)&&we(b,d)<=we(f,h))
printf("yes %.1lf %.1lf\n",a,we(b,d));
else
printf("no\n");
}
}
if(a!=c&&e!=g)
{
if(w==m)
{
if(s!=l)//b不相等,斜率相等,没有焦点
{
printf("no\n");
}
else//在一条直线上,找x最大的那个就是焦点
{
if(we(a,c)>=ni(e,g)&&we(a,c)<=we(e,g))
printf("yes %.1lf %.1lf\n",we(a,c),w*we(a,c)+s);
else if(we(e,g)>=ni(a,c)&&we(e,g)<=we(a,c))
printf("yes %.1lf %.1lf\n",we(e,g),m*we(e,g)+l);
else
printf("no\n");
}
}
else//斜率不相等,直接求焦点
{
double x;
x=(l-s)/(w-m);
if(x>=ni(a,c)&&x<=we(a,c)&&x>=ni(e,g)&&x<=we(e,g))
printf("yes %.1lf %.1lf\n",x,w*x+s);
else
printf("no\n");
}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  acm练习场 1132