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. 使用SQLite数据库和Access数据库的一些经验总结

    在我的<Winform开发框架>中,可使用多种数据库作为程序的数据源,除了常规的Oracle数据库.SqlServer.MySql数据库,其中还包括了SQLite数据库.Access数据库 ...

  2. 单例(C#版)

    单例: 一个类只有一个实例.巧妙利用了编程语言的一些语法规则:构造函数private, 然后提供一个public的方法返回类的一个实例:又方法和返回的类的实例都是static类型,所以只能被类所拥有, ...

  3. 【JS复习笔记】00 序

    作为一个前端苦手,说是复习,你就当我是重学好了. 好吧,我当然不可能抱着一个砖头去复习,所以捡了本薄的来读——<JavaScript语言精粹>. 当初带我的人说这本书挺好,就看这本书好了. ...

  4. sql2008 查询字段所属表

    select a.name as 表名, g.*from sysobjects as a left join syscolumns as b on a.id=b.id left JOIN sys.ex ...

  5. hibernate初步4

    JPA 1.JPA概述 JPA(Java Persistence API)是Sun官方提出的Java持久化规范.它为Java开发人员提供了一种对象/关系映射工具来管理Java应用中的关系数据.,而Hi ...

  6. svn的管理与维护要点—纯手工编写

    由于在公司要维护阿里云的linux服务器,我们的svn服务器就安在阿里云上面.所以经常会涉及到svn的维护操作.离职的时候编写交接文档,刚好有充足的时间写一篇说明介绍,此说明纯原创,不是从网上复制,手 ...

  7. Android笔记——什么是json?json如何使用?

    什么是json 什么是json,json是什么,json如何使用 JSON是JavaScript Object Notation的缩写,可见JSON来源于JavaScript.JSON数据是一系列键值 ...

  8. Oauth笔记

    上周的工作有安全验证这一块,但不懂,只知道有几个关键字Oauth.secret-key .token.签名等.今天就查下资料做笔记. Oauth是什么 不依靠用户账号和密码就能获得访问资源权限 本质: ...

  9. 关于iChartjs在移动端提示框tip显示不正常的解决方法

    最近项目需要使用手机图表,但是找了很久都没找到专门为移动端开发的图表,只能找一些能兼容移动端的图表控件,今天就讲讲关于iChartjs这个图形库的一点问题. 问题 iChartjs的提示框tip的显示 ...

  10. PHP控制前台弹出对话框

    应用场景: 微信授权登录过程中,需要用户确认,故衍生此需求: 相应的逻辑不放在前端的原因是,此部分逻辑属于偏功能业务,所以放在后端,方便统一管理. 解决办法: 通过php echo出javascrip ...