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的更多相关文章

  1. codeforces C. Triangle

    C. Triangle time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...

  2. codeforces 6A. Triangle

    A. Triangle time limit per test 2 seconds memory limit per test 64 megabytes input standard input ou ...

  3. CodeForces - 18A Triangle(数学?)

    传送门 题意: 给出三个点的坐标,初始,这三个点可以构成一个三角形. 如果初始坐标可以构成直角三角形,输出"RIGNT". 如果某个点的 x或y 坐标移动一个单位后可以组成直角三角 ...

  4. [Codeforces 15E] Triangle

    Brief Introduction: 求从N出发,回到N且不包含任何黑色三角的路径数 Algorithm:假设从N点到第二层中间的节点M的路径数为k,易知总路径数为(k*k+1)*2 而从第第四层开 ...

  5. 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 ...

  6. Codeforces Beta Round #6 (Div. 2 Only) A. Triangle 水题

    A. Triangle 题目连接: http://codeforces.com/contest/6/problem/A Description Johnny has a younger sister ...

  7. 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 ...

  8. 【codeforces 766B】Mahmoud and a Triangle

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  9. codeforces A. Vasily the Bear and Triangle 解题报告

    题目链接:http://codeforces.com/problemset/problem/336/A 好简单的一条数学题,是8月9日的.比赛中没有做出来,今天看,从pupil变成Newbie了,那个 ...

随机推荐

  1. MFC-01-Chapter01:Hello,MFC---1.2 MFC简介

    1.2 MFC简介 MFC是Microsoft提供的放置Windows API的面向对象的包装的C++类库.MFC大约封装了好几百个类,其中有一些可以直接调用,有些类可以作为用户自己的类的基类.一些M ...

  2. 用Mockito mock普通的方法

    上面的例子是很理想化的状态,但是在实际的开发中,我们需要经常调用一些依赖特定环境的函数或者调用同事写的代码,而同事仅提供了接口.这个时候就需要利用Mockito来协助我们完成测试. 当然,你可以选择e ...

  3. Y+的一些讨论

    一.关于 fluent计算时壁面函数法和网格的关系,还有一个小问题 1:各位用 fluent的同仁和高手们,我想要比较好的使用 fluent软件,最重要的就是要学好理 论,在这里我想请教各位一个问题, ...

  4. AX2012自定义注释脚本开发

    废话少说,直接进入主题: 1.在类xppSource中增加一个类似的方法: eg. Source ifElse(Source _condition = '', Source _ifStatement ...

  5. Kindle使用的一些方法

    最大的好处就是方便,买书便宜,到手我就买了六部书,十块钱不到,以纸书的价格一本都买不到,能够买一些一直想读一下,但又担心读不下去的书.而且买了之后完全不用担心书柜收纳不下了.另外很轻便,放在包里上下班 ...

  6. jQuery原生框架-----------------属性操作

    // 添加一个处理兼容获取样式的静态方法jQuery.getStyle = function( dom, styleName ) { // dom不是dom,styleName不是字符串,直接打走 i ...

  7. 一定要在主线程更新UI

    在一些技术交流群里面,一些初学者(我表示我也是其中一人),总是会发现,为什么我UIView的animate方法,不会动!而是直接闪? 这是为什么呢? 一定要在主线程中更新UI! 一定要在主线程中更新U ...

  8. form input file 图片上传360IE兼容问题

    <form action="" class="form-box" class="form_box" enctype="mul ...

  9. The Pragmatic Programmer Quick Reference Guide

    1.关心你的技艺 Care About Your Craft 如果不在乎能否漂亮地开发出软件,你又为何要耗费生命去开发软件呢? 2.思考!你的工作 Think! About Your Work 关掉自 ...

  10. Javascript的函数自调

    嗯 也不知道怎么翻译self-invoked,就当自调吧. 在看bootstrap的轮播插件源码的时候发现一种新的自调函数的写法(其实应该不新了),开头的一段就卡住了,原谅我是个菜鸟,就顺便记录一下. ...