题目大意是让你用这n条边放在网格上构成凸包,并且边的两端点必须在网格上。

那么比较容易想到的就是枚举可能情况,因为这样的勾股数组成情况不多,因此可以直接枚举所有连出去的边反映在坐标轴上的所有情况,最后判断是否回到起点并且绕城一个凸包。

但是样例三每条边有最多36个方向,那么366*6!显然会超时,我们就需要一些剪枝。

1.第一条边固定住,那么我们的枚举边的顺序的复杂度变成了5!.

2.枚举到最后一个点的时候,不需要再将次边连出去判断是否回到起点,直接判断起点到该点的距离是否为这条边的长度即可,复杂度降成365.

3.每次往下搜索的时候都要去判断是否把这个点定住,当前的所有点仍然是一个凸包,因为满足的条件的凸包不多,所以这部分剪枝剪得比较多.

附赠数据:

6

60 203 113 164 169 131 

6

185 198 159 109 69 120

6

246 261 281 217 240 225

6

290 124 130 16 112 120

0

41636

37323

125526

32088

 //      ——By DD_BOND

 //#include<bits/stdc++.h>
//#include<unordered_map>
//#include<unordered_set>
#include<functional>
#include<algorithm>
#include<iostream>
//#include<ext/rope>
#include<iomanip>
#include<climits>
#include<cstring>
#include<cstdlib>
#include<cstddef>
#include<cstdio>
#include<memory>
#include<vector>
#include<cctype>
#include<string>
#include<cmath>
#include<queue>
#include<deque>
#include<ctime>
#include<stack>
#include<map>
#include<set> #define fi first
#define se second
#define MP make_pair
#define pb push_back
#define INF 0x3f3f3f3f
#define pi 3.1415926535898
#define lowbit(a) (a&(-a))
#define lson l,(l+r)/2,rt<<1
#define rson (l+r)/2+1,r,rt<<1|1
#define Min(a,b,c) min(a,min(b,c))
#define Max(a,b,c) max(a,max(b,c))
#define debug(x) cerr<<#x<<"="<<x<<"\n"; //#pragma GCC optimize(3)
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef unsigned long long ull; const int seed=;
const ll LLMAX=2e18;
const int MOD=1e9+;
const double eps=1e-;
const int MAXN=1e6+;
const int hmod1=0x48E2DCE7;
const int hmod2=0x60000005; inline ll sqr(ll x){ return x*x; }
inline int sqr(int x){ return x*x; }
inline double sqr(double x){ return x*x; }
ll __gcd(ll a,ll b){ return b==? a: __gcd(b,a%b); }
ll qpow(ll a,ll n){ll sum=;while(n){if(n&)sum=sum*a%MOD;a=a*a%MOD;n>>=;}return sum;}
inline int dcmp(double x){ if(fabs(x)<eps) return ; return (x>? : -); } struct Point{
int x,y;
Point(){ x=y=; }
Point(int _x,int _y):x(_x),y(_y){}
inline Point operator -(const Point &n)const{
return Point(x-n.x,y-n.y);
}
inline int operator *(const Point &n)const{
return x*n.x+y*n.y;
}
inline int operator ^(const Point &n)const{
return x*n.y-y*n.x;
}
}; Point loc[];
int n,sum,ans,l[];
vector<Point>vec[]; inline void dfs(int p,int x,int y,int res,int area){
if(p==n-){
if(sqr(l[p])!=x*x+y*y) return ;
ans=max(ans,area/);
}
else{
for(int i=;i<(int)vec[l[p]].size();i++){
if(p==&&(vec[l[p]][i].x<||vec[l[p]][i].y<||vec[l[p]][i].x<vec[l[p]][i].y)) continue;
Point tmp(x+vec[l[p]][i].x,y+vec[l[p]][i].y);
if(p==||(p>=&&
( ((loc[p]-loc[p-])^(tmp-loc[p]))>||( ((loc[p]-loc[p-])^(tmp-loc[p]))==&&((loc[p]-loc[p-])*(tmp-loc[p]))> ) )&&
( ((tmp-loc[p])^(Point(,)-tmp))>||( ((tmp-loc[p])^(Point(,)-tmp))==&&((tmp-loc[p])*(Point(,)-tmp))> ) )&&
( ((Point(,)-tmp)^loc[])>||( ((Point(,)-tmp)^loc[])==&&((Point(,)-tmp)*loc[])> ) )&&
tmp.x*tmp.x+tmp.y*tmp.y<=sqr(sum-res-l[p]) ) ){
int now=area;
loc[p+]=tmp;
if(p>=) now+=loc[p]^loc[p+];
dfs(p+,tmp.x,tmp.y,res+l[p],now);
}
}
}
} int main(void)
{
loc[]=Point(,);
for(int i=-;i<=;i++)
for(int j=-;j<=;j++){
int p=i*i+j*j;
int sq=round(sqrt(p));
if(sq>||sq*sq!=p) continue;
vec[sq].pb(Point(i,j));
}
while(scanf("%d",&n)&&n){
sum=; ans=-;
for(int i=;i<n;i++) scanf("%d",&l[i]),sum+=l[i];
sort(l,l+n);
do{ dfs(,,,,); }while(next_permutation(l+,l+n));
if(ans==) ans=-;
printf("%d\n",ans);
}
return ;
}

POJ 3135 Polygons on the Grid(枚举+凸包)的更多相关文章

  1. POJ 1873 The Fortified Forest(枚举+凸包)

    Description Once upon a time, in a faraway land, there lived a king. This king owned a small collect ...

  2. POJ.3279 Fliptile (搜索+二进制枚举+开关问题)

    POJ.3279 Fliptile (搜索+二进制枚举+开关问题) 题意分析 题意大概就是给出一个map,由01组成,每次可以选取按其中某一个位置,按此位置之后,此位置及其直接相连(上下左右)的位置( ...

  3. POJ 1873 UVA 811 The Fortified Forest (凸包 + 状态压缩枚举)

    题目链接:UVA 811 Description Once upon a time, in a faraway land, there lived a king. This king owned a ...

  4. poj 1113:Wall(计算几何,求凸包周长)

    Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 28462   Accepted: 9498 Description ...

  5. 【POJ】1228 Grandpa's Estate(凸包)

    http://poj.org/problem?id=1228 随便看看就能发现,凸包上的每条边必须满足,有相邻的边和它斜率相同(即共线或凸包上每个点必须一定在三点共线上) 然后愉快敲完凸包+斜率判定, ...

  6. Poj(3522),UVa(1395),枚举生成树

    题目链接:http://poj.org/problem?id=3522 Slim Span Time Limit: 5000MS   Memory Limit: 65536K Total Submis ...

  7. Codeforces Round #249 (Div. 2) D. Special Grid 枚举

    题目链接: http://codeforces.com/contest/435/problem/D D. Special Grid time limit per test:4 secondsmemor ...

  8. poj 3740 Easy Finding 二进制压缩枚举dfs 与 DLX模板详细解析

    题目链接:http://poj.org/problem?id=3740 题意: 是否从0,1矩阵中选出若干行,使得新的矩阵每一列有且仅有一个1? 原矩阵N*M $ 1<= N <= 16 ...

  9. POJ 1753 Flip Game(二进制枚举)

    题目地址链接:http://poj.org/problem?id=1753 题目大意: 有4*4的正方形,每个格子要么是黑色,要么是白色,当把一个格子的颜色改变(黑->白或者白->黑)时, ...

随机推荐

  1. 【shell】awk格式对齐文本

    源: 218.104.69.100 218.104.69.100 安徽合肥 218.104.69.99 218.104.69.99 安徽合肥 61.190.72.38 61.190.72.38 安徽合 ...

  2. postman—随机数和Monitors

    postman做重复测试时,随机数就有很大的作用,不用每次都输入 在postman的Params中,输入一个左大括号,会显示三种随机数: 也可以在body中设置 随机数如下: {{$guid}}:添加 ...

  3. 2018山东省赛 G Game ( Nim博弈 && DP )

    题目链接 题意 : 给出 N 堆石子,每次可以选择一堆石子拿走任意颗石子,最后没有石子拿的人为败者.现在后手 Bob 可以在游戏开始前拿掉不超过 d 堆的整堆石子,现在问你有几种取走的组合使得 Bob ...

  4. 病毒 x

    04:病毒 查看 提交 统计 提问 总时间限制:  1000ms 内存限制:  65535kB 描述 有一天,小y突然发现自己的计算机感染了一种病毒!还好,小y发现这种病毒很弱,只是会把文档中的所有字 ...

  5. MySQL的(@i:=@i+1)用处及用法

    今天写一个为查询的数据排序列号的SQL语句,整理出来下面的笔记: 这是语法:   SELECT (@i:=@i+1),t.* FROM table_name t,(SELECT @i:=0) AS j ...

  6. (四)mysql -- 常用函数

    今天get一个,先记录一下 以后慢慢补充~ 将varchar转换成int 例如:select * from tb_1 order by cast(sport_sum as unsigned integ ...

  7. 大哥带的MSsql注入(SQL Server)--预习

    ①判断数据库类型and exists (select * from sysobjects)--返回正常为mssql(也名sql server)and exists (select count(*) f ...

  8. [CSP-S模拟测试]:简单计算(数学)

    题目传送门(内部题104) 输入格式 第一行一个正整数$T$,表示该测试点内的数据组数,你需要对该测试点内的$T$组数据都分别给出正确的答案才能获得该测试点的分数. 接下来$T$组数据,每组数据一行两 ...

  9. 问:在指定的JSON数据中(最外层是数组)根据指定条件拿到匹配到的结果

    let carr = [{ "code": "000", "agyTypeCode": "1", "name& ...

  10. web编辑器的快捷键

    alt 键:可以同时选中多个光标 .box 按住 tab 键 可以快速的 <div class="box"></div> #box 按住 tab 键 可以快 ...