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"); } } } }
相关文章推荐
- URAL 1132
- 玲珑学院OJ 1132 Down the Rabbit Hole【Dfs序+暴力】
- 1132. Cut Integer (20)
- 1132 Problem A 最长公共子序列
- js里边填充数据:点一次会闪一次的问题
- Glide modules
- Linux安装软件No Key的解决办法
- 公平调度和容量调度的区别
- jQuery Ajax无刷新操作
- 解决双系统下,Ubuntu安装时不能看到已经做好的win7分区的问题
- android apk 编译打包解析
- jQuery和DOM对象使用说明
- 乡村道路 problem d
- winform MouseWheel事件无效
- printf、fprintf、sprintf的区别
- I.MX6Q(TQIMX6Q/TQE9)学习笔记——新版BSP之触摸屏驱动移植
- 每次返回上一个页面让ajax重新请求的一句代码
- 史上最全的CSS样式整理
- 在Android上用AChartEngine轻松绘制图表
- ado创建数据模型和数据访问类