223. Rectangle Area
来源:互联网 发布:淘宝全球购在哪里 编辑:程序博客网 时间:2024/06/14 04:01
class matrix{private:static const int TOTOP = 0x8;static const int TOBOTTOM = 0x4;static const int TOLEFT = 0x2;static const int TORIGHT = 1;static const int TOMARK = 0x0f;static const int INMARK = 0xf0;static const int INTOP = 0x80;static const int INBOTTOM = 0x40;static const int INLEFT = 0x20;static const int INRIGHT = 0x10;static const int GRAPEWID = 0x100;static const int GRAPELEN = 0x200;int leftX;int leftY;int rightX;int rightY;public:matrix(int lx, int ly, int rx, int ry) : leftX(lx), leftY(ly), rightX(rx), rightY(ry) {};int toAnother(const matrix &m){int ans = 0;if(leftY >= m.rightY)ans |= TOTOP;if(rightY <= m.leftY)ans |= TOBOTTOM;if(rightX <= m.leftX)ans |= TOLEFT;if(leftX >= m.rightX)ans |= TORIGHT;if(rightY >= m.rightY && leftY <= m.leftY){ans |= GRAPEWID;}else{if(leftY < m.rightY && leftY > m.leftY)ans |= INTOP;if(rightY < m.rightY && rightY > m.leftY)ans |= INBOTTOM;}if(rightX >= m.rightX && leftX <= m.leftX){ans |= GRAPELEN;}else{if(rightX < m.rightX && rightX > m.leftX)ans |= INLEFT;if(leftX < m.rightX && leftX > m.leftX)ans |= INRIGHT;}return ans;}int commonArea(const matrix &m){int loc = toAnother(m);if(loc & TOMARK)return 0;int len = 0, wid = 0;if(loc & GRAPEWID)wid = m.rightY - m.leftY;else if( loc & INTOP && loc & INBOTTOM)wid = rightY - leftY;else if(loc & INTOP)wid = m.rightY - leftY;elsewid = rightY - m.leftY;if(loc & GRAPELEN)len = m.rightX - m.leftX;else if(loc & INLEFT && loc & INRIGHT)len = rightX - leftX;else if(loc & INLEFT)len = rightX - m.leftX;elselen = m.rightX - leftX;return len * wid;}int Area(){return (rightX - leftX) * (rightY - leftY);}};class Solution {public: int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {matrix m1(A,B,C,D);matrix m2(E,F,G,H);return m1.Area() + m2.Area() - m1.commonArea(m2); }};
阅读全文
0 0
- 223. Rectangle Area
- [leetcode] 223.Rectangle Area
- [leetcode] 223. Rectangle Area
- 223. Rectangle Area LeetCode
- #leetcode# 223. Rectangle Area
- 223. Rectangle Area
- leetcode 223. Rectangle Area
- 223. Rectangle Area
- LeetCode--223. Rectangle Area
- 223. Rectangle Area
- LeetCode *** 223. Rectangle Area
- LeetCode 223. Rectangle Area
- leetcode-223. Rectangle Area
- 223. Rectangle Area
- 223. Rectangle Area
- LeetCode-223.Rectangle Area
- 223.[Leetcode]Rectangle Area
- 223. Rectangle Area
- ss服务器安装
- Angularjs 过滤器完成排序
- R 学习
- qq、短信第三方
- C语言的int, float,double相互转化(从本质上理解可能的问题)
- 223. Rectangle Area
- java制作倒计时
- 深入理解js的变量提升和函数提升
- Tomcat运行PHP项目
- java ajax异步上传文件(文档、图片都可以)
- MFC——编辑控件的7种方法
- 【DOM 编程艺术】3.4 节点
- tomcat 与 nginx,apache的区别
- 表单标签2