大佬求助,对循环条件的疑问
  • 板块CF407A Triangle
  • 楼主Arceus_gyx
  • 当前回复1
  • 已保存回复1
  • 发布时间2022/12/28 21:56
  • 上次更新2023/10/24 06:16:50
查看原帖
大佬求助,对循环条件的疑问
718808
Arceus_gyx楼主2022/12/28 21:56

下面是ac的代码,第十行改成2* x* x<=a* a就是错的了(91分),x<=y的情况考虑完不应该就可以了吗,不太理解,希望路过的大佬可以帮忙看看www

#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int a, b;
    cin >> a >> b;
    for (int x = 1; x  < a; x++)
    {
        int y = int(sqrt(a * a - x * x) + 0.5);
        if (y * y + x * x == a * a)
        { 
            int g = __gcd(x, y);
            int v = x / g, u = y / g; 
            int k = int(sqrt(b * b / (u * u + v * v)) + 0.5);
            if (k * k * (u * u + v * v) == b * b)
            {
                if (x != k * u)
                { 
                    cout << "YES\n";
                    cout << "0 0\n";
                    cout << x << " " << y << "\n";
                    cout << k * u << " " << -k * v << "\n";
                    return 0;
                }
            }
        }
    }
    cout << "NO\n";
    return 0;
}
2022/12/28 21:56
加载中...