• poj1244Slots of Fun


    链接

    几何的简单题,建立坐标,判断相等以及不共线

      1 #include <iostream>
      2 #include<cstdio>
      3 #include<cstring>
      4 #include<algorithm>
      5 #include<stdlib.h>
      6 #include<vector>
      7 #include<cmath>
      8 #include<queue>
      9 #include<set>
     10 using namespace std;
     11 #define N 200
     12 #define LL long long
     13 #define INF 0xfffffff
     14 const double eps = 1e-8;
     15 const double pi = acos(-1.0);
     16 const double inf = ~0u>>2;
     17 char s[N],sr[30];
     18 struct Point
     19 {
     20     double x,y;
     21     Point(double x=0,double y=0):x(x),y(y) {}
     22 }p[N];
     23 vector<Point>ed[30];
     24 typedef Point pointt;
     25 pointt operator + (Point a,Point b)
     26 {
     27     return Point(a.x+b.x,a.y+b.y);
     28 }
     29 pointt operator - (Point a,Point b)
     30 {
     31     return Point(a.x-b.x,a.y-b.y);
     32 }
     33 int dcmp(double x)
     34 {
     35     if(fabs(x)<eps) return 0;
     36     else return x<0?-1:1;
     37 }
     38 double dis(Point a)
     39 {
     40     return sqrt(a.x*a.x+a.y*a.y);
     41 }
     42 double cross(Point a,Point b)
     43 {
     44     return a.x*b.y-a.y*b.x;
     45 }
     46 double mul(Point p0,Point p1,Point p2)
     47 {
     48     return cross(p1-p0,p2-p0);
     49 }
     50 int main()
     51 {
     52     int n,i,j,g,e;
     53     while(scanf("%d",&n)&&n)
     54     {
     55         getchar();
     56         for(i = 0; i < 26 ; i++)
     57         ed[i].clear();
     58         for(i = 1 ; i <= n*(n+1)/2; i++)
     59         scanf("%c",&s[i]);
     60         int g = 0;
     61         double tx=n,ty = sqrt(3.0)*(n-1);
     62         for(i = 1 ;i <= n; i++)
     63         {
     64             double x0 = tx-i+1;
     65             double y0 = ty-(i-1)*sqrt(3.0);
     66             for(j = 1; j <= i ;j++)
     67             {
     68                 Point pp;
     69                 pp.y = y0;
     70                 pp.x = x0;
     71                 x0+=2;
     72                 g++;
     73                 ed[s[g]-'a'].push_back(pp);
     74             }
     75         }
     76         int cnt = 0;
     77         for(i = 0; i < 26 ; i++)
     78         {
     79             if(ed[i].size()<3) continue;
     80             int k = ed[i].size();
     81             for(j = 0 ;j < k ; j++)
     82                 for(g = j+1 ; g < k ; g++)
     83                     for(e = g+1 ; e < k ; e++)
     84                     {
     85                         Point p1 = ed[i][j],p2 = ed[i][g],p3 = ed[i][e];
     86 //                        cout<<p1.x<<" "<<p1.y<<" "<<p2.x<<" "<<p2.y<<" "<<p3.x<<" "<<p3.y<<endl;
     87 //                        cout<<i<<" "<<dis(p1-p2)<<" "<<dis(p1-p3)<<" "<<dis(p2-p3)<<endl;
     88                         if(dcmp(dis(p1-p2)-dis(p1-p3))==0&&dcmp(dis(p1-p2)-dis(p2-p3))==0&&dcmp(mul(p1,p2,p3))!=0)
     89                         {
     90                             sr[cnt++] = i+'a';
     91                         }
     92                     }
     93         }
     94         if(cnt==0)
     95         {
     96             puts("LOOOOOOOOSER!");
     97             continue;
     98         }
     99         for(i = 0 ; i < cnt ; i++)
    100         printf("%c",sr[i]);
    101         puts("");
    102     }
    103     return 0;
    104 }
    View Code
  • 相关阅读:
    图-拓扑排序
    图-最短路径-Dijkstra及其变种
    【链表问题】打卡7:将单向链表按某值划分成左边小,中间相等,右边大的形式
    【链表问题】打卡5:环形单链表约瑟夫问题
    【链表问题】打卡6:三种方法带你优雅判断回文链表
    【链表问题】打卡4:如何优雅着反转单链表
    【链表问题】打卡3:删除单链表的中间节点
    【链表问题】打卡2:删除单链表的第 K个节点
    史上最全面试题汇总,没有之一,不接受反驳
    一些可以让你装逼的算法技巧总结
  • 原文地址:https://www.cnblogs.com/shangyu/p/3821601.html
Copyright © 2020-2023  润新知