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. pdsh使用

    原文地址:http://bbs.chinaunix.net/thread-2002080-1-1.html 当我们管理数以十计或者更多的集群系统时,往往需要在每台机器上执行同样的命令,或者拷贝同样的文 ...

  2. 在easyui的treeGrid中添加checkbox(jquery)

    jsp界面,也可用在aspx.html等前台界面中: <script type="text/javascript"> function show(checkid){ v ...

  3. 第九篇.bootstrap导航

    创建一个标签式的导航菜单的步骤是: 在ul标签上加上class  nav 再ul标签上加上 class .nav-tabs. 在li标签上加上 active表示激活该项 <ul class=&q ...

  4. JDBC driver connection string大全

    Database   / data source URL format /   driver name Value Default port MySQL URL format: jdbc:mysql: ...

  5. centos 7 下安装numpy、scipy等python包

    本文适用于刚入门的小白,欢迎大牛们批评指正. 因为要开始数据分析,而python又不像R和matlab那么简洁.需要安装的包很多~ 网上找了好多牛人博客,想在centos7下安装numpy,scipy ...

  6. C++ 之 新式转型操作符

    四种新式转型: const_cast.dynamic_cast.reinterpret_cast.static_cast!! 1.const_cast  :  去除常量性 2.dynamic_cast ...

  7. iOS之数据安全

    一.数据安全 术语----- 密钥:密钥是一种参数, 它是在明文转换为密文, 或将密文转换为明文的算法中输入的参数. 密钥分为对称密钥和非对称密钥(也可以根据用途来分为加密密钥和解密密钥) 明文:没有 ...

  8. Counting Bits(Difficulty: Medium)

    题目: Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate ...

  9. ASP.net封装

    设计如下: 代码: using System; using System.IO; public partial class 四则运算 : System.Web.UI.Page { protected ...

  10. Vue.js常用指令总结

    有时候指令太多会造成记错.记混的问题,所以本文在记忆的时候会采用穿插记忆的方式,交叉比对,不易出错. 本文主要讲了一下六个指令: v-if//v-show//v-else//v-for//v-bind ...