Simple geometry (judging the position of the rectangle) uvalive 7070 the E-pang Palace (14 Guangzhou B)

Source: Internet
Author: User
Tags bitset cmath

Topic Portal

Test instructions: Given some points, ask to make up the area and maximum of two disjoint rectangles

Analysis: Violent enumeration, first find the two points that can make up the rectangle and save it (vis array very good), and then write a function to determine whether four points inside another rectangle. There was no save rectangle, with for to find the rectangle, the result is confused to forget to judge the situation of the back shape ...

/************************************************* author:running_time* Created TIME:2015/11/6 Friday 17:00:44* Fil E 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 | 1typedef long ll;const int N = 2e2 + 10;const int INF = 0x3f3f3f3f;const int MOD = 1e9 + 7;const Double EPS = 1e-10;c    Onst Double PI = ACOs ( -1.0); struct point {int x, y; 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, p Oint 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 ics = 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, &AMP;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 = Jud                GE (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;}

 

This is a very lame code to stay here and read ...

/************************************************* author:running_time* Created TIME:2015/10/14 Wednesday 14:59:33* Fi Le 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, &AMP;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, 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[y                                Y].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;}

  

Simple geometry (judging the position of the rectangle) uvalive 7070 the E-pang Palace (14 Guangzhou B)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.