407A - Triangle - CodeForces Solution


brute force geometry implementation math *1600

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
#include <unordered_map>
 
using namespace std;
 
#define endl '\n'
#define ll long long
#define int long long
#define ld  long double
const int32_t INFint = 1e9;
const ll INFll = 1e18;
const ll INF = 9e18;
const ld PI = acos(-1);
const int MOD = 998244353;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define vi vector < int >
#define vii vector < vector < int > >
#define pii pair < int , int >
#define pb push_back


 
int powersOfTwo[31] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824};
int power(int x, int y){ int r = 1; while(y>0){ if(y&1) r = r * x; y = y >> 1; x = x * x; } return r; }

 
#define loop(i,a,b) for (int i = a; i < b; i++)
#define all(arr) arr.begin(),arr.end()
#define rall(arr) arr.rbegin(),arr.rend()
#define gll(a,n) for(ll i=0;i<n;i++) cin>>a[i];
#define input(arr) for(int i=0;i<arr.size();i++) cin>>arr[i];
#define show(a) {int n=a.size(); for(int i=0;i<a.size();i++) {cout << a[i] << " ";} cout << endl;}
#define nl cout << endl
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
//---------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------- 


//power function
int binpow(int a, int b, int m) {
    a %= m;
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

//euclidean gcd
ll gcd (ll a, ll b) {
    return b ? gcd (b, a % b) : a;
}

//least common multiple
int lcm (int a, int b) {
    return a / gcd(a, b) * b;
}

//factorial of n
ll fact(ll n){
    if(n==0)
      return 1;
    ll res = 1;
    for (ll i = 2; i <= n; i++)
        res = (res * i)%MOD;
    return res;
}

//sieve
vector<int> sieve(int n){
    //int n;
    vector<bool> is_prime(n+1, true);
    vector<int> prime;
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i <= n; i++) {
        if(is_prime[i]) prime.pb(i);
        if (is_prime[i] && (long long)i * i <= n) {

            for (int j = i * i; j <= n; j += i)
                is_prime[j] = false;
        }
    }
    return prime;
}
//---------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------- 

 



 
int i;
struct values{
  int health,attack,defence;
};

void solution(){
 int a,b;
 cin>>a>>b;
 vii va,vb;
 for(int x=1;x<a;x++){
  int y = sqrt(a*a - x*x);
  if(y*y+x*x == a*a){
    va.pb({x,y});
  }
 }
 for(int x=1;x<b;x++){
  int y = sqrt(b*b - x*x);
  if(y*y+x*x == b*b){
    vb.pb({x,y});
  }
 }
 for(int i=0;i<va.size();i++){
  for(int j=0;j<vb.size();j++){
    //cout<<(va[i][0])<<" "<<va[i][1]<<" "<<vb[i][0]<<" "<<vb[i][1]<<endl;
    if(va[i][0]*vb[j][1] == va[i][1]*vb[j][0]  && vb[j][0]!=va[i][1]){
      cout<<"YES"<<endl;
      cout<<"0 0\n"<<(-1*va[i][0])<<" "<<va[i][1]<<"\n"<<vb[j][1]<<" "<<vb[j][0]<<endl;
      return;
    }
  }
 }
 cout<<"NO"<<endl;
}


int32_t main(){
  fast;
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	
	int tt = 1;
	//cin >> tt;
	while(tt--){
			solution();
	}
	printclock;
}


Comments

Submit
0 Comments
More Questions

Two Strings
Anagrams
Prime Number
Lexical Sorting Reloaded
1514A - Perfectly Imperfect Array
580A- Kefa and First Steps
1472B- Fair Division
996A - Hit the Lottery
MSNSADM1 Football
MATCHES Playing with Matches
HRDSEQ Hard Sequence
DRCHEF Doctor Chef
559. Maximum Depth of N-ary Tree
821. Shortest Distance to a Character
1441. Build an Array With Stack Operations
1356. Sort Integers by The Number of 1 Bits
922. Sort Array By Parity II
344. Reverse String
1047. Remove All Adjacent Duplicates In String
977. Squares of a Sorted Array
852. Peak Index in a Mountain Array
461. Hamming Distance
1748. Sum of Unique Elements
897. Increasing Order Search Tree
905. Sort Array By Parity
1351. Count Negative Numbers in a Sorted Matrix
617. Merge Two Binary Trees
1450. Number of Students Doing Homework at a Given Time
700. Search in a Binary Search Tree
590. N-ary Tree Postorder Traversal