URAL 1982 Parallel and Perpendicular
来源:互联网 发布:芈月传 大秦帝国 知乎 编辑:程序博客网 时间:2024/04/26 13:04
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
题意:给一个正n边形,求正n边行的对角线中,相互平行相互垂直的对角线有几条(注:相邻的顶点的边不是对角线)
题解:数学题一般由两种解法,一种是找规律,另一种是公式。先把正4-10边行的情况列出来,
n边形 平行 垂直
4 0 2
5 0 0
6 6 9
7 14 0
8 20 20
9 27 0
10 35 35
由此可得 n为偶数时,都可以找到平行和垂直的对角线
n为奇数时,不可能找到垂直的线。
其中n=5 6 7时为特殊情况,其他的推出 平行=垂直=n*(n-3)/2
#include <cstdio> #include <cmath> #define LL __int64 //__int64是Win32平台编译器64位长整型的定义方式int main() { LL n; //定义一个长型的n,表示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; }
0 0
- URAL 1982 Parallel and Perpendicular
- URAL 1981. Parallel and Perpendicular(数学 )
- ural 1981. Parallel and Perpendicular 【规律】
- URAL 1981. Parallel and Perpendicular 对角线的平行和垂直
- Parallel and Perpendicular
- Timus 1981. Parallel and Perpendicular
- Concurrent and Parallel Programming
- Parallel Containers and Objects
- 7. Scaling and Parallel Processing
- twin primes. serial and parallel
- Advanced Computer Architecture and Parallel Processing
- Process Algebra for Parallel and Distributed Processing
- MapReduce and Parallel DBMSs Friends or Foes
- Parallel bulk copy and IDENTITY columns
- MapReduce and Parallel DBMSs: Friends or Foes?
- Export with Spool and Parallel Utl_File
- Auto DOP and Parallel Statement Queuing
- 有关并发Concurrent and 并行Parallel
- 94:Maximum Subarray
- c# 加密与解密 Base64Encode
- Sql Server内置函数实现MD5加密
- PXC集群添加新节点如何使用IST方式避免使用SST方式传输数据
- Bootstrap 按钮
- URAL 1982 Parallel and Perpendicular
- 使用ntp服务同步时间
- 用户线程和守护线程
- ssh 免登陆配置
- 堆排序实现(Java)
- MQTT---HiveMQ源码详解(十五)Persistence-Cluster/Single
- PHP7.0.1下的csv解析bug
- spring事务隔离
- POI操作word模板并生成新的word.docx