2014-2015 ACM-ICPC, NEERC, Moscow Subregional Contest D. Do it Right!

本文介绍了一个算法问题,给定两个正整数A和B,探讨如何找到第三个正整数C,使得A、B、C能构成直角三角形。通过暴力搜索的方法,在给定的限制条件下找到满足条件的C,或者确定不存在这样的C。

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

D. Do it Right!
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Given two distinct positive integers A and B, find out if it is possible to find a third positive integer C so that a triangle with the sides ABand C is a right triangle. Remember that a triangle is called a right triangle if one of its angles equals to 90 degrees.

Input

The first line of input contains two positive integers A and B: the lengths of the two given sides (1 ≤ A < B ≤ 100).

Output

Output "YES" if it is possible to find such an integer C, or "NO" otherwise.

Sample test(s)
input
3 4
output
YES
input
1 2
output
NO
Note
  • In the first example, we can take C = 5.
  • In the second example, it is impossible to find an integer C with the required property.

题意:给a,b,找一个c是的a^2+b^2=c^2

分析:a,b如此小,为何不暴力?

 

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <cstdlib>
 4 #include <cmath>
 5 #include <ctime>
 6 #include <iostream>
 7 #include <algorithm>
 8 #include <map>
 9 #include <set>
10 #include <vector>
11 #include <deque>
12 #include <queue>
13 using namespace std;
14 typedef long long LL;
15 typedef double DB;
16 #define Rep(i, n) for(int i = (0); i < (n); i++)
17 #define Repn(i, n) for(int i = (n)-1; i >= 0; i--)
18 #define For(i, s, t) for(int i = (s); i <= (t); i++)
19 #define Ford(i, t, s) for(int i = (t); i >= (s); i--)
20 #define rep(i, s, t) for(int i = (s); i < (t); i++)
21 #define repn(i, s, t) for(int i = (s)-1; i >= (t); i--)
22 #define MIT (2147483647)
23 #define MLL (1000000000000000000LL)
24 #define INF (1000000001)
25 #define mk make_pair
26 #define ft first
27 #define sd second
28 #define clr(x, y) (memset(x, y, sizeof(x)))
29 #define sqr(x) ((x)*(x))
30 #define sz(x) ((int) (x).size())
31 #define puf push_front
32 #define pub push_back
33 #define pof pop_front
34 #define pob pop_back
35 
36 template<class T>
37 inline T Getint()
38 {
39     char Ch = ' ';
40     T Ret = 0;
41     while(!(Ch >= '0' && Ch <= '9')) Ch = getchar();
42     while(Ch >= '0' && Ch <= '9')
43     {
44         Ret = Ret * 10 + Ch - '0';
45         Ch = getchar();
46     }
47     return Ret;
48 }
49 
50 int a, b;
51 
52 inline void Input()
53 {
54     cin >> a >> b;
55 }
56 
57 inline int Sqr(int x)
58 {
59     return x * x;
60 }
61 
62 inline void Solve()
63 {
64     For(i, 1, 250)
65     {
66         int Arr[3];
67         Arr[0] = a * a;
68         Arr[1] = b * b;
69         Arr[2] = i * i;
70         sort(Arr, Arr + 3);
71         if(Arr[0] + Arr[1] == Arr[2])
72         {
73             puts("YES");
74             return;
75         }
76     }
77     puts("NO");
78 }
79 
80 int main() {
81      Input();
82      Solve();
83     return 0;
84 }
View Code

 

转载于:https://www.cnblogs.com/StupidBoy/p/5063523.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值