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. SpringMVC与MyBatis整合之日期格式转换

    在上一篇博客<SpringMVC与MyBatis整合(一)——查询人员列表>中遗留了日期格式转换的问题,在这篇记录解决过程. 对于controller形参中pojo对象,如果属性中有日期类 ...

  2. LightOJ 1104

    题意: 给你一年有n天,求至少有m人使得至少有两个人在同一天生日的概率不少于0.5. 分析: 任意两个人不在同一天生日的概率为C(n,m)*m!/n^m,它的对立事件A为至少有两个人在同一天生日, 则 ...

  3. C#实现Excel的导入导出

    Excel作为日常使用工具,在开发过程中经常会用到其导入导出功能.经过一个小的练习,学习了下导入导出功能. 导出篇: 从数据库查询到所要导出的数据,以xml的形势保存下来,最后输出excel的格式,保 ...

  4. 把本地代码同步到github

    2016-05-03 12:52:00 把代码同步到远程github,还算比较顺利.主要参考了以下两个博客,谢谢 http://blog.csdn.net/duxinfeng2010/article/ ...

  5. swift 定位

    iOS 8 及以上需要在info.plist文件中添加下面两个属性 NSLocationWhenInUseUsageDescription 使用应用期间 NSLocationAlwaysUsageDe ...

  6. Scala深入浅出实战经典-----002Scala函数定义、流程控制、异常处理入门实战

    002-Scala函数定义.流程控制.异常处理入门实战 Scala函数定义 语句结束无分号 定义无参函数 def 函数名称(参数名称:参数类型)[:Unit=]{ 函数体 } 老师的代码 我的实际代码 ...

  7. PHP store session with couchbase

    如何用couchbase存储session 有两种常见方式:1.采用memcache模式连接couchbase 只需两句修改: ini_set('session.save_handler', 'mem ...

  8. 《java异常的一些总结》

    关于Java中异常的一些总结: 3 有些时候,程序在try块里打开了一些物理资源(例如数据库连接,网络连接. 4 和磁盘文件等),这些物理资源都必须显示回收. 5 6 注意:Java的垃圾回收机制不会 ...

  9. servlet(1)

    一.Servlet简介 Servlet是sun公司提供的一门用于开发动态web资源的技术. Sun公司在其API中提供了一个servlet接口,用户若想用发一个动态web资源(即开发一个Java程序向 ...

  10. 统计字符串”aaaabbbccccddfgh”中字母个数以及统计最多字母数

    function count(){ var str="shhkfahkahsadhadskhdskdha"; var obj={}; for(var i=0;i<str.le ...