7.5---两个正方形分成对半的直线(CC150)
最主要的思路: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)的更多相关文章
- H5一行显示两个正方形
1)有时候一些图片会是正方形或者长方形,对于这样的图片一般都是居中显示到正方体内,代码如下: .exhibition_list img{width:100%;position: relative;t ...
- [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 ...
- [Mac]如何让两个窗口各占半个屏幕
OS X中的拆分视图El Capitan或更高版本允许您使用两个应用程序填充Mac屏幕,而无需手动移动和调整窗口大小. 进入拆分视图 按住 窗口左上角的全屏按钮 . 当您按住按钮时,窗口会缩小,您可 ...
- 《Cracking the Coding Interview》——第7章:数学和概率论——题目5
2014-03-20 02:20 题目:给定二维平面上两个正方形,用一条直线将俩方块划分成面积相等的两部分. 解法:穿过对称中心的线会将面积等分,所以连接两个中心即可.如果两个中心恰好重合,那么任意穿 ...
- 如何从二维平面n个点中寻找距离最近两个点?
如何理解分治算法 什么是分治算法?简单来说就是"分而治之",也就是将原问题划分成n个规模较小的,并且结构与原问题相似的子问题,然后去递归地解决这些子问题,最后再合并其结果,就得到原 ...
- [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 ...
- [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 ...
- 用dx实现半透遮挡效果
四种技术方案: 1.两次绘制role实现半透遮挡2.背景中已经包含building, 则额外绘制一次半透的building即可实现半透遮挡3.利用building的遮罩实现半透遮挡, 利用rtt技术4 ...
- 平面上画n条直线,最多能将平面分成多少部分?
转自:http://blog.csdn.net/cywosp/article/details/6724522 在一个平面上画1999条直线,最多能将这一平面划分成多少个部分? 没有直线时有一个空间:( ...
随机推荐
- JavaWeb学习笔记——开发动态WEB资源(五)servlet身份验证
本工程的功能是实现Javaweb的servlet身份验证 一下是login.html文件中的代码 <!DOCTYPE html> <html> <head> < ...
- FreeImage使用
http://blog.csdn.net/byxdaz/article/details/6056509 http://blog.chinaunix.net/uid-20660110-id-65639. ...
- NGUI架构和Draw Call合并原理
http://bbs.9ria.com/thread-282804-1-1.html http://www.unitymanual.com/blog-97-238.html
- yourphp读取不到hits
源代码 <YP:list name="Article" order="id desc" catid="37" limit=" ...
- Http常用状态码
HTTP状态码(HTTP Status Code) 一些常见的状态码为: 200 - 服务器成功返回网页 404 - 请求的网页不存在 503 - 服务不可用 所有状态解释:点击查看 1xx(临时响应 ...
- History(历史)命令用法
如果你经常使用 Linux 命令行,那么使用 history(历史)命令可以有效地提升你的效率.本文将通过实例的方式向你介绍 history 命令的用法. 使用 HISTTIMEFORMAT 显示时间 ...
- 解决umount.nfs: /data: device is busy 问题
有时候我们需要umount某个挂载目录时会遇到如下问题: [root@localhost /]# umount /data/ umount.nfs: /data: device is busy 通过这 ...
- 注入问题0x00
1.sqlmap遇到MySQL注入可以成功getshell,但是,遇到sqlserver注入未成功getshell. 2.xp_cmdshell 如何 getshell(1433未对外开放). 解决方 ...
- Css常用收集
/*-------------------------------------- 圆角*/ -webkit-border-radius: 4px; -moz-border-radius: 4px; ...
- Yii2 打印sql语句和批量插入数据
打印sql语句: $model->find()->createCommand()->getRawSql(); 批量插入 Yii::$app->db->createComm ...