• HDU 5128.The E-pang Palace-计算几何


    The E-pang Palace

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others)
    Total Submission(s): 4547    Accepted Submission(s): 2403


    Problem Description
    E-pang Palace was built in Qin dynasty by Emperor Qin Shihuang in Xianyang, Shanxi Province. It was the largest palace ever built by human. It was so large and so magnificent that after many years of construction, it still was not completed. Building the great wall, E-pang Palace and Qin Shihuang's tomb cost so much labor and human lives that people rose to fight against Qin Shihuang's regime. 

    Xiang Yu and Liu Bang were two rebel leaders at that time. Liu Bang captured Xianyang -- the capital of Qin. Xiang Yu was very angry about this, and he commanded his army to march to Xianyang. Xiang Yu was the bravest and the strongest warrior at that time, and his army was much more than Liu Bang's. So Liu Bang was frighten and retreated from Xianyang, leaving all treasures in the grand E-pang Palace untouched. When Xiang Yu took Xianyang, he burned E-pang Palce. The fire lasted for more than three months, renouncing the end of Qin dynasty.

    Several years later, Liu Bang defeated Xiangyu and became the first emperor of Han dynasty. He went back to E-pang Palace but saw only some pillars left. Zhang Liang and Xiao He were Liu Bang's two most important ministers, so Liu Bang wanted to give them some awards. Liu Bang told them: "You guys can make two rectangular fences in E-pang Palace, then the land inside the fences will belongs to you. But the corners of the rectangles must be the pillars left on the ground, and two fences can't cross or touch each other." 

    To simplify the problem, E-pang Palace can be consider as a plane, and pillars can be considered as points on the plane. The fences you make are rectangles, and you MUST make two rectangles. Please note that the rectangles you make must be parallel to the coordinate axes.

    The figures below shows 3 situations which are not qualified(Thick dots stands for pillars):


    Zhang Liang and Xiao He wanted the total area of their land in E-pang Palace to be maximum. Please bring your computer and go back to Han dynasty to help them so that you may change the history.
     
    Input
    There are no more than 15 test case.

    For each test case:

    The first line is an integer N, meaning that there are N pillars left in E-pang Palace(4 <=N <= 30).

    Then N lines follow. Each line contains two integers x and y (0 <= x,y <= 200), indicating a pillar's coordinate. No two pillars has the same coordinate.

    The input ends by N = 0.
     
    Output
    For each test case, print the maximum total area of land Zhang Liang and Xiao He could get. If it was impossible for them to build two qualified fences, print "imp".
     
    Sample Input
    8 0 0 1 0 0 1 1 1 0 2 1 2 0 3 1 3 8 0 0 2 0 0 2 2 2 1 2 3 2 1 3 3 3 0
     
    Sample Output
    2 imp
     
    Source
     

    题目就是让你找8个点,组成与坐标系平行的矩形,输出最大面积。题目有个坑,,当其中一个在另一个里面的时候是满足的。

    首先枚举,找左下角和右上角的点,看是否存在左上和右下的点,然后把符合条件的矩形先保存起来,然后判断是否有覆盖的部分,然后找最大值就可以。

    代码:

     1 //5128-B-计算几何
     2 #include<iostream>
     3 #include<cstdio>
     4 #include<cstring>
     5 #include<algorithm>
     6 #include<bitset>
     7 #include<cassert>
     8 #include<cctype>
     9 #include<cmath>
    10 #include<cstdlib>
    11 #include<ctime>
    12 #include<deque>
    13 #include<iomanip>
    14 #include<list>
    15 #include<map>
    16 #include<queue>
    17 #include<set>
    18 #include<stack>
    19 #include<vector>
    20 using namespace std;
    21 typedef long long ll;
    22 typedef pair<int,int> pii;
    23 
    24 const double PI=acos(-1.0);
    25 const double eps=1e-6;
    26 const ll mod=1e9+7;
    27 const int inf=0x3f3f3f3f;
    28 const int maxn=1e4+10;
    29 const int maxm=100+10;
    30 #define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    31 #define lson l,m,rt<<1
    32 #define rson m+1,r,rt<<1|1
    33 
    34 struct node{
    35     int x,y;
    36 
    37     bool operator<(const node &a) const{
    38         if(x==a.x) return y<a.y;
    39         else return x<a.x;
    40     }
    41 }a[maxn];
    42 
    43 struct rectangle{
    44     node p1,p2;
    45     int area;
    46 }rec[maxn];
    47 
    48 map<node,int> mp;
    49 
    50 int judge(int i,int j)
    51 {
    52     if(rec[i].p2.x<rec[j].p1.x) return 1;
    53     if(rec[i].p2.y<rec[j].p1.y) return 1;
    54     if(rec[i].p1.x>rec[j].p2.x) return 1;
    55     if(rec[i].p1.y>rec[j].p2.y) return 1;
    56     if(rec[i].p1.x<rec[j].p1.x&&rec[i].p1.y<rec[j].p1.y&&rec[i].p2.x>rec[j].p2.x&&rec[i].p2.y>rec[j].p2.y) return 2;
    57     else return 0;
    58 }
    59 
    60 int main()
    61 {
    62     int n;
    63     while(scanf("%d",&n)&&n){
    64             mp.clear();
    65         for(int i=0;i<n;i++){
    66             scanf("%d%d",&a[i].x,&a[i].y);
    67             mp[a[i]]=1;
    68         }
    69         sort(a,a+n);
    70         int h=0;
    71         for(int i=0;i<n;i++){
    72             for(int j=i+1;j<n;j++){
    73                 if(a[j].x>a[i].x&&a[j].y>a[i].y){
    74                     node t1,t2;
    75                     t1.x=a[i].x;t1.y=a[j].y;
    76                     t2.x=a[j].x;t2.y=a[i].y;
    77                     if(mp[t1]&&mp[t2]){
    78                         rec[h].p1.x=a[i].x;rec[h].p1.y=a[i].y;
    79                         rec[h].p2.x=a[j].x;rec[h].p2.y=a[j].y;
    80                         rec[h++].area=(a[j].y-a[i].y)*(a[j].x-a[i].x);
    81                     }
    82                 }
    83             }
    84         }
    85         int ans=-1;
    86         for(int i=0;i<h;i++){
    87             for(int j=0;j<h;j++){
    88                 if(judge(i,j)==1){
    89                     ans=max(ans,rec[i].area+rec[j].area);
    90                 }
    91                 else if(judge(i,j)==2){
    92                     ans=max(ans,rec[i].area);
    93                 }
    94             }
    95         }
    96         if(ans==-1)printf("imp
    ");
    97         else printf("%d
    ",ans);
    98     }
    99 }

    溜了。

  • 相关阅读:
    C#练习代码
    docker部署gitlab
    vim 缩进设置
    css 初步学习笔记
    tomcat
    201871010107公海瑜《面向对象程序设计(java)》第一周学习总结 公海瑜
    发现JavaScript真强大
    今天看了一點ant的內容,受益匪浅
    一道趣味問題
    一個挺適合初學者的Ant教程
  • 原文地址:https://www.cnblogs.com/ZERO-/p/9794061.html
Copyright © 2020-2023  润新知