题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1981
You are given a regular n-gon. Your task is to calculate two values: the number of its diagonals that are parallel to at least one of its other diagonals, and the number of its diagonals that
are perpendicular to at least one of its diagonals. A diagonal is a segment connecting two non-adjacent polygon vertices.
Input
The only line contains an integer n (4 ≤ n ≤ 105).
Output
Output two required numbers.
Sample
input | output |
---|---|
4 |
0 2 |
题意:
求正多边形的对角线中 相互平行和相互垂直的条数!
PS:
画图即可看出规律,
1、边形偶数的都可以找到互相平行和垂直的
2、边形为奇数的不可能找到相互平行和垂直的
代码如下:
#include <cstdio> #include <cmath> #define LL __int64 int main() { LL n; while(~scanf("%I64d",&n)) { LL num = n*(n-3)/2;//对角线条数 if(n == 4) { printf("0 2\n"); continue; } if(n == 5) { printf("0 0\n"); continue; } if(n == 6) { printf("6 9\n"); continue; } if(n%2)//边形为奇数 { printf("%I64d 0\n",num);//不可能有垂直的,画图就知道了 } else//边形偶数的都可以找到互相平行和垂直的 { printf("%I64d %I64d\n",num,num); } } return 0; }
时间: 2024-12-16 15:54:18