zoukankan
html css js c++ java
PKU1039
几何题
#include
<
math.h
>
#include
<
string
.h
>
#include
<
stdio.h
>
struct
Point
{
double
x,y;
}
;
struct
Line
{
double
x1, y1;
double
x2, y2;
}
;
int
n;
double
x[
20
],y[
20
];
Line line;
int
result;
double
dis;
Point cut(Line l)
{
double
a1, b1, a2, b2;
a1
=
(line.y2
-
line.y1)
/
(line.x2
-
line.x1);
b1
=
line.y1
-
a1
*
line.x1;
a2
=
(l.y2
-
l.y1)
/
(l.x2
-
l.x1);
b2
=
l.y1
-
a1
*
l.x1;
Point p;
p.x
=
(b2
-
b1)
/
(a1
-
a2);
p.y
=
a1
*
p.x
+
b1;
return
p;
}
double
ppdis(Point p1, Point p2)
{
return
sqrt((p1.x
-
p2.x)
*
(p1.x
-
p2.x)
+
(p1.y
-
p2.y)
*
(p1.y
-
p2.y));
}
double
distance()
{
double
dis1, dis2;
Point p1,p2,p3;
p1.x
=
0
, p1.y
=
(line.y2
-
line.y1)
/
(line.x2
-
line.x1)
*
(
0
-
line.x1)
+
line.y1;
Line line1, line2;
line1.x1
=
x[result
-
1
];
line1.y1
=
y[result
-
1
];
line1.x2
=
x[result];
line1.y2
=
y[result];
p2
=
cut(line1);
line2.x1
=
x[result
-
1
];
line2.y1
=
y[result
-
1
]
-
1
;
line2.x2
=
x[result];
line2.y2
=
y[result]
-
1
;
p3
=
cut(line2);
dis1
=
ppdis(p1,p2);
dis2
=
ppdis(p1,p3);
//
printf("%d %lf %lf\n",result, p2.x,p2.y);
if
(dis1
<
dis2)
return
dis2;
else
return
dis1;
}
bool
thro(
int
i)
{
double
holdy
=
(line.y2
-
line.y1)
/
(line.x2
-
line.x1)
*
(x[i]
-
line.x1)
+
line.y1;
if
(holdy
>=
y[i]
-
1
&&
holdy
<=
y[i])
return
1
;
else
return
0
;
}
int
cnt()
{
int
i;
for
(i
=
0
; i
<
n; i
++
)
{
if
(
!
thro(i))
break
;
}
return
i;
}
void
func()
{
int
i, j;
int
res;
for
(i
=
0
; i
<
n; i
++
)
{
for
(j
=
i
+
1
; j
<
n; j
++
)
{
line.x1
=
x[i];
line.y1
=
y[i];
line.x2
=
x[j];
line.y2
=
y[j];
res
=
cnt();
if
(result
<
res)
{
result
=
res;
dis
=
distance();
}
line.x1
=
x[i];
line.y1
=
y[i];
line.x2
=
x[j];
line.y2
=
y[j]
-
1
;
res
=
cnt();
if
(result
<
res)
{
result
=
res;
dis
=
distance();
}
line.x1
=
x[i];
line.y1
=
y[i]
-
1
;
line.x2
=
x[j];
line.y2
=
y[j];
res
=
cnt();
if
(result
<
res)
{
result
=
res;
dis
=
distance();
}
line.x1
=
x[i];
line.y1
=
y[i]
-
1
;
line.x2
=
x[j];
line.y2
=
y[j]
-
1
;
res
=
cnt();
if
(result
<
res)
{
result
=
res;
dis
=
distance();
}
}
}
}
int
main()
{
while
(scanf(
"
%d
"
,
&
n)
!=
EOF)
{
if
(n
==
0
)
break
;
result
=
0
;
dis
=
0
;
int
i;
for
(i
=
0
; i
<
n; i
++
)
{
scanf(
"
%lf%lf
"
,
&
x[i],
&
y[i]);
}
func();
/**/
/*
line.x1=0,line.y1=1,line.x2=4,line.y2=1;
int xx=thro(3);
printf("%d\n",xx);
*/
if
(result
<
n)
printf(
"
%.2f\n
"
,dis);
else
printf(
"
Through all the pipe.\n
"
);
}
return
0
;
}
查看全文
相关阅读:
cas sso ajax的jsonp实现方案总结(新浪微薄、淘宝案例分析)
在linux下利用nohup来后台运行java程序
(判断)window.open()窗口被关闭后执行事件
AngularJS开发指南14:依赖注入
contentEditable
AngularJS 最佳实践
LDAP基本概念
LDAP
spring 配置文件中使用properties文件 配置
【解决Jira】Chrome提示Java插件因过期而遭到阻止(JIRA上传截屏截图)
原文地址:https://www.cnblogs.com/SQL/p/897746.html
最新文章
链路状态和距离矢量路由协议的不同
智能路由器常见的操作系统有这么几种
Apache Tomcat8必备知识(完整的支持WebSockets 1.0)
Tomcat 7 的七大新特性(更容易将Tomcat内嵌到应用去中去 )
锐捷 rg-S2026f 学习笔记
btrace
解决 eclipse tomcat cannot create a server using the selected type
UT报错误:A granted authority textual representation is required
FreeFileSync 4.2 发布,文件夹比较和同步工具
Windows自带NAT端口映射,命令行CMD操作即可
热门文章
关闭程序进程的批处理(千千静听)
redhat 连接mysql数据库Can't get hostname for your address
java支持跨平台获取cpuid、主板id、硬盘id、mac地址 (兼容windows、Linux)
redhat 防火墙禁止允许的IP链接指定的端口
PLSQL在64位 win7/WIN8上运行(绿色版plsql、无需安装oracle客户端)
DCI改进,发布后作业乱码不能打开
华硕主板P8H61(P8H61-M_LX3_PLUS_R2.0)成功禁用USB口
oracle行跟踪(基于行跟踪的ROWDEPENDENCIES ORA_ROWSCN信息)
column count of mysql.proc is wrong. expected 20,found 16. the table is probably corruptd.
Mysql的“Table 'mysql.servers' doesn't exist”的解决方法
Copyright © 2011-2022 走看看