CodeForces 407A-Triangle【模拟】

左手的ㄟ右手 2022-07-24 09:24 237阅读 0赞

A. Triangle

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

There is a right triangle with legs of length a and b. Your task is to determine whether it is possible to locate the triangle on the plane in such a way that none of its sides is parallel to the coordinate axes. All the vertices must have integer coordinates. If there exists such a location, you have to output the appropriate coordinates of vertices.

Input

The first line contains two integers a, b (1 ≤ a, b ≤ 1000), separated by a single space.

Output

In the first line print either “YES” or “NO” (without the quotes) depending on whether the required location exists. If it does, print in the next three lines three pairs of integers — the coordinates of the triangle vertices, one pair per line. The coordinates must be integers, not exceeding 109 in their absolute value.

Examples

input

  1. 1 1

output

  1. NO

input

  1. 5 5

output

  1. YES
  2. 2 1
  3. 5 5
  4. -2 4

input

  1. 5 10

output

  1. YES
  2. -10 4
  3. -2 -2
  4. 1 2
  5. 解题思路:
  6. 题目就是给出两个边长,我们要找到直角三角形的三个点,这个三角形的边不平行于xy轴。
  7. #include<stdio.h>
  8. #include<string.h>
  9. #include<cmath>
  10. #include<algorithm>
  11. using namespace std;
  12. int main()
  13. {
  14. int a,b;
  15. while(scanf("%d%d",&a,&b)!=EOF)
  16. {
  17. int flag=0;
  18. int ax,ay,bx,by;
  19. for(ax=1;ax<a;ax++)
  20. {
  21. for(bx=1;bx<b;bx++)
  22. {
  23. ay=(int)sqrt(a*a-ax*ax);
  24. by=(int)sqrt(b*b-bx*bx);
  25. if(ax*ax+ay*ay==a*a&&bx*bx+by*by==b*b)
  26. {
  27. if(ax*bx==ay*by)
  28. {
  29. if(ax!=bx)
  30. {
  31. flag=1;
  32. break;
  33. }
  34. }
  35. }
  36. }
  37. if(flag)
  38. break;
  39. }
  40. if(!flag)
  41. printf("NO\n");
  42. else
  43. {
  44. printf("YES\n");
  45. printf("0 0\n");
  46. printf("%d %d\n",ax,-ay);
  47. printf("%d %d\n",bx,by);
  48. }
  49. }
  50. return 0;
  51. }

发表评论

表情:
评论列表 (有 0 条评论,237人围观)

还没有评论,来说两句吧...

相关阅读