Run
Time limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): 101 Accepted Submission (s): 43
Problem Descriptionafa is a girl who like runing. Today,he download an app about runing. The app can record the trace of her runing. AFA'll start runing in the park. There is many chairs in the Park,and AFA would start his runing in a chair and end in this chair. Between Chairs,she running in a line.she want the the trace can be a regular triangle or a square or a regular pentago N or a regular hexagon.
Many ways can her find.
Ways is same if the set of chair that they contains is same.
Inputthere is multiply case.
In each case,there are a integer n (1 < = n < =) in a line.
In next n lines,there is integers xi,yi (0 < = Xi,yi < 9) in each line.
Outputoutput the number of ways.
Sample INPUT40 00 11 01 1
Sample OUTPUT1 Although the topic is very simple, I still have a generic code.
#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 = (is); 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#defineGETS (CH) fgets (CH), Maxn,stdin) #define INF 0x3f3f3f3f#define MOD 1000000007using 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];p oint list[5];int Crosses (point p0,point p1,point p2)//calculate cross product 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)//calculates the distance of the 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)//Polar sort function, the same angle is the small distance in front {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)//Calculate dot product 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); can only form 4-side cout << ans << endl; }}
HDU 5365 (Computational geometry)