HOJ 1551 Polylops(简单数学题)

Polylops

My Tags  (Edit)
  Source : Waterloo ACM Programming Contest Oct 4, 1998
  Time limit : 1 sec   Memory limit : 32 M

Submitted : 57, Accepted : 33

Given the vertices of a non-degenerate polygon (no 180-degree angles, zero-length sides, or self-intersection - but not necessarily convex), you must determine how many distinct lines of symmetry exist for that polygon. A line of symmetry is one on which the polygon, when reflected on that line, maps to itself.


Input

Input consists of a description of several polygons. 

Each polygon description consists of two lines. The first contains the integer "n" (3 <= n <= 1000), which gives the number of vertices on the polygon. The second contains "n" pairs of numbers (an x- and a y-value), describing the vertices of the polygon in order. All coordinates are integers from -1000 to 1000.

Input terminates on a polygon with 0 vertices.


Output

For every polygon described, print out a line saying "Polygon #x has y symmetry line(s).", where x is the number of the polygon (starting from 1), and y is the number of distinct symmetry lines on that polygon.

Sample Input

4
-1 0 0 2 1 0 0 -1
3
-666 -42 57 -84 19 282
3
-241 -50 307 43 -334 498
0
Sample Output
Polygon #1 has 1 symmetry line(s).
Polygon #2 has 0 symmetry line(s).
Polygon #3 has 1 symmetry line(s).

既然是一道简单数学题为什么还特意写了一发题解呢。。

因为这题非常坑,有一种特别神奇的情况很难想到。

求从长方体的角沿着表面走到表面任意点的最短距离。

可以把长方体翻折开,化立体为平面,求直线距离即可。

分类讨论,在下面的三个面直接求距离,在上面的时候需要求出几种可能路径取最小值。

每个面都有四种路径,可以想一想(我当初就只想到了两种。。WA到死。。)

代码如下:

#include <iostream>
#include <cstdio>
using namespace std;
const int INF = 0x3f3f3f3f;
int main()
{
    int lx,ly,lz,x,y,z;
    while(scanf("%d%d%d%d%d%d",&lx,&ly,&lz,&x,&y,&z),lx+ly+lz+x+y+z){
        int ans = INF;
        if(!x||!y||!z)
            ans = x*x+y*y+z*z;
        if(x == lx){
            ans = min(ans,(x+y)*(x+y)+z*z);
            ans = min(ans,(z+x)*(z+x)+y*y);
            ans = min(ans,(ly+z)*(ly+z)+(x+ly-y)*(x+ly-y));
            ans = min(ans,(y+lz)*(y+lz)+(x+lz-z)*(x+lz-z));
        }if(y == ly)
        {
            ans = min(ans,(y+z)*(y+z)+x*x);
            ans = min(ans,(y+x)*(y+x)+z*z);
            ans = min(ans,(z+lx)*(z+lx)+(y+lx-x)*(y+lx-x));
            ans = min(ans,(lz+x)*(lz+x)+(y+lz-z)*(y+lz-z));
        }if(z == lz){
            ans = min(ans,(z+y)*(z+y)+x*x);
            ans = min(ans,(z+x)*(z+x)+y*y);
            ans = min(ans,(y+lx)*(y+lx)+(z+lx-x)*(z+lx-x));
            ans = min(ans,(ly+x)*(ly+x)+(z+ly-y)*(z+ly-y));
        }
        printf("%d\n",ans);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值