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. ADO.NET学习系列(一)

    一.ADO.NET基础 程序和数据库交互,要通过ADO.NET进行:通过ADO.NET就能在数据库中执行SQL了.ADO.NET中提供了对不同数据库的统一操作接口(ODBC).另外还有一种操作数据库的 ...

  2. C#设计模式——代理模式(Proxy Pattern)

    一.概述在软件开发中,有些对象由于创建成本高.访问时需要与其它进程交互等原因,直接访问会造成系统速度慢.复杂度增大等问题.这时可以使用代理模式,给系统增加一层间接层,通过间接层访问对象,从而达到隐藏系 ...

  3. MVC应用程序实现上传文件

    学习MVC以来,一直想实现上传文件的功能,使用jQuery来实现上传,有很多插件.此篇演示中,Insus.NET是使用Uploadify.http://www.uploadify.com/,它有更多的 ...

  4. 【iOS】线程安全的文件读写

    前段时间看了一遍GCD(Grand Central Dispatch)多线程,GCD是苹果为多核开发提供的解决方案 多线程最常见的问题就是读写,比如数据库读写,文件读写,读取是共享的,写是互斥,允许多 ...

  5. ASP.NET 使用AJAX让GridView的数据行显示提示框(ToolTip)

    介绍ASP.NET AJAX可以使你的web应用程序具有更丰富的功能和更多的用户响应. 本文中,我将演示如何通过ASP.NET AJAX的帮助,给像GridView这样的数据绑定控件的数据行增加pop ...

  6. C++隐藏规则

    在面向对象的开发过程中,经常出现类的继承,这里面出现的成员函数的重载(overload).覆盖(override)与隐藏(hidden)很容易混淆. 首先澄清这3个概念: 重载 相同的范围(在同一个类 ...

  7. DataSet与DataTable对象

    DataSet与DataTable对象 摘自:http://www.cnblogs.com/fttbfttb/articles/1509662.html DataSet对象 DataSet是ADO.N ...

  8. vs2012中编译时出现程序集所使用的版本高于所引用的版本

    我在运行别人的项目时出现版本不兼容的问题:

  9. sql多行转一行,以逗号隔开

    --SELECT ff= stuff((select ','+cast(WorkOrderNo as varchar)-- FROM dbo.TB_WorkOrder c -- where tpl.P ...

  10. mongodb学习4---索引

    1,mongodb的性能分析 db.active.find({id:'sdfasdf6jh67j353g346hkfgh6'}).explain('executionStats') "mil ...