#1040 : 矩形判断
2015-09-12 09:37
190 查看
我觉得测试用例可能很少很easy
import java.awt.Point; import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner scanner = new Scanner(System.in); int T = scanner.nextInt(); double[] slope = new double[4]; while (T-- != 0) { for (int i = 0; i < 4; i++) { int x1 = scanner.nextInt(); int y1 = scanner.nextInt(); int x2 = scanner.nextInt(); int y2 = scanner.nextInt(); if (x1 == x2) { slope[i] = Integer.MAX_VALUE; } else { slope[i] = (y1 - y2)/(x1 - x2 + 0.0); } } if (isRectangle(slope)) { System.out.println("YES"); } else { System.out.println("NO"); } } } private static boolean isEquals(double a, double b){ if (a - b >= -0.0000000001 && a - b <= 0.0000000001) { return true; } else { return false; } } private static boolean isRectangle(double[] slope) { // TODO Auto-generated method stub double s1 = slope[0], s2 = slope[0]; int count = 0; for (int i = 1; i < slope.length; i++) { if (!isEquals(slope[i], s1) && !isEquals(slope[i], s2)) { count++; s2 = slope[i]; } } if (count == 0 || count > 1) { return false; } if (s1 > s2) { s1 = s1 + s2; s2 = s1 - s2; s1 = s1 - s2; } if (isEquals(s1, 0) && isEquals(s2, Integer.MAX_VALUE)) { return true; } else { if (isEquals((s1 * s2 + 1), 0)) { return true; } else { return false; } } } }
相关文章推荐
- Android进阶(十八)AndroidAPP开发问题汇总(二)
- hdoj 1166 敌兵布阵 【线段树&&二分树】【树状数组】
- 精彩文章推荐
- 简单介绍Java编程中的线程池
- 第二周项目:程序的多文件组织
- 让IE6 IE7 IE8 IE9 IE10 IE11支持Bootstrap的解决方法
- 三级抓包考点总结
- EF框架组件详述(EF基础系列篇3)
- benchmark information -(clojure webservice/nippy/)
- Android两个注意事项.深入了解Intent和IntentFilter(两)
- CentOS6.5搭建NTP服务
- Delphi XE3,C++ Builder XE3,RAD Studio XE3 v17.0.4770.56661(With Update 2) 官方下载激活
- mybatis以序列周期,同样处理的这个问题的价值
- 修改crontab默认的编辑器
- 为应用添加多个Activity与参数传递
- 【Java多线程】-线程中断
- The difference between LayoutInflater.inflate and findViewById
- 某MIT计算机学生谈学数学
- JavaScript学习笔记(三):JavaScript也有入口Main函数
- iOS开发 - 三方库实现聚光引导效果与触摸跟踪动效