URAL 1981. Parallel and Perpendicular 对角线的平行和垂直

探讨如何计算正n边形中至少有一条平行或垂直的对角线条数,针对不同n值给出具体解法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1981. Parallel and Perpendicular

Time limit: 0.5 second
Memory limit: 64 MB
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




题意:

问正n边形,有多少条对角线能找到一条以上与之平行的对角线,又有多少条对角线可以找到一条以上与之垂直的对角线。


 yy的。 画出了5,6,7,8,发现了点规律。正六边形 的三条线平分线是找不到与之平行的对角线的,而每一条线都可以找到与之垂直的对角线。所以n=6时,答案是6和9。再慢慢画出七边形,和五边形相似,没有对角线会互相垂直的,后面的所有奇数的正n边形都是找不到垂直的对角线的。但是奇数n>7,所有对角线都是可以找到互相平行的对角线的。再画画八边形,所有对角线都可以找到互相垂直互相平行的对角线。






#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <malloc.h>
#include <ctype.h>
#include <math.h>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
#include <stack>
#include <queue>
#include <vector>
#include <deque>
#include <set>
#include <map>  
#include<stdio.h>
#include<stdlib.h>

#define pi acos(-1.0)
int main()
{  
	__int64 n,ans; 
	while(scanf("%I64d",&n) != EOF && n)  
	{   
		if(n==4)
		{
			puts("0 2");
		}
		else if(n==6)
			puts("6 9");
		else if (n&1)
		{
			if(n==5)
				puts("0 0");
			else
			{
				ans=(n*(n-3))/2; 
				printf("%I64d 0\n",ans); 
			}
		}
		else 
		{
			ans=(n*(n-3))/2;
			printf("%I64d %I64d\n",ans,ans); 
		}  
	} 
	return 0; 
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值