题目传送门

题意:给了一些点,问组成两个不相交的矩形的面积和最大

分析:暴力枚举,先找出可以组成矩形的两点并保存起来(vis数组很好),然后写个函数判断四个点是否在另一个矩形内部。当时没有保存矩形,用for来找矩形,结果写糊涂了忘记判断回形的情况。。。

/************************************************
* Author :Running_Time
* Created Time :2015/11/6 星期五 17:00:44
* File Name :B_2.cpp
************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int N = 2e2 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos (-1.0);
struct Point {
int x, y;
Point () {}
Point (int x, int y) : x (x), y (y) {}
bool operator < (const Point &r) const {
if (x == r.x) return y < r.y;
else return x < r.x;
}
}p[33];
struct Matrix {
Point a, b;
Matrix () {}
Matrix (Point a, Point b) : a (a), b (b) {}
};
vector<Matrix> mat;
bool vis[N][N]; int inside(Point p, Point a, Point b) {
if (p.x >= a.x && p.x <= b.x
&& p.y <= a.y && p.y >= b.y) {
if (p.x > a.x && p.x < b.x
&& p.y < a.y && p.y > b.y) return -1;
else return 1;
}
else return 0;
} int area_mat(int i) {
return (mat[i].b.x - mat[i].a.x) * (mat[i].a.y - mat[i].b.y);
} int judge(int i, int j) {
Point ic = Point (mat[i].a.x, mat[i].b.y),
id = Point (mat[i].b.x, mat[i].a.y);
int res1 = inside (mat[i].a, mat[j].a, mat[j].b);
int res2 = inside (mat[i].b, mat[j].a, mat[j].b);
int res3 = inside (ic, mat[j].a, mat[j].b);
int res4 = inside (id, mat[j].a, mat[j].b);
if (!res1 && !res2 && !res3 && !res4) return 0;
else if (res1 == -1 && res2 == -1 && res3 == -1 && res4 == -1) return -1;
else return 1;
} int main(void) {
int n;
while (scanf ("%d", &n) == 1) {
if (!n) break;
mat.clear ();
memset (vis, false, sizeof (vis));
for (int i=0; i<n; ++i) {
scanf ("%d%d", &p[i].x, &p[i].y);
vis[p[i].x][p[i].y] = true;
}
sort (p, p+n);
for (int i=0; i<n; ++i) {
int x1 = p[i].x, y1 = p[i].y;
for (int j=i+1; j<n; ++j) {
int x2 = p[j].x, y2 = p[j].y;
if (x1 >= x2 || y1 <= y2) continue;
if (!vis[x1][y2] || !vis[x2][y1]) continue;
mat.push_back (Matrix (Point (x1, y1), Point (x2, y2)));
}
}
int ans = 0;
for (int i=0; i<mat.size (); ++i) {
for (int j=i+1; j<mat.size (); ++j) {
int res1 = judge (i, j);
int res2 = judge (j, i);
if (!res1 && !res2) {
ans = max (ans, area_mat (i) + area_mat (j));
}
if (res1 == -1 || res2 == -1) {
ans = max (ans, max (area_mat (i), area_mat (j)));
}
}
} if (ans == 0) puts ("imp");
else printf ("%d\n", ans);
} //cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; return 0;
}

 

这个很挫的代码放在这留个念。。。

/************************************************
* Author :Running_Time
* Created Time :2015/10/14 星期三 14:59:33
* File Name :B.cpp
************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; const int N = 33;
const int M = 210;
const int INF = 0x3f3f3f3f;
struct Point {
int x, y;
bool operator < (const Point &r) const {
if (x == r.x) return y < r.y;
else return x < r.x;
}
}p[N];
vector<int> vx[M], vy[M]; int cal(int la, int lb) {
if (la < 0) la = -la;
if (lb < 0) lb = -lb;
return la * lb;
} int main(void) {
int n;
while (scanf ("%d", &n) == 1) {
if (!n) break;
for (int i=0; i<=200; ++i) {
vx[i].clear (); vy[i].clear ();
}
for (int i=1; i<=n; ++i) {
scanf ("%d%d", &p[i].x, &p[i].y);
}
sort (p+1, p+1+n);
for (int i=1; i<=n; ++i) {
vx[p[i].x].push_back (i); vy[p[i].y].push_back (i);
}
int ans = 0;
bool flag = false;
for (int i=1; i<=n; ++i) { //i one
int x = p[i].x, y = p[i].y;
if (vx[x].size () <= 1 || vy[y].size () <= 1) continue;
for (int j=0; j<vx[x].size (); ++j) { //j two
int jj = vx[x][j];
if (jj == i || p[jj].y <= y) continue;
int jy = p[jj].y;
for (int k=0; k<vy[y].size (); ++k) { //k three
int kk = vy[y][k];
if (kk == i || p[kk].x <= x) continue;
int kx = p[kk].x;
if (vx[kx].size () <= 1) continue;
for (int l=0; l<vx[kx].size (); ++l) { //l four
int ll = vx[kx][l];
if (ll == kk || p[ll].y <= y) continue;
if (p[ll].y == jy) { //find the first rectangle if (vy[jy].size () >= 4) {
for (int r=0; r<vy[jy].size (); ++r) {
int rr = vy[jy][r];
if (rr == ll || rr == jj) continue;
for (int r3=0; r3<vy[jy].size (); ++r3) {
int r4 = vy[jy][r3];
if (r4 == ll || r4 == jj || r4 == rr) continue;
int xx = p[rr].x, kkx = p[r4].x;
if (x <= xx && xx <= kx) continue;
if (x <= kkx && kkx <= kx) continue;
if (vx[xx].size () <= 1 || vx[kkx].size () <= 1) continue;
for (int o=0; o<vx[xx].size (); ++o) {
int oo = vx[xx][o];
if (oo == rr || p[oo].y <= jy) continue;
int jjy = p[oo].y;
for (int u=0; u<vx[kkx].size (); ++u) {
int uu = vx[kkx][u];
if (uu == r4 || p[uu].y != jjy) continue;
flag = true;
ans = max (ans, cal (kx - x, jy - y) + cal (kkx - xx, jjy - jy));
}
}
}
}
} for (int yy=jy+1; yy<=200; ++yy) {
if (vy[yy].size () <= 1) continue;
for (int yi=0; yi<vy[yy].size (); ++yi) {
int ii = vy[yy][yi];
int xx = p[ii].x, yy = p[ii].y; //to find the second rectangle
for (int j3=0; j3<vx[xx].size (); ++j3) {
int j4 = vx[xx][j3];
if (j4 == ii || p[j4].y <= yy) continue;
int jjy = p[j4].y;
for (int k3=0; k3<vy[yy].size (); ++k3) {
int k4 = vy[yy][k3];
if (k4 == ii) continue;
int kkx = p[k4].x;
for (int l3=0; l3<vx[kkx].size (); ++l3) {
int l4 = vx[kkx][l3];
if (l4 == k4 || p[l4].y != jjy) continue;
flag = true;
ans = max (ans, cal (kx - x, jy - y) + cal (kkx - xx, jjy - yy));
}
}
}
}
} if (vx[kx].size () >= 4) {
for (int r=0; r<vx[kx].size (); ++r) {
int rr = vx[kx][r];
if (rr == kk || rr == ll) continue;
for (int r3=0; r3<vy[jy].size (); ++r3) {
int r4 = vx[kx][r3];
if (r4 == kk || r4 == ll || r4 == rr) continue;
int yy = p[rr].y, jjy = p[r4].y;
if (yy > jjy) swap (yy, jjy);
if (y <= yy && yy <= jy) continue;
if (y <= jjy && jjy <= jy) continue;
if (vy[yy].size () <= 1 || vy[jjy].size () <= 1) continue;
for (int o=0; o<vy[yy].size (); ++o) {
int oo = vy[yy][o];
if (oo == rr || p[oo].x <= kx) continue;
int kkx = p[oo].x;
for (int u=0; u<vy[jjy].size (); ++u) {
int uu = vy[jjy][u];
if (uu == r4 || p[uu].x != kkx) continue;
flag = true;
ans = max (ans, cal (kx - x, jy - y) + cal (kkx - kx, jjy - jy));
}
}
}
}
} for (int x5=kx+1; x5<=200; ++x5) {
if (vx[x5].size () <= 1) continue;
for (int xi=0; xi<vx[x5].size (); ++xi) {
int ii = vx[x5][xi];
int xx = p[ii].x, yy = p[ii].y; //to find the second rectangle
for (int j3=0; j3<vx[x5].size (); ++j3) {
int jj = vx[x5][j3];
if (jj == ii || p[jj].y <= yy) continue;
int jjy = p[jj].y;
if (vy[yy].size () <= 1) continue;
for (int k3=0; k3<vy[yy].size (); ++k3) {
int k4 = vy[yy][k3];
if (k4 == ii || p[k4].x <= xx) continue;
int kkx = p[k4].x;
for (int l3=0; l3<vx[kkx].size (); ++l3) {
int l4 = vx[kkx][l3];
if (l4 == k4 || p[l4].y != jjy) continue;
flag = true;
ans = max (ans, cal (kx - x, jy - y) + cal (kkx - xx, jjy - yy));
}
}
}
}
}
}
}
}
}
} if (flag) {
printf ("%d\n", ans);
}
else puts ("imp");
} return 0;
}

  

简单几何(判断矩形的位置) UVALive 7070 The E-pang Palace(14广州B)的更多相关文章

  1. Python下opencv使用笔记(二)(简单几何图像绘制)

    简单几何图像一般包含点.直线.矩阵.圆.椭圆.多边形等等.首先认识一下opencv对像素点的定义. 图像的一个像素点有1或者3个值.对灰度图像有一个灰度值,对彩色图像有3个值组成一个像素值.他们表现出 ...

  2. poj 2031Building a Space Station(几何判断+Kruskal最小生成树)

    /* 最小生成树 + 几何判断 Kruskal 球心之间的距离 - 两个球的半径 < 0 则说明是覆盖的!此时的距离按照0计算 */ #include<iostream> #incl ...

  3. python练习题-简单方法判断三个数能否组成三角形

    python简单方法判断三个数能否组成三角形 #encoding=utf-8 import math while True: str=raw_input("please input thre ...

  4. Codeforces 935 简单几何求圆心 DP快速幂求与逆元

    A #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #def ...

  5. POJ 1269 Intersecting Lines(判断两直线位置关系)

    题目传送门:POJ 1269 Intersecting Lines Description We all know that a pair of distinct points on a plane ...

  6. 简单地判断判断两矩形相交/重叠 C#

    最近需要用到矩形相交算法的简单应用,所以特地拿一个很简单的算法出来供新手参考,为什么说是给新手的参考呢因为这个算法效率并不是很高,但是这个算法只有简简单单的三行.程序使用了两种方法来判断是否重叠/相交 ...

  7. 简单几何(直线位置) POJ 1269 Intersecting Lines

    题目传送门 题意:判断两条直线的位置关系,共线或平行或相交 分析:先判断平行还是共线,最后就是相交.平行用叉积判断向量,共线的话也用叉积判断点,相交求交点 /********************* ...

  8. 简单几何(线段与直线的位置) POJ 3304 Segments

    题目传送门 题意:有若干线段,问是否存在一条直线,所有线段投影到直线上时至少有一个公共点 分析:有一个很好的解题报告:二维平面上线段与直线位置关系的判定.首先原问题可以转换为是否存在一条直线与所有线段 ...

  9. 简单几何(点与线段的位置) POJ 2318 TOYS && POJ 2398 Toy Storage

    题目传送门 题意:POJ 2318 有一个长方形,用线段划分若干区域,给若干个点,问每个区域点的分布情况 分析:点和线段的位置判断可以用叉积判断.给的线段是排好序的,但是点是无序的,所以可以用二分优化 ...

随机推荐

  1. Antenna Placement(匈牙利算法 ,最少路径覆盖)

    Antenna Placement Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6991   Accepted: 3466 ...

  2. Unity3D如何制作透贴和使用透贴模型

    http://momowing.diandian.com/post/2012-10-25/40040842845 Unity3D如何制作透贴和使用透贴模型??解决办法!!! 问题: 同事通过3DMAX ...

  3. PLY文件(转)

    转载:http://bbs.itiankong.com/thread-89555-1-1.html PLY 是一种电脑档案格式,全名为 多边形档案(Polygon File Format) 或 史丹佛 ...

  4. Linux&shell之高级Shell脚本编程-创建函数

    写在前面:案例.常用.归类.解释说明.(By Jim) 使用函数 #!/bin/bash # testing the script function myfun { echo "This i ...

  5. MySQL使用索引的场景及真正利用索引的SQL类型

    1. 为什么使用索引 在无索引的情况下,MySQL会扫描整张表来查找符合sql条件的记录,其时间开销与表中数据量呈正相关.对关系型数据表中的某些字段建索引可以极大提高查询速度(当然,不同字段是否sel ...

  6. MySQL数据库索引的4大类型以及相关的索引创建

    以下的文章主要介绍的是MySQL数据库索引类型,其中包括普通索引,唯一索引,主键索引与主键索引,以及对这些索引的实际应用或是创建有一个详细介绍,以下就是文章的主要内容描述. (1)普通索引 这是最基本 ...

  7. iOS 中添加lib型target库的依赖问题

    今天在编码时遇到一个问题,总提示我找不到系统库文件. 我的项目结构类似下图 在TestLib中有引用CoreLocation库的类.但是CoreLocation库需要加在PhotoInfoDemo对象 ...

  8. Linux删除乱码文件

    2015年2月28日 17:11:54 1.  ls -i  列出文件的inode号 ??Φ-ͦ?+?-ˬͩ-????-??.doc 2.  find folder -inum -delete -de ...

  9. 5.python(迭代器,装饰器,生成器,基本算法,正则)

    一,迭代器 1.迭代器  (1)迭代器是访问集合元素的一种方式.迭代器对象从集合的第一个元素开始访问,知道所有的元素被访问完结束.迭代器只能往前不会后退.  (2)对于原生支持随机访问的数据结构(如t ...

  10. codeforces 476C.Dreamoon and Sums 解题报告

    题目链接:http://codeforces.com/problemset/problem/476/C 题目意思:给出两个数:a 和 b,要求算出 (x/b) / (x%b) == k,其中 k 的取 ...