博客
关于我
1079 三角形
阅读量:626 次
发布时间:2019-03-13

本文共 1384 字,大约阅读时间需要 4 分钟。

1079 三角形

时间限制:500MS 代码长度限制:10KB

提交次数:283 通过次数:82

题型: 编程题 语言: G++;GCC

Description

著名的数学家毕达哥拉斯可能从来都不曾想过有人居然会问他这样的一个问题:给出一个整数,存在多少个直角三角形,

它的某一条边的长度等于这个整数,而且其他边的长度也是整数。既然毕达哥拉斯不可能预见到有计算机的出现,
如果他回答不出来,那谁又能责怪他呢?但是现在既然你有了计算机,那么回答不出来就说不过去了。

输入格式 第一行有一个整数n,代表有多少个数据(1<=n<=20)。接下来有n行,每行代表一个数据。一个数据就是一个整数ai(a<=i<=n,1<=ai<=100)。

输出格式

每个数据都必须有相应的输出。两个数据的输出之间有一个空行。

对于每一个数据,如果找不到解,则输出一个空行。如果找到解,就把符合条件的所有直角三角形输出。每个三角形占一行,输出该三角形的另外两条边,
必须先输出长边,然后一个逗号,再输出短边。两个三角形之间不能有空行,而且必须按照长边降序排列。

输入样例

2

20
12

输出样例

101,99

52,48
29,21
25,15
16,12

37,35

20,16
15,9
13,5

#define _CRT_SECURE_NO_WARNINGS#include "stdio.h"#include "stdlib.h"#include "iostream"#include 
#include
#include
#include
#include
using namespace std;//题目当直角边为100 斜边最大为2501void work(int d) { //如果d为直角边 //遍历斜边c for (int c = 2501; c > d; c--) { //开平方强转int求b int b = (int)sqrt(c * c - d * d); //如果b为整数则说明是一组数据 //并且c要大于b 否则会重复 if (b * b + d * d == c * c&&c>b) { cout << c << "," << b << endl; } } //如果d为斜边 //则遍历直角边a for (int a = d - 1; a > 0; a--) { //开平方强转int求b int b = (int)sqrt(d * d - a * a); //如果b为整数则说明是一组数据 //并且a要大于b 否则会重复 if (a * a + b * b == d * d&&a>b) { cout << a << "," << b << endl; } } //找完后换行 cout << endl;}int main(void) { ios::sync_with_stdio(0), cin.tie(0); int n; cin >> n; while (n--) { int d; cin >> d; work(d); } return 0;}

转载地址:http://elraz.baihongyu.com/

你可能感兴趣的文章
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
No module named 'pandads'
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>
No new migrations found. Your system is up-to-date.
查看>>
No qualifying bean of type XXX found for dependency XXX.
查看>>
No qualifying bean of type ‘com.netflix.discovery.AbstractDiscoveryClientOptionalArgs<?>‘ available
查看>>
No resource identifier found for attribute 'srcCompat' in package的解决办法
查看>>
no session found for current thread
查看>>
No static resource favicon.ico.
查看>>
no such file or directory AndroidManifest.xml
查看>>
No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
查看>>
NO.23 ZenTaoPHP目录结构
查看>>