Enumeration is fine, because we have just learned DFS, so what we do with DFS is actually three for loops.
#include<cstdio>#include<cmath>#include<cstring>#define HG -1e-12using namespace std;int n,sum,vis[110],temp[5];typedef struct point{ int x,y;} point;point p[110];int isok(int x1,int y1,int x2,int y2,int x3,int y3 ){ double a=sqrt((y2-y1)*1.0*(y2-y1)+(x2-x1)*1.0*(x2-x1)); double b=sqrt((y3-y1)*1.0*(y3-y1)+(x3-x1)*1.0*(x3-x1)); double c=sqrt((y3-y2)*1.0*(y3-y2)+(x3-x2)*1.0*(x3-x2)); double C=(a*a+b*b-c*c)/(2*a*b); double B=(a*a+c*c-b*b)/(2*a*c); double A=(b*b+c*c-a*a)/(2*b*c); if(A>HG&&B>HG&&C>HG) return 1; else return 0;}void dfs(int cur,int num){ vis[cur]=1; temp[num]=cur; if(num==2) { if(isok(p[temp[0]].x,p[temp[0]].y,p[temp[1]].x,p[temp[1]].y,p[temp[2]].x,p[temp[2]].y)) sum++; } else for(int i=0; i<n; i++) { if(!vis[i]&&i>cur) { dfs(i,num+1); vis[i]=0; } }}int main(){ //freopen("in.txt","r",stdin); int cas; scanf("%d",&cas); while(cas--) { scanf("%d",&n); sum=0; for(int i=0; i<n; i++) scanf("%d%d",&p[i].x,&p[i].y); memset(vis,0,sizeof(vis)); for(int i=0; i<n; i++) { memset(vis,0,sizeof(vis)); dfs(i,0); } printf("%d\n",sum); } return 0;}
The first Wa is only conducted DFS (0, 0), no DFS starting from the second point, the second is to determine whether it is an acute triangle, double A = SQRT (y2-y1) * 1.0 * (y2-y1) + (x2-x1) * 1.0 * (x2-x1); this is because the x, y range is 1000000 and will overflow if it is saved with int, so * is converted to double.
"Higher Education Community Cup" third Fujian University Student Program Design Competition