HDU - 5128The E-pang Palace+暴力枚举,计算几何
第一次写计算几何,ac,感动。
不过感觉自己的代码还可以美化一下。
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5128
题意:
在一个坐标系中,有n个点,从中找到两个互不touch,互不cross的两个矩形(边要和坐标轴平行),使得面积最大。
思路:
枚举每个点,n的四次方,这题有个坑点是“回型矩阵”,是真的坑,然后discuss区里说的十字形矩阵是骗人的。
每次对枚举的四个点进行check,如果两个矩阵的四个点相互不在对方的矩阵中,那么这组就是合法的。
如果(这四个点组成一个回型矩阵),那么上面判check的结果就是,*一个矩阵的四个点在另一个矩阵中,而另一个矩阵没有*。
注意**中的条件是必要条件,还有判断一下,这个回型矩阵中,有没有边重合。
ac代码
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iterator>
#include <cmath>
using namespace std; #define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue #define Pll pair<ll,ll>
#define Pii pair<int,int> #define fi first
#define se second #define OKC ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long ll;
typedef unsigned long long ull; /*-----------------show time----------------*/
int n;
int l[],r[];
int mp[][];
bool check(int i,int j,int x,int y)
{
int e[][];
e[][] = l[i],e[][] = r[i];
e[][] = l[i],e[][] = r[j];
e[][] = l[j],e[][] = r[j];
e[][] = l[j],e[][] = r[i];
int le1 = min(l[x],l[y]),le2 = max(l[x],l[y]);
int ri1 = min(r[x],r[y]),ri2 = max(r[x],r[y]);
if(mp[l[x]][r[y]]==||mp[l[y]][r[x]]==)return false;
for(int w=; w<=; w++)
{
if(mp[e[w][]][e[w][]]==)return false;
if(e[w][]>=le1 && e[w][] <= le2 && e[w][]>=ri1 && e[w][] <= ri2)
return false;
}
return true;
}
/*
bool tepan(int i,int j,int q,int w)
{
//1
int l1 = min(l[i],l[j]),l2 = max(l[i],l[j]);
int r1 = min(r[i],r[j]),r2 = max(r[i],r[j]); //2 int x1 = min(l[q],l[w]),x2 = max(l[q],l[w]);
int y1 = min(r[q],r[w]),y2 = max(r[q],r[w]); if(y1<r1 && y2>r2 && l1<x1 && l2 > x2)return true;
if(y1>r1 && y2<r2 && l1>x1 && l2 < x2)return true;
return false;
}
*/
int main(){
while(~scanf("%d", &n)&&n){
memset(mp,,sizeof(mp));
for(int i=; i<=n; i++){
scanf("%d%d", &l[i],&r[i]);
mp[l[i]][r[i]] = ;
}
int ans = ;
for(int i=; i<=n; i++){
for(int j=; j<=n; j++){
for(int q = ; q<=n; q++){
for(int w = ; w<=n; w++){ if(check(i,j,q,w)&&check(q,w,i,j)){
//if(tepan(i,j,q,w) ||tepan(q,w,i,j))continue;
if(l[i]==l[j]||r[i]==r[j]||l[q]==l[w]||r[q]==r[w])continue;
int tmp = abs(l[i]-l[j]) * abs(r[i] - r[j]) + abs(l[q]-l[w]) * abs(r[q] - r[w]) ;
ans = max (ans,tmp);
}
else if(check(i,j,q,w))
{
if(l[i]==l[j]||r[i]==r[j]||l[q]==l[w]||r[q]==r[w])continue;
if(mp[l[q]][r[w]]==||mp[l[w]][r[q]]==)continue;
int tmp = abs(l[i]-l[j]) * abs(r[i] - r[j]) ;
// int tmp = max(tmp,)
int e[][];
e[][] = l[q],e[][] = r[q];
e[][] = l[q],e[][] = r[w];
e[][] = l[w],e[][] = r[w];
e[][] = l[w],e[][] = r[q];
int le1 = min(l[i],l[j]),le2 = max(l[i],l[j]);
int ri1 = min(r[i],r[j]),ri2 = max(r[i],r[j]);
int flag = ;
for(int s = ; s<=;s++){ //用于判断回字型的合法,里面完全包于
if(e[s][]==le1||e[s][]==le2||e[s][]==ri1||e[s][]==ri1){
flag = ;
break;
}
}
if(flag)ans = max (ans,tmp);
/*
if(tmp==3) //样例一自己跑出3.发现了回型矩阵的奥秘;
{
cout<<"----------------"<<endl;
cout<<"zhe;"<<i<<" "<<j<<" "<<q<<" "<<w<<endl;
int e[5][4];
e[1][1] = l[i],e[1][2] = r[i];
e[2][1] = l[i],e[2][2] = r[j];
e[3][1] = l[j],e[3][2] = r[j];
e[4][1] = l[j],e[4][2] = r[i];
int le1 = min(l[q],l[w]),le2 = max(l[q],l[w]);
int ri1 = min(r[q],r[w]),ri2 = max(r[q],r[w]);
debug(le1);debug(le2);debug(ri1);debug(ri2);
}
*/
} }}}} //这是四重循环的右括号
if(ans == )puts("imp");
else printf("%d\n",ans);
}
return ;
}
HDU5128
HDU - 5128The E-pang Palace+暴力枚举,计算几何的更多相关文章
- hdu 1172 猜数字(暴力枚举)
题目 这是一道可以暴力枚举的水题. //以下两个都可以ac,其实差不多一样,呵呵 //1: //4 wei shu #include<stdio.h> struct tt { ],b[], ...
- hdu 4445 Crazy Tank (暴力枚举)
Crazy Tank Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- HDU 4770 Lights Against Dudely 暴力枚举+dfs
又一发吐血ac,,,再次明白了用函数(代码重用)和思路清晰的重要性. 11779687 2014-10-02 20:57:53 Accepted 4770 0MS 496K 2976 B G++ cz ...
- HDU 4930 Fighting the Landlords(暴力枚举+模拟)
HDU 4930 Fighting the Landlords 题目链接 题意:就是题中那几种牌型.假设先手能一步走完.或者一步让后手无法管上,就赢 思路:先枚举出两个人全部可能的牌型的最大值.然后再 ...
- HDU 4431 Mahjong (DFS,暴力枚举,剪枝)
题意:给定 13 张麻将牌,问你是不是“听”牌,如果是输出“听”哪张. 析:这个题,很明显的暴力,就是在原来的基础上再放上一张牌,看看是不是能胡,想法很简单,也比较好实现,结果就是TLE,一直TLE, ...
- HDU 1270 小希的数表 (暴力枚举+数学)
题意:... 析:我们可以知道,a1+a2=b1,那么我们可以枚举a1,那么a2就有了,并且a1+a3=b2,所以a3就有了,我们再从把里面的剩下的数两两相加,并从b数组中去掉, 那么剩下的最小的就是 ...
- hdu 5491 The Next(暴力枚举)
Problem Description Let L denote the number of 1s in integer D’s binary representation. Given two in ...
- HDU 4462 Scaring the Birds (暴力枚举DFS)
题目链接:pid=4462">传送门 题意:一个n*n的区域,有m个位置是能够放稻草人的.其余都是玉米.对于每一个位置(x,y)所放稻草人都有个作用范围ri, 即abs(x-i)+ab ...
- HDU 6351暴力枚举 6354计算几何
Beautiful Now Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)T ...
随机推荐
- 插入Oracle数据库后返回当前主键id
最近做一个spring版本3.0.4的老项目功能,应用场景要用到插入oracle表后返回主键ID拿来和其他表关联. 用oralce的可以一直用这种处理方式,高兼容低,搜索网上的资料都不能和这个Spri ...
- 最全数据分析资料汇总(含python、爬虫、数据库、大数据、tableau、统计学等)
一.Python基础 Python简明教程(Python3) Python3.7.4官方中文文档 Python标准库中文版 廖雪峰 Python 3 中文教程 Python 3.3 官方教程中文版 P ...
- 8、大型项目的接口自动化实践记录----DB分别获取预期结果、实际结果
上一篇实现数据分离升级版--从DB获取数据,以及对应的请求实现,作为一个case,还缺少了预期结果与实际结果的获取及对比.因为前面的文章已经说过接口返回值的获取及对比,所以这篇不说这块了,这篇说一下D ...
- 在docker中开启新的container
当你在启动某个容器类型的时候 如果产生了类似的错误: docker: Error: No such image: b27f5dfcfc70c16d7b135889460def6b3f831bcc72 ...
- C#使用代理IP发送请求
https://www.cnblogs.com/benbenfishfish/p/5830149.html 获取可代理的IP https://www.cnblogs.com/ShalenChe/p ...
- 使用Typora编写博客并发布
前言 用CSDN写了一段时间,广告漫天飞舞.... 于是在博客园申请了一个账号,然后看见markdown编辑页面的第一眼: 再见^_^ 搜索一波,凭着博客园强大的生态,30多万的用户,第三方的支持应接 ...
- js五子棋游戏代码分享
HTML代码 <canvas id="game"></canvas> CSS代码 * { margin: 0; padding: 0; } #game { ...
- PCB学习总结
一.电子设计流程概述:项目立项------元件创库----------原理图设计-----------封装绘制-------pcb设计--------生产文件的输出--------pcb文件加工 二. ...
- Duilib的圆角矩形 抗锯齿优化 弥补RoundRect不足(网易云信borderround版本)
VListBox class="list" name="list" padding="5,3,5,3" bordersize="1 ...
- 003——Netty之Buffer、Channel以及多路复用器Selector
Buffer 1.缓冲区类型 2.缓冲区定义 (1)Buffer是一个对象,其中包含写入与读出的数据.是新IO与原IO的重要区别.任何情况下访问NIO中的数据都需要通过缓存区进行操作. (2)Buff ...