Rectangle Area
来源:互联网 发布:连接u8数据服务器失败 编辑:程序博客网 时间:2024/05/22 03:16
小学期末考试题啊。不过当要用程序写的时候,我还是费了点劲,因为题意弄错了。题目是求2个三角形覆盖的所有面积,不是求相交的面积。因此要分为不相交、相交两种情况。相交的话减去重叠部分即可,重叠部分的坐标画个图就可清晰找到规律。
如下:
int miniOfTwo(int a, int b) { if (a >= b) return b; else return a;}int maxOfTwo(int a, int b) { if (a >= b) return a; else return b;}int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) { int result = 0; int xx = 0, yy = 0; result = ((C - A) * (D - B) + (G - E) * (H - F)); if (E >= C || G <= A || F >= D || H <= B) //如果不相交 ; else { xx = miniOfTwo(C, G) - maxOfTwo(A, E); yy = miniOfTwo(H, D) - maxOfTwo(B, F); result -= xx * yy; } return result;}
0 0
- Rectangle Area
- Rectangle Area
- Rectangle Area
- Rectangle Area
- Rectangle Area
- Rectangle Area
- Rectangle Area
- Rectangle Area
- Rectangle Area
- Rectangle Area
- Rectangle Area
- Rectangle Area
- Rectangle Area
- Rectangle Area
- Rectangle Area
- Rectangle Area
- Rectangle Area
- Rectangle Area
- 数据库oracle for update of和for update区别
- API性能测试基本性能指标及要求
- 关于android开发中出现中文乱码
- openssl编程之服务端
- gethostbyname用法
- Rectangle Area
- 记AWS+Drupal Happy Hour 150610—— AWS Active 分享
- lnmp
- 数据挖掘学习笔记之CART树
- SAT数学考试必背公式---三角函数
- 用ng-bind-html指令和 $sce服务 实现页面输出html
- android 定义颜色color时6位或8位值的区别
- 专治懒癌100年,疗效嗷嗷好!
- SpringMVC拦截器中通过反射得到Controller方法注解时ClassCastException解决方案