Fzu problem 2110 star

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.