1. 程式人生 > >【Codeforces Round #239 (Div. 1) A】Triangle

【Codeforces Round #239 (Div. 1) A】Triangle

div urn end ont stdin a* 題意 sqrt 是不是

【鏈接】 我是鏈接,點我呀:)
【題意】


在這裏輸入題意

【題解】


最後的直角三角形可以通過平移,將直角頂點移動到坐標原點。
然後我們只要枚舉另外兩個點其中一個點的坐標就好了。
x坐標的範圍是[1..a)
因為再長的話,這條邊肯定就超過邊長a了。
然後用一些相似三角形的規律就能知道另外一個點的坐標了。
看看這兩個點的y坐標是不是一樣就好。

【代碼】

#include <bits/stdc++.h>
using namespace std;

int a,b;

int main(){
    #ifdef LOCAL_DEFINE
        freopen("rush_in.txt"
, "r", stdin); #endif ios::sync_with_stdio(0),cin.tie(0); cin >> a >> b; for (int i = 1;i < a;i++){ int x = i; int y = sqrt(a*a-x*x); if (y*y+x*x==a*a && b*y%a==0 && b*x%a==0 && b*x/a!=y){ cout<<"YES"
<<endl; cout<<"0 0"<<endl; cout<<x<<' '<<y<<endl; cout<<-b*y/a<<' '<<b*x/a<<endl; return 0; } } cout<<"NO"<<endl; return 0; }

【Codeforces Round #239 (Div. 1) A】Triangle