CodeForces - 407A
| Time Limit: 1000MS | Memory Limit: 262144KB | 64bit IO Format: %I64d & %I64u |
Description
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 Input
1 1
NO
5 5
YES
2 1
5 5
-2 4
5 10
YES
-10 4
-2 -2
1 2
Source
首先要求在平面内找到一个直角三角形,两个边
长分别为a,b,并且三条边都不得与二维坐标轴的
平行,且点都在整数点上,首先这个三角形若是
存在的话,那么它肯定可以在这个平面上平移的
,那么我们把它给移到一二象限,然后一个点固
定在(0,0)点,这样另外两个点看一下 a,b,的范
围,那么另外两个点无非在 一二两个象限内以
(0,0)为端点的 边长为1000的正方形内,在这两
个正方形内 枚举出所有符合的点,分在两个容器
内,然后在枚举两个点 与(0,0)点是否可以组成
直角三角形,是否与坐标轴平行
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
void solve()
{int T,t,n,m,i,j,k,a,b,a1,a2=,b1,b2;
scanf("%d%d",&a,&b);
for(a1=;a1<a;a1++)
{ a2=sqrt(a*a-a1*a1);
if(a*a==a1*a1+a2*a2)
{ b1=a1*b/a;
b2=a2*b/a;
if(b*b==b1*b1+b2*b2 && a2!=b1)
{ printf("YES\n");
printf("0 0\n");
printf("%d %d\n",a1,a2);
printf("%d %d\n",-b2,b1);
return;
}
}
}
printf("NO\n");
}
int main()
{ solve();
}
CodeForces - 407A的更多相关文章
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- CodeForces - 696B Puzzles
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
- CodeForces - 148D Bag of mice
http://codeforces.com/problemset/problem/148/D 题目大意: 原来袋子里有w只白鼠和b只黑鼠 龙和王妃轮流从袋子里抓老鼠.谁先抓到白色老鼠谁就赢. 王妃每次 ...
随机推荐
- 转-Android中自动连接到指定SSID的Wi-Fi
最近在做一个项目,其中涉及到一块“自动连接已存在的wifi热点”的功能,在网上查阅了大量资料,五花八门,但其中一些说的很简单,即不能实现傻瓜式的拿来就用,有些说的很详细,但其中不乏些许错误造成功能无法 ...
- Android基础类之BaseAdapter
转:http://www.cnblogs.com/mandroid/archive/2011/04/05/2005525.html Android基础类之BaseAdapter BaseAdapter ...
- Android Studio使用教程
http://blog.csdn.net/ryantang03/article/details/8948037 http://blog.csdn.net/ryantang03/article/deta ...
- centos 配置固定ip
centos下网络配置方法(网关.dns.ip地址配置) 来源:互联网 作者:佚名 时间:07-13 00:32:07 [大 中 小] 本文介绍了centos网络配置的方法,centos网络配置主要包 ...
- spring属性依赖注入
一.构造方法方式注入 1.项目结构如下: 2.新建Customer类 package hjp.spring.attributeinject; public class Customer { priva ...
- ReactiveCocoa初步
[self.usernameTextField.rac_textSignal subscribeNext:^(id x) { NSLog(@"%@", x); }]; 打印结果 - ...
- ARP欺骗病毒,网页“篡改”,注入iframe代码!
---------------权威资料看这里--------------- 清华大学信息网络工程研究中心-中国教育和科研计算机网应急响应组<ARP 欺骗网页劫持攻击分析>PDF文件,直接I ...
- TFS2008解除独占式锁定文件命令(转载)
使用场景:如果项目团队成员A对项目某个文件以独占式方式签出,恰好那天该成员A没有来上班而成员需要对此文件进入修改并check in,这时需要先把A对该文件的锁定解除.没有IDE可以使用,只能使用下面的 ...
- ASP.NET版Memcached监控工具(转载)
在上一篇文章<使用Memcached提高.NET应用程序的性能>中周公讲述如何在.NET中使用Memcached来提高.NET应用程序的性 能.在实际的使用中有可能出现Memcached因 ...
- Linux 学习笔记(一)
Linux体系结构 下面是Linux体系结构的示意图: 在所有Linux版本中,都会涉及到以下几个重要概念: 内核:内核是操作系统的核心.内核直接与硬件交互,并处理大部分较低层的任务,如内存管理.进程 ...