最主要的思路: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. HDFS的Java操作

    实验环境: Windows 10 Eclipse Mars.2 Release (4.5.2) CentOS 7 Hadoop-2.7.3 先决条件: 1) Windows上各环境变量已配置OK.   ...

  2. centos6.5yum方式升级内核

    升级内核需要使用elrepo的yum源,在安装yum源之前还需要我们导入elrepo的key,如下:rpm -import https://www.elrepo.org/RPM-GPG-KEY-elr ...

  3. C# JIT & AOT

    http://msdn.microsoft.com/library/z1zx9t92 http://msdn.microsoft.com/en-us/library/ht8ecch6(v=vs.90) ...

  4. MySQL编译安装错误:No curses/termcap library found的解决方法

    CentOS编译安装MySQL,./coonfigure时出现错误: checking for termcap functions library... configure: error: No cu ...

  5. fastjson是阿里巴巴的开源JSON解析库

    fastjson的API十分简洁. String text = JSON.toJSONString(obj); //序列化 VO vo = JSON.parseObject("{...}&q ...

  6. webservice报错Message part refundRequest was not recognized. (Does it exist in service WSDL?)

    最近在做一个支付的接口. 因为接口方使用webservice交互.  我只能去学习了下webservice 现在出了一个很古怪的问题~  我在请求他们url的时候, 返回给我找不到控制名错误 Mess ...

  7. 只有文本编辑器才是王道, 什么ide都是evil的浮云, 看看linus linux的内核开发工具vim emacs

    只有文本编辑器才是王道, 什么ide都是evil的浮云, 看看linus linux的内核开发工具vim emacs [ide is evil] (http://i.cnblogs.com/EditP ...

  8. mysql tinyint

    在MySQL的数据类型中,Tinyint的取值范围是:带符号的范围是-128到127.无符号的范围是0到255(见官方<MySQL 5.1参考手册>http://dev.mysql.com ...

  9. C# DateTime和String转换

    "; DateTime.ParseExact(time,"yyyyMMdd",System.Globalization.DateTimeFormatInfo.Curren ...

  10. 360随身WIFI程序单文件绿色版及网卡驱动(附使用感受)

    大家好,我是Colin,今天刚收到传说中的360WIFI,拿到手后马上就进行了测试.就做工而言,19.9的价格算是比较公道的,网卡很小,做工还可以,带磨砂质感,而且还提供了一个耳机插头,可以当挂件一样 ...