CodeForces 407A-Triangle

Triangle

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

Output

NO

Input

5 5

Output

YES
2 1
5 5
-2 4

Input

5 10

Output

YES
-10 4
-2 -2
1 2

翻译可以自己百度翻译

思路

在平面中三角形可以平移,就把其中一个坐标规定为(0,0),在这个(0,0)所在的角的两边在一个在第二象限和第一象限。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#define N 10000
using namespace std;
int op=1;
int fa[N][2];
int fb[N][2];
bool deter(int a,int f[][2])//寻找a,b正两条边由哪两个整数组成,如果其中有一个无法组成就返回0;
{
 	 int j=0; 
 	 for(int i=1;i<=a-1;i++)
 	 {
 		int t=a*a-i*i;
  		t=(int)sqrt(t);
  		if(t*t+i*i==a*a)
 		{
   			 f[++j][0]=i*op;
 	 	 	f[j][1]=t;
 		 }
	 }
	 f[0][0]=j;//因为不只有一对,用数组储存下来,f【0】[0]记录对数
	 op=-1;//第一次运行deter函数是横坐标是整数,但第二次运行时是第二象限的边,所以op要变成-1
	 //op的作用就是控制横坐标的整数,也就是第一象限还是第二象限
	 if(j) return 1;
 	return 0;
}
bool det(int a[][2],int b[][2],int x,int y)
{
	 int l1=a[0][0],l2=b[0][0];
	 int cx,cy,c;
	 x*=x;
	 y*=y;
	 for(int i=1;i<=l1;i++)
	 {
	  	for(int j=1;j<=l2;j++)
 		 {
   		 	if(a[i][1]==b[j][1]) continue; //第三条边不能和x轴平行;
   			cx=abs(a[i][0]-b[j][0]);
 		 	cy=abs(a[i][1]-b[j][1]);
  		 	c=cx*cx+cy*cy;//求出第三条边的平方
   		 	if(x+y==c||c==a-b)//第三条边是直角边或者斜边
   		 	{
  			  	printf("YES\n"); 
  			  	printf("0 0\n");
   			  	printf("%d %d\n",a[i][0],a[i][1]);
    			  	printf("%d %d",b[j][0],b[j][1]);
   			  	return 0;//找到一个就直接结束函数
  		 	}
  		}
	 }
	 return 1;
}
int main()
{
 	int a,b,t;
 	scanf("%d%d",&a,&b);
 	if(a<b)
 	{
  	t=a;
  	a=b;
  	b=t; 
 	}
 	if(deter(a,fa)&&deter(b,fb))//进入的条件是:两条边都找到了合适的整数;
 	{
     		if(det(fa,fb,a,b))//如果不合适,则det函数返回值是1,说明没找到;
   		  printf("NO");
  	} 
  	else printf("NO");
  return 0;
} 
还有哪里不会,欢迎下方留言。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值