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了,那个 ...
随机推荐
- ios 真机调试 could not find Developer Disk Image
同事不小心把iphone测试机升级到了最新系统, 真机调试以前的项目时候不能运行, 提示could not find Developer Disk Image. 原因:缺少最新系统9.3的镜像 解决办 ...
- inside the C++ Object model总结
一. 关于对象 1.内联函数:能够除去函数调用的开支,每一处内联函数的调用都是代码的复制.这是一种空间换取时间的做法,若函数代码量大或者有循环的情况下,不宜内联(这件事有些编译器会自动帮你做).在类中 ...
- nginx url重定向
nginx内部支持url rewrite,内部编译进去了rewrite模块,nginx的rewrite模块类似于apache的rewriterule功能:支持多种规则和正则表达式: 详细介绍如下: N ...
- php session的操作
[设置session数据] <?php session_start(); //初始化 //session文件中可以保存 dobule,integer,bool,array,object $_SE ...
- Xcode 7如何 免费 真机调试iOS应用
运行Xcode后,点击菜单中的Preferences…进入Accounts标签,这里选择添加Apple ID: 在弹出的对话框中登入你的Apple ID,没有的话去注册一个就是了,登录成功后会看到下面 ...
- KTV项目 SQL数据库的应用 结合C#应用窗体
五道口北大青鸟校区 KTV项目 指导老师:袁玉明 歌曲播放原理 SQL数据库关系图 C#解决方案类图 第一步:创建数据库连接方法和打开方法和关闭方法! public class DBHelper { ...
- .Net读取Excel文件时丢失数据的问题 (转载)
相信很多人都试过通过OleDB读取Excel文件,这种方法效率十分高,只是有一点会让人十分头痛,就是当一列中既有混合型数据,又有纯数据时,往往容易丢失数据. 百度过后,改连接字符串 “HDR=YES; ...
- 搭建java开发环境、使用eclipse编写第一个java程序
搭建java开发环境.使用eclipse编写第一个java程序 一.Java 开发环境的搭建 1.首先安装java SDK(简称JDK). 点击可执行文件 jdk-6u24-windows-i586. ...
- 一、Android屏幕的计量单位
px :是屏幕的像素点in :英寸mm:毫米pt :磅,1/72英寸dp :一个基于density的抽象单位,如果一个160dpi的屏幕,1dp=1pxdip :等同于dpsp :同dp ...
- jfinal和httl结合
一导入jar包 二配置web.xml文件 三配置httl.properties文件 此时会出现如下问题: 解决办法: 加入 javassist-3.15.0-GA.jar包 再运行会有如下警告 解决办 ...