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了,那个 ...
随机推荐
- hdu 1159, LCS, dynamic programming, recursive backtrack vs iterative backtrack vs incremental, C++ 分类: hdoj 2015-07-10 04:14 112人阅读 评论(0) 收藏
thanks prof. Abhiram Ranade for his vedio on Longest Common Subsequence 's back track search view in ...
- 让powershell同时只能运行一个脚本(进程互斥例子)
powershell,mutex,互斥,进程互斥,脚本互斥 powershell脚本互斥例子,在powershell类别文章中,声明原创唯一. powershell 传教士 原创文章 2016-07- ...
- mybatis的mapper中,实体非空检验问题
因为项目变动,数据库需要删除一个字段,于是勤劳的我把项目中对应的实体属性也给弄掉了,可是没有弄彻底,mybatis里面的mapper没有管,当时感觉是选择性的插入: <if test=" ...
- Makefile 一点一滴(一)—— 从最简单的makefile模板写起
我在网上先找了一个最简单的makefile. 建立一个 TestCpp 目录,简单的写几行代码,命名为“TestCpp.cpp”,然后和这个最简单的 makefile 一起扔进去: TestCpp.c ...
- 同上 遍历obj的值 来定义当前的后台数据在页面的定位
function getlistRoom(obj) { //obj就是通过ajax传过来的 data for (var i = 0; i < obj.length; i++) {//遍历数据 v ...
- C/C++函数调用的几种方式及函数名修饰规则以及c++为什么不允许重载仅返回类型不同的函数
我们知道,调用函数时,计算机常用栈来存放函数执行需要的参数,由于栈的空间大小是有限的,在windows下栈是向低地址扩展的数据结构,是一块连续的内存区域.这句话的意思是栈顶的地址和栈的最大容量是系统预 ...
- iOS 为移动中的UIView(UIButton )添加点击事件
高高兴兴迎接新的产品新需求,满心欢喜的开始工作,结果研究了一下午才发现,是自己想的太简单了,是我太单纯呀. 需求是这样的类似下雪的效果,随机产生一些小雪花,然后每个雪花可以点击到下个页面. 接到需求之 ...
- 关闭键盘导致tableView:didSelectRowAtIndexPath:失效解决办法
今天公司的小兄弟问了tableView:didSelectRowAtIndexPath:不能执行的问题. 从经验看觉得可能是控制器没有成为tableView的代理所致.但代码中已经添加了代码 _tab ...
- 关于ios “<null>”的异常处理
在iOS开发过程中经常需要与服务器进行数据通讯,但是在数据接通过程中会出现:null "<null>"等问题导致莫名其妙的崩溃. 相信你一定会写各种判断来处理这些异常, ...
- fushioncharts 使用教程要点---使用JSON数据方式
1.建立图表步骤: A.下载fushionChart,引入FusionCharts.js和FusionChartsExportComponent.js文件 B.建立图表对象 var chart1 = ...