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. jquery实现checkbox全选和全部取消,以及获取值

    在后台管理中经常会遇到列表全选和取消的功能,如评论审核.申请等,用到的html标记就是checkbox.我用的是mysql数据库,代码如下: <!DOCTYPE html PUBLIC &quo ...

  2. Ant介绍

    今天介绍一下Ant,Ant是基于Java的跨平台构建工具,它易于使用,并且可扩展.可升级.它既可以用于小的个人项目,也可以用于大型的.多组协同的软件项目. 在我们的项目开发中,为了构建一个软件产品,我 ...

  3. java多线程系列之 synchronized

    一.synchronized基本原理 java的内置锁:每个java对象都可以用做一个实现同步的锁,这些锁成为内置锁.线程进入同步代码块或方法的时候会自动获得该锁,在退出同步代码块或方法时会释放该锁. ...

  4. Ubuntu下freeradius-server的安装

    一.安装 (1)更新 #apt-get update (2)下载 链接:ftp://ftp.freeradius.org/pub/freeradius/freeradius-server-2.2.9. ...

  5. Android性能优化之使用线程池处理异步任务

    转:http://blog.csdn.net/u010687392/article/details/49850803

  6. JAVA编程讲座-吴老

    JAVA系列公开课第4讲:多态系列课程:从JAVA编程零基础讲起,同时结合工作中遇到的具体实例,语言清晰易懂,连续10周+深入讲解,打下编程基础,让我们一起打来自动化测试的大门时间:4月25日(周一) ...

  7. 关于ios “<null>”的异常处理

    在iOS开发过程中经常需要与服务器进行数据通讯,但是在数据接通过程中会出现:null "<null>"等问题导致莫名其妙的崩溃. 相信你一定会写各种判断来处理这些异常, ...

  8. 《java小应用程序(Applet)和java应用程序(Application)分别编写的简单计算器》

    Application和Java Applet的区别.Java语言是一种半编译半解释的语言.Java的用户程序分为两类:Java Application和Java Applet.这两类程序在组成结构和 ...

  9. 大视野3562 [SHOI2014]神奇化合物

    http://www.lydsy.com/JudgeOnline/problem.php?id=3562 //Accepted 6020 kb 1012 ms //由于题目的特殊要求:然而,令科学家们 ...

  10. 64位系统下找不到office 32位组件

    如果系统式64位的,而装的是32位的office软件,在运行栏中输入命令:dcomcnfg,打开组件服务管理窗口,但是却发现找不到Microsoft Excel程序, 这主要是64位系统的问题,exc ...