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了,那个 ...
随机推荐
- Swift 2.0 异常处理
转自:http://www.jianshu.com/p/96a7db3fde00 WWDC 2015 宣布了新的 Swift 2.0. 这次重大更新给 Swift 提供了新的异常处理方法.这篇文章会主 ...
- C#实现Excel的导入导出
Excel作为日常使用工具,在开发过程中经常会用到其导入导出功能.经过一个小的练习,学习了下导入导出功能. 导出篇: 从数据库查询到所要导出的数据,以xml的形势保存下来,最后输出excel的格式,保 ...
- export a java project to runable jar
When a java project needs to be transfered to another machine, e.g. vps, we need to export it to a r ...
- webstorm 10 更改默认端口
快捷键 ctrl + Alt + s :打开配置 如图下可以更改 默认端口.快捷键可能跟qq的快捷键冲突,可以关闭qq来设置端口
- centos 6 安装 gitlib
安装gitlab-----------1. 下载 gitlabcurl -O https://downloads-packages.s3.amazonaws.com/centos-6.5/gitlab ...
- Enterprise Architect 学习 之 用例图
用例模型 用例模型用来记录系统的需求,它提供系统与用户及其他参与者的一种通信手段. 执行者 用例图显示了系统和系统外实体之间的交互.这些实体被引用为执行者.执行者代表角色,可以包括:用户,外部硬件和其 ...
- 火狐浏览器不能获取 event,解决js报错问题
//←的keyCode等于:37 //→的keyCode等于:39 //↑的keyCode等于:38 //↓的keyCode等于:40 function keystoke(obj){ //var e ...
- android studio 2.2.2下fragment的创建和跳转
一,首先,Fragment是android应用中十分重要的一个功能,十分轻量化,也类似于activity一样,是一个个布局,可以相互跳转和传递参数.但是,它运行起来十分流畅,而且易于管理,下面是在学习 ...
- jdk安装及环境变量配置
JDK是 Java 语言的软件开发工具包,主要用于移动设备.嵌入式设备上的java应用程序.JDK是整个java开发的核心,它包含了JAVA的运行环境,JAVA工具和JAVA基础的类库. jdk下载地 ...
- android基础(五)网络编程
android 的网络编程一般可以分为两种:基于Socket的,基于Http的. 一.socket与Http socket封装了TCP/IP协议,TPC/IP协议是传输层协议,主要解决数据如何在网络中 ...