zoukankan      html  css  js  c++  java
  • 铁轨 (Magnetic Train Tracks,Dhaka 2007,LA 4064)

     1 #include <iostream>
     2 #include <string.h>
     3 #include <string>
     4 #include <fstream>
     5 #include <algorithm>
     6 #include <stdio.h>
     7 #include <vector>
     8 #include <queue>
     9 #include <set>
    10 #include <cmath>
    11 using namespace std;
    12 const double eps = 1e-8;
    13 const double pi=acos(-1.0);
    14 const int INF=0x7fffffff;
    15 unsigned long long uINF = ~0LL;
    16 #define MAXN 10000007
    17 typedef long long LL;
    18 struct node
    19 {
    20     double x,y;
    21 }p[1500];
    22 
    23 node operator-(node a,node b)
    24 {
    25     a.x-=b.x;
    26     a.y-=b.y;
    27     return a;
    28 }
    29 int check(double x)
    30 {
    31     if(fabs(x)<eps)return 0;
    32     return x<0? -1:1;
    33 }
    34 double ang[5500];
    35 int main()
    36 {
    37     int n;int t=1;
    38     while(scanf("%d",&n),n)
    39     {
    40         for(int i=0;i<n;i++)
    41         scanf("%lf%lf",&p[i].x,&p[i].y);
    42 
    43 
    44         printf("Scenario %d:
    ",t++);
    45         if(n<3)
    46         {
    47             printf("There are 0 sites for making valid tracks
    ");
    48             continue;
    49         }
    50         int ans=0;
    51         for(int i=0;i<n;i++)
    52         {
    53             int len=0;node temp;
    54         for(int j=0;j<n;j++)
    55         {
    56             if(i==j)continue;
    57             temp=p[j]-p[i];
    58             ang[len++]=atan2(temp.y,temp.x);
    59         }
    60         sort(ang,ang+len);
    61         for(int j=0;j<len;j++)
    62             ang[j+len]=ang[j]+2*pi;
    63         int t=0;
    64         for(int j=0;j<len;j++)
    65         {
    66             while(check(ang[t]-ang[j]-pi/2)<0)t++;
    67             ans+=t-j-1;
    68         }
    69         }
    70         printf("There are %d sites for making valid tracks
    ",ans-(n*(n-1)*(n-2))/3);
    71     }
    72 
    73     return 0;
    74 }

    统计 2边 角度小于pi/2 的组合 减去重复的 及所求三角形个数

  • 相关阅读:
    「考试总结」2020-12-01 入冬
    「考试总结」2020-11-30 低智
    2020-11-29 自闭瞎写
    「晚测反思」2020-11-26 点亮
    「晚测反思」2020-11-28 复盘
    「刷题笔记」二分图匹配
    「刷题笔记」AC自动机
    「刷题笔记」哈希,kmp,trie
    「刷题笔记」数学I
    「刷题笔记」DP优化-斜率优化
  • 原文地址:https://www.cnblogs.com/TO-Asia/p/3213872.html
Copyright © 2011-2022 走看看