Codeforces Round #239 (Div. 2), problem: (C) Triangle editorial: http://codeforces.com/blog/entry/11333
Codeforces Round #239 (Div. 2), problem: (C) Triangle solution: http://ideone.com/KVM6Cb
#include <iostream> #include <cstdio> #include <cmath> using namespace std; int gcd(int u, int v) { if(u==v) return u; if(u==0) return v; if(v==0) return u; if(~u & 1) { if(v & 1) return gcd(u>>1, v); else return gcd(u>>1, v>>1)<<1; } if(~v & 1) return gcd(u, v>>1); if(u>v) return gcd((u-v)>>1, v); return gcd((v-u)>>1, u); } int main() { int a, b, x, y, g, Bx, By, B; scanf("%d%d", &a, &b); for(int i=0; i<a; i++) { for(int j=0; j<a; j++) { if(pow(i, 2) + pow(j, 2)==pow(a, 2)) { x=i, y=j; g=gcd(x, y); Bx=-y/g; By=x/g; B=sqrt(pow(Bx, 2) + pow(By, 2)); if(b%B==0 && sqrt(pow(By*b/B-y, 2))!=0 && sqrt(pow(Bx*b/B-x, 2))!=0) { printf("YES\n"); printf("0 0\n"); printf("%d %d\n", x, y); printf("%d %d\n", Bx*b/B, By*b/B); return 0; } } } } printf("NO"); return 0; }
note: the above code is my solution based on the editorial. you can have a look for another sol's also. i like the below solutions also. check other's codes if you dont get editorial well.
By BigChampion, contest: Codeforces Round #239 (Div. 1), problem: (A) Triangle, Accepted, #
#include <cstdio> using namespace std; int gcd(int x,int y) { if (!y) return x; return gcd(y,x%y); } int main() { int a,b,x=0,y,i,j; scanf("%d%d",&a,&b); int g=gcd(a,b); for (i=1;i<g;i++) for (j=1;j<g;j++) if ((i*a!=j*b)&&(i*i+j*j==g*g)) x=i,y=j; if (!x) {printf("NO\n"); return 0;} printf("YES\n"); printf("1 1\n%d %d\n%d %d\n",1+a/g*x,1+a/g*y,1+b/g*y,1-b/g*x); return 0; }
By ehsan.m.a.e, contest: Codeforces Round #239 (Div. 2), problem: (C) Triangle, Accepted, #
#include<iostream> #include <cmath> using namespace std; int main() { int a,b,i,a2; float t,ta,tb; cin>>a>>b; a2=a*a; for(i=1;i<a;i++) { t=sqrt(a2-i*i); if(t-(int)t==0) { ta=-1*(b*t)/a; tb=(b*i)/a; if(ta-(int)ta==0 && tb-(int)tb==0 && tb!=t) { cout<<"YES\n0 0\n"<<i<<" "<<t<<"\n"<<ta<<" "<<tb; return 0; } } } cout<<"NO"; return 0; }
No comments:
Post a Comment