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
;
}
查看全文
相关阅读:
HTML5的data-*自己定义属性
Cocos2d-X直接使用OpenGL接口
经典递推问题错排公式分析
一步一步跟我学习lucene(18)---lucene索引时join和查询时join使用演示样例
Linux下安装JRE和Eclipse IDE for C/C++ Developers
Android 官方推荐 : DialogFragment 创建对话框
hibernate 继承映射
[Swift通天遁地]七、数据与安全-(7)创建文件浏览器:以可视化的方式浏览沙箱文件
[Swift通天遁地]七、数据与安全-(6)管理文件夹和创建并操作文件
[Swift]LeetCode398. 随机数索引 | Random Pick Index
原文地址:https://www.cnblogs.com/SQL/p/897746.html
最新文章
【观点见解】解读大数据的5个误区
大数据时代了解一些问题
大数据时代了解一些问题
大数据不会“主动”为企业做的10件事
大数据如何触发精准营销
大数据如何触发精准营销
大数据分析之—基于模型的复杂数据多维聚类分析
大数据分析之—基于模型的复杂数据多维聚类分析
排名前20位的大数据职位及其职责,你能胜任么
spring mvc3.1 @ResponseBody注解生成大量Accept-Charset
热门文章
osx中使用defaults
队列实现 (双向循环链表 C++)
【Cocos游戏实战】功夫小子第八课之游戏打包和相关问题说明
hadoop集群加入新节点hhbase调试
七个迹象说明你可能受到APT 攻击
二叉树的非递归遍历(前序、中序、后序)
HTML5的兴起与4G网络的出现,能否够终止移动端的持续下滑走向
wifidog 认证
Objective-c基础知识学习笔记
libcanbus官方主页
Copyright © 2011-2022 走看看