Hdu 5563 Clarke and five-pointed Star (enumeration)

Source: Internet
Author: User

Test instructions: Give the coordinates of 5 points and ask whether the 5 points are exactly the vertices of a pentagram.

Ideas:

The DFS enumerates the order of 5 points.

Judge 5 adjacent edges equal and 5 diagonal lines equal. If all are satisfied then yes, otherwise not.

Attached: Why should we judge 5 diagonal lines equally?

, a square above a positive triangle, also satisfies 5 adjacent edges equal, but does not satisfy 5 diagonal lines equal.

Code:

1#include <cstdio>2#include <cstring>3#include <iostream>4#include <algorithm>5#include <cstdlib>6#include <cmath>7#include <vector>8#include <queue>9#include <map>Ten#include <Set> One #defineEPS 10e-6 A  - using namespacestd; -  the Doublex[8],y[8]; - BOOLvis[8]; - intorder[6]; - Doubledis[ A]; +  - DoubleCalintIintj) + { A     return(X[i]-x[j]) * (X[i]-x[j]) + (Y[i]-y[j]) * (y[i]-y[j]); at } -  - BOOLisOK () - { -      for(intI=0;i<4; i++) -Dis[i] = cal (order[i+1],order[i+2]); indis[4] = cal (order[5],order[1]); -     intFlag1 =1; to      for(intI=0;i<4; i++) +     { -         if(Fabs (dis[i]-dis[4]) >EPS) the         { *Flag1 =0; $              Break;Panax Notoginseng         } -     } the  +dis[5] = cal (order[1],order[3]); Adis[6] = cal (order[1],order[4]); thedis[7] = cal (order[2],order[4]); +dis[8] = cal (order[2],order[5]); -dis[9] = cal (order[3],order[5]); $     intFlag2 =1; $      for(intI=5;i<9; i++) -     { -         if(Fabs (dis[i]-dis[9]) >EPS) the         { -Flag2 =0;Wuyi              Break; the         } -     } Wu     returnFlag1 &&Flag2; - } About  $ BOOLDfsintPOS) - { -     if(pos = =6) -     { A         if(isOK ()) +             return true; the     } -      for(intI=0;i<5; i++) $     { the         if(!Vis[i]) the         { theOrder[pos] =i; theVis[i] =true; -             if(Dfs (pos+1))return true; inVis[i] =false; the         } the     } About     return false; the } the  the intMain () + { -     intT; thescanf"%d",&T);Bayi      while(t--) the     { thememset (Vis,0,sizeof(Vis)); -          for(intI=0;i<5; i++) -scanf"%LF%LF",&x[i],&y[i]); the         if(Dfs (1)) puts ("Yes"); the         ElsePuts"No"); the     } the     return 0; -}
View Code

Hdu 5563 Clarke and five-pointed Star (enumeration)

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.