最主要的思路:1,这条直线就是要把两个正方形的中点链接。

2,注意的特殊情况:中心点重合。

答案:

public class Solution {

    public static void main(String[] args){
Point[] a = {new Point(136,6278),new Point(3958,6278),new Point(3958,2456),new Point(136,2456)};
Point[] b = {new Point(-3898,11132),new Point(7238,11132),new Point(7238,-4),new Point(-3898,-4)};
System.out.println(Arrays.toString(getBipartition(a,b)));
}
public static double[] getBipartition(Point[] a, Point[] b) {
// write code here
double[] res = new double[2];
Center c1 = new Center((a[0].x + a[1].x)/2.0,(a[0].y + a[3].y)/2.0);
Center c2 = new Center((b[0].x + b[1].x)/2.0,(b[0].y + b[3].y)/2.0); System.out.println(c2.x);
if(c1.x == c2.x && c1.y == c2.y){
res[0] = (a[2].y-a[0].y)*1.0 / (a[2].x - a[0].x);
res[1] = a[0].y - res[0] * a[1].x;
}
else{ res[0] = (c2.y - c1.y) / (c2.x - c1.x);
res[1] = c2.y - res[0] * c2.x;
} return res; }
} class Center{
double x;
double y;
Center(double x, double y){
this.x = x;
this.y = y;
}
}
class Point {
int x;
int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public Point() {
this.x = 0;
this.y = 0;
}
}

7.5---两个正方形分成对半的直线(CC150)的更多相关文章

  1. H5一行显示两个正方形

    1)有时候一些图片会是正方形或者长方形,对于这样的图片一般都是居中显示到正方体内,代码如下:  .exhibition_list img{width:100%;position: relative;t ...

  2. [CareerCup] 7.5 A Line Cut Two Squares in Half 平均分割两个正方形的直线

    7.5 Given two squares on a two-dimensional plane, find a line that would cut these two squares in ha ...

  3. [Mac]如何让两个窗口各占半个屏幕

    OS X中的拆分视图El Capitan或更高版本允许您使用两个应用程序填充Mac屏幕,而无需手动移动和调整窗口大小. 进入拆分视图 按住 窗口左上角的全屏按钮  . 当您按住按钮时,窗口会缩小,您可 ...

  4. 《Cracking the Coding Interview》——第7章:数学和概率论——题目5

    2014-03-20 02:20 题目:给定二维平面上两个正方形,用一条直线将俩方块划分成面积相等的两部分. 解法:穿过对称中心的线会将面积等分,所以连接两个中心即可.如果两个中心恰好重合,那么任意穿 ...

  5. 如何从二维平面n个点中寻找距离最近两个点?

    如何理解分治算法 什么是分治算法?简单来说就是"分而治之",也就是将原问题划分成n个规模较小的,并且结构与原问题相似的子问题,然后去递归地解决这些子问题,最后再合并其结果,就得到原 ...

  6. [LeetCode] Median of Two Sorted Arrays 两个有序数组的中位数

    There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two ...

  7. [LeetCode] 4. Median of Two Sorted Arrays 两个有序数组的中位数

    There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two ...

  8. 用dx实现半透遮挡效果

    四种技术方案: 1.两次绘制role实现半透遮挡2.背景中已经包含building, 则额外绘制一次半透的building即可实现半透遮挡3.利用building的遮罩实现半透遮挡, 利用rtt技术4 ...

  9. 平面上画n条直线,最多能将平面分成多少部分?

    转自:http://blog.csdn.net/cywosp/article/details/6724522 在一个平面上画1999条直线,最多能将这一平面划分成多少个部分? 没有直线时有一个空间:( ...

随机推荐

  1. JavaWeb学习笔记——Tomcat相关

    Tomcat目录分析 1.bin 存放启动和关闭Tomcat的脚本文件 2.conf  存放Tomcat服务器的各种配置文件 3.lib  存放Tomcat服务器的支持jar包 4.logs  存放T ...

  2. LaTex 使用 - 配置

    Reference Link: http://www.howtotex.com/howto/installing-latex-on-windows/ MikTeX:http://miktex.org/ ...

  3. Object.ReferenceEquals

    https://msdn.microsoft.com/en-us/library/system.object.referenceequals(v=vs.110).aspx However, the r ...

  4. Starling Tutorial

    http://www.hsharma.com/tutorials/starting-with-starling-ep-1-intro-setup/

  5. 上下联动,右侧按钮过多poper展示

    http://pan.baidu.com/s/1dDFMLjF

  6. Django笔记-字符编码相关问题整理

    1.添加中文注释后编译出错,提示:Non-ASCII   解决方法: 在Python脚本文件的第一行或第二行添加一句:      #coding:gbk或#coding:utf-8或##-*- cod ...

  7. Java中hashCode的作用

    转  http://blog.csdn.net/fenglibing/article/details/8905007 Java中hashCode的作用 2013-05-09 13:54 64351人阅 ...

  8. django,python,svn_web

  9. 用C语言将搜狗输入法词库转换成QQ拼音输入法词库

    搜狗输入法词库格式: 'ni'kan'xia 你看下 'ni'kan'xia'gai'hou 你看下改后 'ni'kan'xing'ma 你看行吗 'ni'kan'zen'me'yang 你看怎么样 ...

  10. BootStrap学习------栅格

    使用Bootstrap前端框架-栅格 要点 1.使用Bootstrap需要引入的css和js: (1)bootstrap.min.js (2)bootstrap.min.css 2.栅格系统需要通过& ...