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了,那个 ...
随机推荐
- 两台装有Ubuntu系统的服务器搭建VPN(一台为本地服务器,另一台为云服务器)
我们搭建VPN采用的是openvpn,搭建过程总体需要经过三大步骤: 1.openvpn的安装与配置 2.端口转发 3.系统重启iptables规则自动生效 注意:以下所有名令在ro ...
- CSipSimple的插件结构
CSipSimple的第三方编码器是以插件形式集成的,那么它是怎么实现的?我们以音频编码器为例进行说明. 一.何为插件 工程中有一个包,com.csipsimple.plugins.codecs.从包 ...
- php 错误堆栈
ob_start(); debug_print_backtrace(); $errpr = ob_get_clean();
- JS实现登陆验证的主要代码及思路
window.onload = function(){ // 获取input标签 var alInput = document.getElementsByTagName("input&quo ...
- maven 问题解决 tools以及jconsole两个jar包 无效
在SVN上下载项目,结果完成后出现两个jar包不存在的情况 如下图: 然后,第一步就是去查看POM.xml文件是否配置了这两个文件,结果并没有,于是就更加奇怪了 所以怀疑是不是其他maven下载的ja ...
- Python里的编码问题
马克一篇 http://bbs.chinaunix.net/archiver/tid-1163613.html http://www.openhome.cc/Gossip/Python/ImportI ...
- C#读取大文本文件
今天偶遇一同事抱怨,sqlserver导出的CSV,明明有1000W条,但用excel打开就只剩100W了,足足消失了90%,所以她怀疑文件是足量的1000W条,是excel捣了鬼.可是文件容量有2G ...
- git stash -u 添加新文件
git 提交 有新文件执行 git stash -u ------ 如果已经执行git stash,会发现有UNtracked这个单词 说明新文件没有添加进去,此时 执行 git stash ...
- tomcat中catalina是什么(转)
转自http://blog.sina.com.cn/s/blog_700aa8830101kgbk.html 谢谢博主的总结 catalina 就是Tomcat服务器使用的 Apache实现的serv ...
- WebStorm里面配置运行React Native的方案
以前开发react native项目总是需要打开WebStorm编写代码,Xcode跑项目.显得有点多余. 今天教大家如何直接使用WebStorm这个IDE直接完成编码+运行项目工作.这样就可以不用打 ...