The E-pang Palace

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=217902

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 magnicent 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 ght 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 re lasted
for more than three months, renouncing the end of Qin dynasty.
Several years later, Liu Bang defeated Xiangyu and became the rst 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 gures below shows 3 situations which are not qualied (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 rst 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 qualied 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

HINT

题意

平面给你n个点,让你找到两个和坐标轴平行的矩形,然后要求这两个矩形要么内含,要么相离

然后输出能够组成的最大面积

题解:

首先我们枚举矩形,只用n^2枚举就好了

只用枚举对角线,然后枚举之后,我们就暴力去判断就好了

判断两种情况,想清楚了,还是很简单的

代码:

  1. #include<iostream>
  2. #include<stdio.h>
  3. #include<iostream>
  4. #include<cstring>
  5. using namespace std;
  6.  
  7. int mp[][];
  8. struct node
  9. {
  10. int x,y;
  11. };
  12. node p[];
  13. int In(node a,node c,node b)
  14. {
  15. if(a.x<=b.x&&a.x>=c.x&&a.y<=b.y&&a.y>=c.y)
  16. return ;
  17. return ;
  18. }
  19. int No_In(node a,node c,node b)
  20. {
  21. if(a.x<b.x&&a.x>c.x&&a.y<b.y&&a.y>c.y)
  22. return ;
  23. return ;
  24. }
  25. int check(node a,node b,node c,node d)
  26. {
  27. node t1[],t2[];
  28. t1[].x=min(a.x,b.x);t1[].y=min(a.y,b.y);
  29. t1[].x=max(a.x,b.x);t1[].y=min(a.y,b.y);
  30. t1[].x=min(a.x,b.x);t1[].y=max(a.y,b.y);
  31. t1[].x=max(a.x,b.x);t1[].y=max(a.y,b.y);
  32.  
  33. t2[].x=min(c.x,d.x);t2[].y=min(c.y,d.y);
  34. t2[].x=max(c.x,d.x);t2[].y=min(c.y,d.y);
  35. t2[].x=min(c.x,d.x);t2[].y=max(c.y,d.y);
  36. t2[].x=max(c.x,d.x);t2[].y=max(c.y,d.y);
  37.  
  38. for(int i=;i<;i++)
  39. {
  40. //cout<<t1[i].x<<" "<<t1[i].y<<endl;
  41. if(mp[t1[i].x][t1[i].y]==)
  42. return ;
  43. }
  44.  
  45. for(int i=;i<;i++)
  46. {
  47. //cout<<t2[i].x<<" "<<t2[i].y<<endl;
  48. if(mp[t2[i].x][t2[i].y]==)
  49. return ;
  50. }
  51.  
  52. if(t1[].x==t1[].x)return ;
  53. if(t1[].y==t1[].y)return ;
  54. if(t2[].x==t2[].x)return ;
  55. if(t2[].y==t2[].y)return ;
  56.  
  57. int flag = ;
  58. for(int i=;i<;i++)
  59. if(No_In(t1[i],t2[],t2[]))
  60. flag++;
  61. if(flag==)return (t2[].x-t2[].x)*(t2[].y-t2[].y);
  62.  
  63. flag = ;
  64. for(int i=;i<;i++)
  65. if(No_In(t2[i],t1[],t1[]))
  66. flag++;
  67. if(flag==)return (t1[].x-t1[].x)*(t1[].y-t1[].y);
  68.  
  69. for(int i=;i<;i++)
  70. if(In(t1[i],t2[],t2[]))
  71. return ;
  72. for(int i=;i<;i++)
  73. if(In(t2[i],t1[],t1[]))
  74. return ;
  75.  
  76. return (t2[].x-t2[].x)*(t2[].y-t2[].y) + (t1[].x-t1[].x)*(t1[].y-t1[].y);
  77. }
  78. int main()
  79. {
  80. int n;
  81. while(scanf("%d",&n)!=EOF)
  82. {
  83. memset(mp,,sizeof(mp));
  84. if(n==)break;
  85. for(int i=;i<=n;i++)
  86. {
  87. scanf("%d%d",&p[i].x,&p[i].y);
  88. mp[p[i].x][p[i].y]=;
  89. }
  90. int ans = ;
  91. for(int i=;i<=n;i++)
  92. {
  93. for(int j=i+;j<=n;j++)
  94. {
  95. for(int t=;t<=n;t++)
  96. {
  97. for(int k=t+;k<=n;k++)
  98. {
  99. if(i==t&&j==k)continue;
  100. int Area = check(p[i],p[j],p[t],p[k]);
  101. if(Area!=)
  102. {
  103. //printf("%d %d %d %d %d %d %d %d\n",p[i].x,p[i].y,p[j].x,p[j].y,p[t].x,p[t].y,p[k].x,p[k].y);
  104. //cout<<Area<<endl;
  105. }
  106. ans = max(ans,Area);
  107. }
  108. }
  109. }
  110. }
  111. if(ans==)printf("imp\n");
  112. else printf("%d\n",ans);
  113. }
  114. }

UVALive 7070 The E-pang Palace 暴力的更多相关文章

  1. UVALive 7070 The E-pang Palace(暴力)

    实话说这个题就是个暴力,但是有坑,第一次我以为相含是不行的,结果WA,我加上相含以后还WA,我居然把这两个矩形的面积加在一块了吗,应该取大的那一个啊-- 方法就是枚举对角线,为了让自己不蒙圈,我写了一 ...

  2. 简单几何(判断矩形的位置) UVALive 7070 The E-pang Palace(14广州B)

    题目传送门 题意:给了一些点,问组成两个不相交的矩形的面积和最大 分析:暴力枚举,先找出可以组成矩形的两点并保存起来(vis数组很好),然后写个函数判断四个点是否在另一个矩形内部.当时没有保存矩形,用 ...

  3. UVaLive 6855 Banks (水题,暴力)

    题意:给定 n 个数,让你求最少经过几次操作,把所有的数变成非负数,操作只有一种,变一个负数变成相反数,但是要把左右两边的数加上这个数. 析:由于看他们AC了,时间这么短,就暴力了一下,就AC了... ...

  4. UVALive 2145 Lost in Space(暴力)

    题目并不难,就是暴力,需要注意一下输出形式和精度. #include<iostream> #include<cstdio> #include<cmath> usin ...

  5. The E-pang Palace(暴力几何)

    //暴力的几何题,问,n个点可以组成的矩形,不相交,可包含的情况下,最大的面积,还有就是边一定与 x y 轴平行,所以比较简单了 //暴力遍历对角线,搜出所有可能的矩形,然后二重循环所有矩形,判断一下 ...

  6. UVALive 6862 Triples (找规律 暴力)

    Triples 题目链接: http://acm.hust.edu.cn/vjudge/contest/130303#problem/H Description http://7xjob4.com1. ...

  7. UVALive 7457 Discrete Logarithm Problem (暴力枚举)

    Discrete Logarithm Problem 题目链接: http://acm.hust.edu.cn/vjudge/contest/127401#problem/D Description ...

  8. UVALive - 6837 Kruskal+一点性质(暴力枚举)

    ICPC (Isles of Coral Park City) consist of several beautiful islands. The citizens requested constru ...

  9. HDU - 5128The E-pang Palace+暴力枚举,计算几何

    第一次写计算几何,ac,感动. 不过感觉自己的代码还可以美化一下. 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5128 题意: 在一个坐标系中,有n个 ...

随机推荐

  1. 【转】移动web资源整理

    目录(更新于20150311) meta基础知识 H5页面窗口自动调整到设备宽度,并禁止用户缩放页面 忽略将页面中的数字识别为电话号码 忽略Android平台中对邮箱地址的识别 当网站添加到主屏幕快速 ...

  2. ubuntu1204上不能正常用emacs配合gocode进行自动补全

    我按gocode的页面https://github.com/nsf/gocode上去做,可是还是未成功,,我确认auto-complete在c-mode中是可以使用的,因为有补全出来了, 我再找了ht ...

  3. How to Calculate difference between two dates in C# z

    Do you need to find the difference in number of days, hours or even minute between the two date rang ...

  4. delphi 设置表格样式。

    //设置表格样式 wordDoc.Tables.Item(1).Borders.Item(Word.WdBorderType.wdBorderLeft).LineStyle = Word.WdLine ...

  5. MFC ListControl用法

    http://blog.csdn.net/lovton/article/details/6527208 1.建立一个对象m_LogList 步骤:在对话listcontrol控件右键点击添加变量-&g ...

  6. js刷新页面方法

    1,reload 方法,该方法强迫浏览器刷新当前页面.语法:location.reload([bForceGet])   参数: bForceGet, 可选参数, 默认为 false,从客户端缓存里取 ...

  7. maltab几个常见的问题

    maltab常见的几个习题 1. MATLAB 的命令窗口的作用是什么?编辑/调试窗口?图象窗口? MATLAB命令窗口是MATLAB起动时第一个看到的窗口,用户可以在命令窗口提示符"> ...

  8. 转储oracle的redo文件

    1.确定当前使用的redo文件 SQL> select member from v$logfile where group# = ( select group# from v$log where ...

  9. Developer Tools(开发工具)

    Google提供了使用Java和Python开发App Engine的免费工具.你可以从Google的网站上下载你所用语言和操作系统的软件开发包.Java用户可以以Eclipse集成开发环境的方式获取 ...

  10. 优雅地对泛型List 进行深拷贝

    public class People { public string Name; public int Age; public People(string name, int age) { this ...