CodeForces 239A. Triangle
Link: http://codeforces.com/contest/407/problem/A
给定直角三角形的2个直角边a,b。求在直角坐标系中,是否存在对应的直角三角形,使得三个定点都在整点上,并且三边都不和坐标轴平行。
如果存在,输出YES,和三个点的坐标。否则输出NO
很显然,为了方便,可以把原点作为 一个顶点。
这道题目做的时候少考虑了很多情况。
比如:
如何使得边不和坐标轴平行? 要保证要求的另外两个点的横坐标或者纵坐标不能相等。
如何保证三角形是直角三角形? 只需要保证,另外两个点和坐标轴围成的三角形相似。
因为范围是1000,所以可以暴力求解。复杂度O(10^6)
/*
* =====================================================================================
* Filename : triangle.cpp
* Description : triangle
* Version : 0.1
* Created : 03/30/14 15:57
* Author : Liu Xue Yang (LXY), liuxueyang457@163.com
* Motto : How about today?
* =====================================================================================
*/
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
/*
* === FUNCTION ======================================================================
* Name: gcd
* Description: gcd
* =====================================================================================
*/
int
gcd ( int a, int b )
{
? a : gcd(b, a % b);
} /* ----- end of function gcd ----- */
/*
* === FUNCTION ======================================================================
* Name: test
* Description: test
* =====================================================================================
*/
void
test ( int xa, int ya, int xb, int yb )
{
if ( xa == xb || ya == yb ) {
return;
}
printf ( "YES\n" );
printf ( "0 0\n" );
printf ( "%d %d\n", xa, ya );
printf ( "%d %d\n", xb, yb );
exit();
return ;
} /* ----- end of function test ----- */
/*
* === FUNCTION ======================================================================
* Name: main
* =====================================================================================
*/
int
main ( int argc, char *argv[] )
{
int a, b;
scanf ( "%d%d", &a, &b );
; x < a; ++x ) {
; y < a; ++y ) {
if ( x * x + y * y == a * a ) {
int g = gcd(x, y);
int dx = x / g, dy = y / g, u = dx * dx + dy * dy;
int v = b * b, ratio = v / u, k = (int)sqrt(ratio) ;
if ( v % u ) {
continue;
}
if ( k * k != ratio ) {
continue;
}
test(x, y, dy * k, -dx * k);
test(x, y, -dy * k, dx * k);
}
}
}
puts("NO");
return EXIT_SUCCESS;
} /* ---------- end of function main ---------- */
这是tourist的代码
CodeForces 239A. Triangle的更多相关文章
- codeforces C. Triangle
C. Triangle time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- 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了,那个 ...
随机推荐
- PostSharp-4.3.22安装包_KeyGen发布
PostSharp-4.3.22安装包_KeyGen发布 请低调使用. 下载相关 PostSharp-4.3.22安装包_KeyGen.part1.rar PostSharp-4.3.22安装包_Ke ...
- 用jQuery Mobile做HTML5移动应用的三个优缺点
JQuery Mobile 和 HTML5 的 3个优点 1. 上手迅速并支持快速迭代:在一个星期多一点的时间里,通过阅读JQuery Mobile文档以及O’Reilly出版的JQuery Mobi ...
- linux test 命令使用
1. 关于某个文件名的『类型』侦测(存在与否),如 test -e filename -e 该『文件名』是否存在?(常用) -f 该『文件名』是否为文件(file)?(常用) -d 该『文件名』是否为 ...
- VMware下利用ubuntu13.04建立嵌入式开发环境之一
1.软件准备: (1) VMware网上很多,需要根据自己的需要选择,这里选用的VMware Workstation 9. (2)ubuntu 操作系统,同样根据自己的需要下载系统安装包.这里我选择 ...
- jquery.get()
1.获取当前jquery对象匹配到的dom元素 2.语法: jqueryObject.get([index]) //jQueryObject[index]等价于jQueryObject.get(ind ...
- css渐变色DIV
<!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> ...
- java反射机制深入详解
java反射机制深入详解 转自:http://www.cnblogs.com/hxsyl/archive/2013/03/23/2977593.html 一.概念 反射就是把Java的各种成分映射成 ...
- MFC之TreeCtrl控件使用经验总结
树形控件可以用于树形的结构,其中有一个根接点(Root)然后下面有许多子结点,而每个子结点上有允许有一个或多个或没有子结点.MFC中使用CTreeCtrl类来封装树形控件的各种操作.通过调用BOOL ...
- Qt5.5中,使MainWindow初始为全屏
MainWindow w; w.showMaximized(); 实例化后,初始显示设置为最大格式即可!
- C语言状态机
转载声明 如果转载本博客内容,请联系869119842@qq.com,获得作者书面授权 前言 状态机的好处不用多说,自己百度去,但传统的编程模式,无论是C语言,或是硬件FPGA的Verilog都是采用 ...