zoukankan      html  css  js  c++  java
  • poj 3304 计算几何

     大意: 是否存在一条直线,使所有线段在直线上的投影至少交与一点

      思路: 转换为是否存在一条直线与所有的线段相交,做这条直线的垂线,那么垂线即为所求

     3 **/
     4 #include <iostream>
     5 #include <cmath>
     6 using namespace std;
     7 int n;
     8 const double eps = 1e-8;
     9 struct point{
    10     double x,y;
    11 };
    12 
    13 struct line{
    14     point a,b;
    15 };
    16 line l[200];
    17 double dis(point o,point p){
    18     return sqrt((o.x-p.x)*(o.x-p.x)+(o.y-p.y)*(o.y-p.y));
    19 }
    20 
    21 double cross(point o,point p,point q){
    22     return (p.x-o.x)*(q.y-o.y)-(p.y-o.y)*(q.x-o.x);
    23 }
    24 int judge(point t1,point t2){
    25     if(dis(t1,t2)<eps)
    26         return 0;
    27     for(int i=0;i<n;i++)
    28         if(cross(t1,t2,l[i].a)*cross(t1,t2,l[i].b)>eps)
    29             return 0;
    30     return 1;
    31 }
    32 int main(){
    33     int t;
    34     cin>>t;
    35     while(t--){
    36         cin>>n;
    37         for(int i=0;i<n;i++)
    38            cin>>l[i].a.x>>l[i].a.y>>l[i].b.x>>l[i].b.y;
    39         int flag =0;
    40         if(n==1)
    41             flag =1;
    42         for(int i=0;!flag&&i<n;i++){
    43             for(int j=0;!flag&&j<n;j++){
    44                 if(judge(l[i].a,l[j].a)||judge(l[i].a,l[j].b)||judge(l[i].b,l[j].a)||judge(l[i].b,l[j].b))
    45                     flag =1;
    46             }
    47         }
    48         if(flag)
    49             cout<<"Yes!"<<endl;
    50         else{
    51             cout<<"No!"<<endl;
    52         }
    53     }
    54 }
  • 相关阅读:
    INTZ DX format
    多线程渲染
    BindVertexbuffer
    Lock flag DX
    Triple buffering and vsync
    可迭代对象和迭代器
    装饰器
    闭包函数
    名称空间和作用域
    函数对象
  • 原文地址:https://www.cnblogs.com/Bang-cansee/p/3724239.html
Copyright © 2011-2022 走看看