HOJ 1551 Polylops(简单数学题)

来源:互联网 发布:剑灵力士卡刀软件 编辑:程序博客网 时间:2024/05/30 04:49

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 -13-666 -42 57 -84 19 2823-241 -50 307 43 -334 4980
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
原创粉丝点击