标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 101 Accepted Submission(s): 43
#include <map> #include <set> #include <list> #include <stack> #include <queue> #include <deque> #include <cmath> #include <ctime> #include <cstdio> #include <vector> #include <bitset> #include <sstream> #include <cstdlib> #include <complex> #include <climits> #include <cstring> #include <iostream> #include <algorithm> #define REP(i,N) for (int i = 0;i < (N);i++) #define REP_1(i,N) for (int i = 1;i < (N);i++) #define REP_2(i,be,en) for (int i = (be);i < (en);i++) #define DWN(i,N) for (int i = (N);i >= 0;i--) #define DWN_1(i,N) for (int i = (N);i >= 1;i--) #define DWN_2(i,en,be) for (int i = (en);i >= (be);i--) #define FR(N) freopen((N),"r",stdin) #define FW(N) freopen((N),"w",stdout) #define SO(N) scanf("%d",&(N)) #define STO(N,M) scanf("%d %d",&(N),&(M)) #define STH(N,M,K) scanf("%d %d %d",&(N),&(M),&(K)) #define PS(N) printf("%d",(int)(N)); #define MAXN 2010 #define GETS(ch) fgets((ch),MAXN,stdin) #define INF 0x3f3f3f3f #define MOD 1000000007 using namespace std; typedef long long LL; typedef LL ll; typedef map<int,LL> MINT; typedef map<char,int> MCH; typedef map<string,int> MSTR; typedef vector<int> VINT; typedef set<LL> SINT; typedef pair<int,int> PINT; LL read(){ LL ret=0,f=1; char x=getchar(); while(!(x>=‘0‘ && x<=‘9‘)){if(x==‘-‘)f=-1;x=getchar();} while(x>=‘0‘ && x<=‘9‘) ret=ret*10+x-‘0‘, x=getchar(); return ret*f; } class point { public: int x,y; }node[30]; point List[5]; int cross(point p0,point p1,point p2) //计算叉积 p0p1 X p0p2 { return (p1.x-p0.x)*(p2.y-p0.y)-(p1.y-p0.y)*(p2.x-p0.x); } double dis(point p1,point p2) //计算 p1p2的 距离 { return sqrt((double)(p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y)); } bool cmp(point p1,point p2) //极角排序函数 , 角度相同则距离小的在前面 { int tmp=cross(List[0],p1,p2); if(tmp>0) return true; else if(tmp==0&&dis(List[0],p1)<dis(List[0],p2)) return true; else return false; } int cross2(point p0,point p1,point p2) //计算点积 p0p1 · p1p2 { return (p1.x-p0.x)*(p2.x-p1.x)+(p1.y-p0.y)*(p2.y-p1.y); } int ans = 0; int work(vector<int> V) { int len = V.size(); for (int i = 1;i < len;i++) { if (node[V[i]].x < node[V[0]].x) { swap(V[i],V[0]); } else if (node[V[i]].x == node[V[0]].x) { if (node[V[i]].y < node[V[0]].y) { swap(V[i],V[0]); } } } for (int i = 0;i < len;i++) { List[i] = node[V[i]]; } sort(List,List + len,cmp); for (int i = 0;i < len - 1;i++) { if (dis(List[i],List[i + 1]) - dis(List[i + 1],List[(i + 2) % len]) > 1e-6) return 0; if (cross2(List[(i + len - 1) % len],List[i],List[i + 1]) != 0) return 0; } return 1; } int N; void dfs(int u,int pos,vector<int> V,int num) { if (pos == num) { ans += work(V); return; } if (u >= N) return; V.push_back(u); dfs(u + 1,pos + 1,V,num); V.pop_back(); dfs(u + 1,pos,V,num); } int main() { while (cin >> N) { for (int i = 0;i < N;i++) { cin >> node[i].x >> node[i].y; } vector<int> V; V.clear(); ans = 0; dfs(0,0,V,4); // 只能形成4边形 cout << ans << endl; } }
标签:
原文地址:http://www.cnblogs.com/xiaoshanshan/p/4714185.html