Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 239 Accepted Submission(s): 110
先预处理好哪些点的组合可以构成正方形。
然后按照二进制,去寻找答案。
虽然感觉复杂度比较大,但是还是过了。
1 /* *********************************************** 2 Author :kuangbin 3 Created Time :2013/9/15 星期日 14:08:43 4 File Name :2013杭州网络赛\1002.cpp 5 ************************************************ */ 6 7 #pragma comment(linker, "/STACK:1024000000,1024000000") 8 #include <stdio.h> 9 #include <string.h> 10 #include <iostream> 11 #include <algorithm> 12 #include <vector> 13 #include <queue> 14 #include <set> 15 #include <map> 16 #include <string> 17 #include <math.h> 18 #include <stdlib.h> 19 #include <time.h> 20 using namespace std; 21 22 pair<int,int>p[100]; 23 int n; 24 vector<int>vec; 25 26 27 bool judge(pair<int,int>p1,pair<int,int>p2,pair<int,int>p3,pair<int,int>p4) 28 { 29 if(p3.first - p1.first != 0 && p3.second - p1.second == p3.first - p1.first) 30 { 31 if(p2.first == p3.first && p2.second == p1.second) 32 if(p4.first == p1.first && p4.second == p3.second) 33 return true; 34 } 35 return false; 36 } 37 //判断p1p2p3p4四个点能不能形成正方形 38 bool check(pair<int,int>p1,pair<int,int>p2,pair<int,int>p3,pair<int,int>p4) 39 { 40 if(judge(p1,p2,p3,p4))return true; 41 if(judge(p1,p2,p4,p3))return true; 42 if(judge(p1,p3,p2,p4))return true; 43 if(judge(p1,p3,p4,p2))return true; 44 if(judge(p1,p4,p2,p3))return true; 45 if(judge(p1,p4,p3,p2))return true; 46 47 swap(p1,p2); 48 if(judge(p1,p2,p3,p4))return true; 49 if(judge(p1,p2,p4,p3))return true; 50 if(judge(p1,p3,p2,p4))return true; 51 if(judge(p1,p3,p4,p2))return true; 52 if(judge(p1,p4,p2,p3))return true; 53 if(judge(p1,p4,p3,p2))return true; 54 swap(p1,p2); 55 56 swap(p1,p3); 57 if(judge(p1,p2,p3,p4))return true; 58 if(judge(p1,p2,p4,p3))return true; 59 if(judge(p1,p3,p2,p4))return true; 60 if(judge(p1,p3,p4,p2))return true; 61 if(judge(p1,p4,p2,p3))return true; 62 if(judge(p1,p4,p3,p2))return true; 63 swap(p1,p3); 64 65 swap(p1,p4); 66 if(judge(p1,p2,p3,p4))return true; 67 if(judge(p1,p2,p4,p3))return true; 68 if(judge(p1,p3,p2,p4))return true; 69 if(judge(p1,p3,p4,p2))return true; 70 if(judge(p1,p4,p2,p3))return true; 71 if(judge(p1,p4,p3,p2))return true; 72 swap(p1,p4); 73 74 75 return false; 76 77 } 78 79 int dp[1<<20]; 80 int solve(int s) 81 { 82 if(dp[s] != -1)return dp[s]; 83 int ans = 0; 84 int sz = vec.size(); 85 for(int i = 0;i < sz;i++) 86 if((s&vec[i]) == vec[i]) 87 { 88 ans = max(ans,1+solve(s^vec[i])); 89 } 90 return dp[s] = ans; 91 } 92 93 int main() 94 { 95 //freopen("in.txt","r",stdin); 96 //freopen("out.txt","w",stdout); 97 while(scanf("%d",&n) == 1) 98 { 99 if(n == -1)break; 100 vec.clear(); 101 for(int i = 0;i < n;i++) 102 scanf("%d%d",&p[i].first,&p[i].second); 103 //找出所有可以组成正方形的组合 104 for(int i = 0;i < n;i++) 105 for(int j = i+1;j < n;j++) 106 for(int x = j+1;x < n;x++) 107 for(int y = x+1;y < n;y++) 108 if(check(p[i],p[j],p[x],p[y])) 109 { 110 vec.push_back((1<<i)|(1<<j)|(1<<x)|(1<<y)); 111 } 112 memset(dp,-1,sizeof(dp)); 113 int tot = (1<<n) -1; 114 printf("%d\n",4*solve(tot)); 115 } 116 return 0; 117 }