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. 【C#】线程之Parallel

    在一些常见的编程情形中,使用任务也许能提升性能.为了简化变成,静态类System.Threading.Tasks.Parallel封装了这些常见的情形,它内部使用Task对象. Parallel.Fo ...

  2. 正则表达式相关:C# 抓取网页类(获取网页中所有信息)

    类的代码: using System; using System.Data; using System.Configuration; using System.Net; using System.IO ...

  3. sql联合查询去除重复计算总和

    1.首先来个联合查询 SELECT 字段1, 字段2, 字段3, 字段4 FROM 表1 INNER JOIN 表2 ON 表1.字段x = 表2.字段x x:代表随意的一个,只要在联合查询的两张表都 ...

  4. 【C#进阶系列】00 序

    老早就被各种推荐<CLR via C#>这本书了,然而一直没去学. 因为工作中所需要的.NET功底目前算是足以应付了,而前端却不熟,所以跑去学了一段时间前端的知识. 终于算是把前端方面的基 ...

  5. Urlencode and Urldecode 命令行

    由于经常使用,简单记录之 $ alias urlencode='python -c "import sys, urllib as ul; print ul.quote_plus(sys.ar ...

  6. [PHP] 读取大文件并显示

    使用PHP读取日志文件,当文件比较大的时候,会报内存不足,因此应该部分读取,读取指定的行数的数据 PHP代码: <?php class Test{ //日志路径 const LOG_PATH=& ...

  7. .net学习总结

    .NET 学前入门 了解.Net能做什么 了解.NET,C#语言及其特点(分清.NET和C#的关系),对.Net学习有系统全面的认识. C#基础 变量,赋值运算符.数据类型转换等. 选择结构控制(if ...

  8. RHEL7文件权限

    本文介绍Linux下的文件权限 操作系统为RHEL7.2_X86_64 可以从以下三种访问方式限制访问权限: 1 只允许用户自己访问 2 允许一个预先指定的用户组中的用户访问 3 允许系统中的任何用户 ...

  9. Arcgis for android 离线查询

    参考.. 官方API demo ... 各种资料 以及.. ArcGIS for Android示例解析之高亮要素-----HighlightFeatures ttp://blog.csdn.net/ ...

  10. Upgrading or Redeploying SharePoint 2010 Workflows

    While creating several State Machine SharePoint 2010 workflows using visual studio for a client I ha ...