C. 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.

Sample test(s)
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


#include "stdio.h"
#include "string.h"
#include "math.h"
#include "vector"
using namespace std; struct node
{
int x,y;
}; vector<node> a[1005]; bool change(int x1,int y1,int x2,int y2)
{
bool flag = true;
if (-x1*x2+y1*y2==0 && y1!=y2) { printf("YES\n%d %d\n%d %d\n%d %d\n",0,0,-x1,y1,x2,y2); }
else if(-x1*y2+y1*x2==0 && y1!=x2) { printf("YES\n%d %d\n%d %d\n%d %d\n",0,0,-x1,y1,y2,x2); }
else if(-y1*x2+x1*y2==0 && x1!=y2) { printf("YES\n%d %d\n%d %d\n%d %d\n",0,0,-y1,x1,x2,y2); }
else if(-y1*y2+x1*x2==0 && x1!=x2) { printf("YES\n%d %d\n%d %d\n%d %d\n",0,0,-y1,x1,y2,x2); }
else
flag = false;
return flag;
} int main()
{
int i,j;
int x,y;
int ans,num;
node cur;
for(i=1; i<=1000; ++i)
{
for(j=i; j<=1000; ++j)
{
ans = (int)sqrt(i*i+j*j);
if(ans > 1000) continue;
if(ans*ans==i*i+j*j)
{
cur.x = i;
cur.y = j;
a[ans].push_back(cur);
}
}
}
bool flag = false;
scanf("%d %d",&x,&y);
for(i=0; i<a[x].size(); i++)
{
for(j=0; j<a[y].size(); j++)
{
if( change(a[x][i].x,a[x][i].y,a[y][j].x,a[y][j].y) )
{
flag = true;
break;
}
}
if(flag) break;
}
if(!flag)
printf("NO\n");
return 0;
}

codeforces C. Triangle的更多相关文章

  1. CodeForces 239A. Triangle

    Link:  http://codeforces.com/contest/407/problem/A 给定直角三角形的2个直角边a,b.求在直角坐标系中,是否存在对应的直角三角形,使得三个定点都在整点 ...

  2. codeforces 6A. Triangle

    A. Triangle time limit per test 2 seconds memory limit per test 64 megabytes input standard input ou ...

  3. CodeForces - 18A Triangle(数学?)

    传送门 题意: 给出三个点的坐标,初始,这三个点可以构成一个三角形. 如果初始坐标可以构成直角三角形,输出"RIGNT". 如果某个点的 x或y 坐标移动一个单位后可以组成直角三角 ...

  4. [Codeforces 15E] Triangle

    Brief Introduction: 求从N出发,回到N且不包含任何黑色三角的路径数 Algorithm:假设从N点到第二层中间的节点M的路径数为k,易知总路径数为(k*k+1)*2 而从第第四层开 ...

  5. Codeforces Round #396 (Div. 2) B. Mahmoud and a Triangle 贪心

    B. Mahmoud and a Triangle 题目连接: http://codeforces.com/contest/766/problem/B Description Mahmoud has ...

  6. Codeforces Beta Round #6 (Div. 2 Only) A. Triangle 水题

    A. Triangle 题目连接: http://codeforces.com/contest/6/problem/A Description Johnny has a younger sister ...

  7. Codeforces Round #396 (Div. 2) A - Mahmoud and Longest Uncommon Subsequence B - Mahmoud and a Triangle

    地址:http://codeforces.com/contest/766/problem/A A题: A. Mahmoud and Longest Uncommon Subsequence time ...

  8. 【codeforces 766B】Mahmoud and a Triangle

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  9. codeforces A. Vasily the Bear and Triangle 解题报告

    题目链接:http://codeforces.com/problemset/problem/336/A 好简单的一条数学题,是8月9日的.比赛中没有做出来,今天看,从pupil变成Newbie了,那个 ...

随机推荐

  1. 重构第27天 去除上帝类(Remove God Classes)

    理解:本文中的”去除上帝类”是指把一个看似功能很强且很难维护的类,按照职责把自己的属性或方法分派到各自的类中或分解成功能明确的类,从而去掉上帝类. 详解:我们经常可以在一些原来的代码中见到一些类明确违 ...

  2. istView的项移除

    如标题所言,是做删除ListView绑定项的功能的:鉴于这个功能当时确实花费了很多时间,并且网上也找不到删除所需的案例,所以,我就做了一份案例,仅供各位前辈和同行进行参考,如有不当之处,还望指点,我将 ...

  3. 解决打印机报错:操作无法完成(错误0x00000709)。

    解决:操作无法完成(错误0x00000709).再次检查打印机名称,并确保打印机已连接到... 上午同时说,网络打印机打印不了,于是首先看一下打印服务器IP是不是给换了,结果没换. 接着尝试重新添加一 ...

  4. 深入.NET内测题

    一 选择题 1)      以下关于序列化和反序列化的描述错误的是( C). a)      序列化是将对象的状态存储到特定存储介质中的过程 b)      二进制格式化器的Serialize()和D ...

  5. 泛函编程(14)-try to map them all

    虽然明白泛函编程风格中最重要的就是对一个管子里的元素进行操作.这个管子就是这么一个东西:F[A],我们说F是一个针对元素A的高阶类型,其实F就是一个装载A类型元素的管子,A类型是相对低阶,或者说是基础 ...

  6. ahjesus 部署lighttpd

    这个就不写了,直接传送门过去看,按照说的做就可以了 如果你想要安装最新版的,传送门 需要注意的是configure这一步,你看完他的help以后还要输入 ./configure 才能继续下一步 再就是 ...

  7. DWR的Reverse Ajax技术实现

    DWR的逆向ajax其实主要包括两种模式:主动模式和被动模式.其中主动模式包括Polling和Comet两种,被动模式只有Piggyback这一种. 所谓的Piggyback指的是如果后台有什么内容需 ...

  8. ajax跨子域请求的两种现代方法

    因为面向互联网的性质,我们公司的大部分系统都采用多子域的方式进行开发和部署,以达到松耦合和分布式的目的,因此子系统间的交互不可避免.虽然通过后台的rpc框架解决了大部分的交互问题,但有些情况下,前端直 ...

  9. C#常用集合的使用(转载)

    大多数集合都在System.Collections,System.Collections.Generic两个命名空间.其中System.Collections.Generic专门用于泛型集合. 针对特 ...

  10. [iOS] 使用xib作为应用程序入口 with IDE

    [iOS] 使用xib作为应用程序入口 with IDE 在「使用xib做为应用程序入口 with Code」这篇文章中,介绍了如何透过写Code的方式,来使用xib做为应用程序的入口.但其实在Xco ...