题目大意是让你用这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

  1. // ——By DD_BOND
  2.  
  3. //#include<bits/stdc++.h>
  4. //#include<unordered_map>
  5. //#include<unordered_set>
  6. #include<functional>
  7. #include<algorithm>
  8. #include<iostream>
  9. //#include<ext/rope>
  10. #include<iomanip>
  11. #include<climits>
  12. #include<cstring>
  13. #include<cstdlib>
  14. #include<cstddef>
  15. #include<cstdio>
  16. #include<memory>
  17. #include<vector>
  18. #include<cctype>
  19. #include<string>
  20. #include<cmath>
  21. #include<queue>
  22. #include<deque>
  23. #include<ctime>
  24. #include<stack>
  25. #include<map>
  26. #include<set>
  27.  
  28. #define fi first
  29. #define se second
  30. #define MP make_pair
  31. #define pb push_back
  32. #define INF 0x3f3f3f3f
  33. #define pi 3.1415926535898
  34. #define lowbit(a) (a&(-a))
  35. #define lson l,(l+r)/2,rt<<1
  36. #define rson (l+r)/2+1,r,rt<<1|1
  37. #define Min(a,b,c) min(a,min(b,c))
  38. #define Max(a,b,c) max(a,max(b,c))
  39. #define debug(x) cerr<<#x<<"="<<x<<"\n";
  40.  
  41. //#pragma GCC optimize(3)
  42. //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  43.  
  44. using namespace std;
  45.  
  46. typedef long long ll;
  47. typedef pair<int,int> P;
  48. typedef pair<ll,ll> Pll;
  49. typedef unsigned long long ull;
  50.  
  51. const int seed=;
  52. const ll LLMAX=2e18;
  53. const int MOD=1e9+;
  54. const double eps=1e-;
  55. const int MAXN=1e6+;
  56. const int hmod1=0x48E2DCE7;
  57. const int hmod2=0x60000005;
  58.  
  59. inline ll sqr(ll x){ return x*x; }
  60. inline int sqr(int x){ return x*x; }
  61. inline double sqr(double x){ return x*x; }
  62. ll __gcd(ll a,ll b){ return b==? a: __gcd(b,a%b); }
  63. ll qpow(ll a,ll n){ll sum=;while(n){if(n&)sum=sum*a%MOD;a=a*a%MOD;n>>=;}return sum;}
  64. inline int dcmp(double x){ if(fabs(x)<eps) return ; return (x>? : -); }
  65.  
  66. struct Point{
  67. int x,y;
  68. Point(){ x=y=; }
  69. Point(int _x,int _y):x(_x),y(_y){}
  70. inline Point operator -(const Point &n)const{
  71. return Point(x-n.x,y-n.y);
  72. }
  73. inline int operator *(const Point &n)const{
  74. return x*n.x+y*n.y;
  75. }
  76. inline int operator ^(const Point &n)const{
  77. return x*n.y-y*n.x;
  78. }
  79. };
  80.  
  81. Point loc[];
  82. int n,sum,ans,l[];
  83. vector<Point>vec[];
  84.  
  85. inline void dfs(int p,int x,int y,int res,int area){
  86. if(p==n-){
  87. if(sqr(l[p])!=x*x+y*y) return ;
  88. ans=max(ans,area/);
  89. }
  90. else{
  91. for(int i=;i<(int)vec[l[p]].size();i++){
  92. if(p==&&(vec[l[p]][i].x<||vec[l[p]][i].y<||vec[l[p]][i].x<vec[l[p]][i].y)) continue;
  93. Point tmp(x+vec[l[p]][i].x,y+vec[l[p]][i].y);
  94. if(p==||(p>=&&
  95. ( ((loc[p]-loc[p-])^(tmp-loc[p]))>||( ((loc[p]-loc[p-])^(tmp-loc[p]))==&&((loc[p]-loc[p-])*(tmp-loc[p]))> ) )&&
  96. ( ((tmp-loc[p])^(Point(,)-tmp))>||( ((tmp-loc[p])^(Point(,)-tmp))==&&((tmp-loc[p])*(Point(,)-tmp))> ) )&&
  97. ( ((Point(,)-tmp)^loc[])>||( ((Point(,)-tmp)^loc[])==&&((Point(,)-tmp)*loc[])> ) )&&
  98. tmp.x*tmp.x+tmp.y*tmp.y<=sqr(sum-res-l[p]) ) ){
  99. int now=area;
  100. loc[p+]=tmp;
  101. if(p>=) now+=loc[p]^loc[p+];
  102. dfs(p+,tmp.x,tmp.y,res+l[p],now);
  103. }
  104. }
  105. }
  106. }
  107.  
  108. int main(void)
  109. {
  110. loc[]=Point(,);
  111. for(int i=-;i<=;i++)
  112. for(int j=-;j<=;j++){
  113. int p=i*i+j*j;
  114. int sq=round(sqrt(p));
  115. if(sq>||sq*sq!=p) continue;
  116. vec[sq].pb(Point(i,j));
  117. }
  118. while(scanf("%d",&n)&&n){
  119. sum=; ans=-;
  120. for(int i=;i<n;i++) scanf("%d",&l[i]),sum+=l[i];
  121. sort(l,l+n);
  122. do{ dfs(,,,,); }while(next_permutation(l+,l+n));
  123. if(ans==) ans=-;
  124. printf("%d\n",ans);
  125. }
  126. return ;
  127. }

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. python 面向对象_2

    self的理解 通俗理解self就是实例对象,实例化的是什么,self就是什么 实例变量: 经过实例化才能使用的变量 class Person(): def __init__(self,id,name ...

  2. node.js入门学习(六)--express

    1.官网:http://expressjs.com/ 中文:http://www.expressjs.com.cn/ 2.HelloWorld 1)mkdir node-express-demo 2) ...

  3. Redis实战(十五)Redis实现接口调用频率限制

    序言 登录次数 资料

  4. C++ - 操作运算符

    一.操作运算符 操作运算符:在C++中,编译器有能力将数据.对象和操作符共同组成表达式,解释为对全局或成员函数的调用 该全局或成员函数被称为操作符函数,程序员可以通过重定义函数操作符函数,来达到自己想 ...

  5. POJ 1912 凸包

    题目: #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib& ...

  6. windows 安装 Mongodb 数据库及操作图形化软件 Robo 3T

    1 下载系统对应的正确 Mongodb 和 Robo 3T 版本 2 选中 Mongodb 需要安装的路径(后续会使用路径) 3 启动 Mongodb 服务器(到安装相关的路径) 可以参考 菜鸟教程 ...

  7. 手动创建Maven项目并建立两个项目之间的依赖关系

    用命令行快速建立maven项目 -> mvn:archetype:generate -> 直接回车或者自己输入你想生成的 -> groupId ->artifactId -&g ...

  8. 利用IKVM在C#中调Java程序(总结+案例)

    IKVM.NET是一个针对Mono和微软.net框架的java实现,其设计目的是在.NET平台上运行java程序.本文将比较详细的介绍这个工具的原理.使用入门(如何java应用转换为.NET应用.), ...

  9. Json C#解析

    介绍 项目中数据格式如果是是Json格式,推荐大家使用LitJson和Newtonsoft.json进行解析 库的详细介绍和下载地址 推荐使用VS自带的Nuget来使用 Newtonsoft.Json ...

  10. event.currentTarget

    https://api.jquery.com/event.currentTarget/ event.currentTargetReturns: Element Description: The cur ...