codeforces C. Triangle
1 second
256 megabytes
standard input
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.
The first line contains two integers a, b (1 ≤ a, b ≤ 1000),
separated by a single space.
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.
1 1
NO
5 5
YES
2 1
5 5
-2 4
5 10
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的更多相关文章
- CodeForces 239A. Triangle
Link: http://codeforces.com/contest/407/problem/A 给定直角三角形的2个直角边a,b.求在直角坐标系中,是否存在对应的直角三角形,使得三个定点都在整点 ...
- codeforces 6A. Triangle
A. Triangle time limit per test 2 seconds memory limit per test 64 megabytes input standard input ou ...
- CodeForces - 18A Triangle(数学?)
传送门 题意: 给出三个点的坐标,初始,这三个点可以构成一个三角形. 如果初始坐标可以构成直角三角形,输出"RIGNT". 如果某个点的 x或y 坐标移动一个单位后可以组成直角三角 ...
- [Codeforces 15E] Triangle
Brief Introduction: 求从N出发,回到N且不包含任何黑色三角的路径数 Algorithm:假设从N点到第二层中间的节点M的路径数为k,易知总路径数为(k*k+1)*2 而从第第四层开 ...
- 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 ...
- Codeforces Beta Round #6 (Div. 2 Only) A. Triangle 水题
A. Triangle 题目连接: http://codeforces.com/contest/6/problem/A Description Johnny has a younger sister ...
- 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 ...
- 【codeforces 766B】Mahmoud and a Triangle
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- codeforces A. Vasily the Bear and Triangle 解题报告
题目链接:http://codeforces.com/problemset/problem/336/A 好简单的一条数学题,是8月9日的.比赛中没有做出来,今天看,从pupil变成Newbie了,那个 ...
随机推荐
- 脊柱外科病人资料管理系统的界面设计分析(2)--JOA评分记录的实现
在上篇随笔<脊柱外科病人资料管理系统的界面设计分析>中介绍了一些常用的界面设计方面的内容,本篇继续上一篇,介绍脊柱外科病人管理系统的JOA评分记录模块的界面设计以及实现方面的内容. JOA ...
- sql server索引功能资料
无论何时对基础数据执行插入.更新或删除操作,SQL Server 数据库引擎都会自动维护索引.随着时间的推移,这些修改可能会导致索引中的信息分散在数据库中(含有碎片).当索引包含的页中的逻辑排序(基于 ...
- Azure开发者任务之一:解决Azure Storage Emulator初始化失败
初学Windows Azure: 我打算开始学习Windows Azure.我安装了Azure SDK,然后在“Cloud”标签下选择Windows Azure模板,创建了一个项目,然后又创建了一个W ...
- Java、Hibernate(JPA)注解大全
1.@Entity(name=”EntityName”) 必须,name为可选,对应数据库中一的个表 2.@Table(name=””,catalog=””,schema=””) 可选,通常和@Ent ...
- PHP遍历目录四种方法
学习SPL的时候,遇到了DirectoryIterator这个目录类,谢了一下遍历目录的方法.于是总结一下遍历目录的四种写法 如下: <?php /* * 方法一:利用SPL的目录类,这个很简单 ...
- [Windows Phone] APP上架,遇到错误2001的解决方案。(Error:2001)
[Windows Phone] APP上架,遇到错误2001的解决方案.(Error:2001) 问题情景 最近在开始玩Windows Phone的开发,开发的过程中虽然有点小挫折,但是参考网络许多前 ...
- (七)play之yabe项目【CRUD】
(七)play之yabe项目[CRUD] 博客分类: 框架@play framework 增加CRUD功能 使用CRUD能干嘛?----> 在页面对模型进行增删改查操作,这样有什么实际意义 ...
- js事件小记
参考javascript编程全解 javascript高级程序设计 javascript经典实例 对事件的处理方式称为事件处理程序或事件侦听器 ,对于一个元素或事件,只能设定1个事件处理程序,却可以 ...
- Javascript的一种代码结构方式——插件式
上几周一直在做公司的webos的前端代码的重构,之中对javascript的代码进行了重构(之前的代码耦合严重.拓展.修改起来比较困难),这里总结一下当中使用的一种代码结构——插件式(听起来怎么像独孤 ...
- 【使用 DOM】使用 Window 对象
1. 获取 Window 对象 可以用两种方式获得Window对象.正规的HTML5方式是在Document对象上使用defaultView属性.另一种是使用所有浏览器都支持的全局变量window . ...