zoukankan      html  css  js  c++  java
  • F

    UVA___10535

    The shooter is in a great problem. He is trapped in a “2D” maze with a laser gun and can use it once. The gun is very powerful and the laser ray, it emanates can traverse infinite distance in its direction. In the maze the targets are some walls (Here this is line segments). If the laser ray touches any wall or intersects it, that wall will be destroyed and the ray will advance ahead. The shooter wants to know the maximum number of walls, he can destroy with a single shot. The shooter will never stand on a wall.

    Input

    The input file contains 100 sets which needs to be processed. The description of each set is given below: Each set starts with a postive integer, N (1 ≤ N ≤ 500) the number of walls. In next few lines there will be 4 ∗ N integers indicating two endpoints of a wall in cartesian co-ordinate system. Next line will contain (x, y) the coordinates of the shooter. All coordinates will be in the range [-10000,10000]. Input is terminated by a case where N = 0. This case should not be processed.

    Output

    For each set of input print the maximum number of walls, he can destroy by a single shot with his gun in a single line.

    Sample Input

    3

    0 0 10 0

    0 1 10 1

    0 2 10 2

    0 -1

    3

    0 0 10 0

    0 1 10 1

    0 3 10 3

    0 2

    0

    Sample Output

    3

    2

    题意:

    从原点开枪,枪的子弹可以穿透墙壁,给出所有墙壁的两个端点以及原点,求最多可以穿透多少墙壁(只能朝一个方向开一枪)

    思路:

    可以将墙与原点的关系转化为可达角度,然后就会形成一个区间,那么问题模型就变为选择一个点,求覆盖到它的最多的区间

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cmath>
    using namespace std;
    #define PI acos(-1.0)
    struct node
    {
        double r;
        int type;
        bool operator < (const struct node&another) const
        {
            if(r!=another.r) return r<another.r;
            return type<another.type;
        }
    }event[5510];
    
    struct cc
    {
        int x0,y0,x1,y1;
    }contra[510];
    
    int x,y;
    
    double caculate(int x0,int y0)
    {
        if(x0==x&&y0>y) return 90;
        if(x0==x&&y0<y) return 270;
        if(x0<x&&y0==y) return 180;
        if(x0>x&&y0==y) return 0;
    
        double acor=atan((y0-y)*1.0/(x0-x));
        if(acor<0) acor+=PI;
        if(y0<y)   return 180+acor*180/(PI);
        return acor*180/PI;
    }
    
    int main()
    {
         int n;
         while(~scanf("%d",&n),n!=0)
         {
           for(int i=0;i<n;i++)
           cin>>contra[i].x0>>contra[i].y0>>contra[i].x1>>contra[i].y1;
    
           cin>>x>>y;
    
           int id=0;
           for(int i=0;i<n;i++)
           {
               int l=caculate(contra[i].x0,contra[i].y0);
               int r=caculate(contra[i].x1,contra[i].y1);
               if(l>r) swap(l,r);
               if(r-l>=180)
               {
                   event[id].r=0;event[id++].type=-1;
                   event[id].r=l;event[id++].type=1;
                   event[id].r=r;event[id++].type=-1;
                   event[id].r=360;event[id++].type=1;
                   continue;
               }
               event[id].r=l;event[id++].type=-1;
               event[id].r=r;event[id++].type=1;
           }
           sort(event,event+id);
           int maxx=0;
           int cur=0;
           for(int i=0;i<id;i++)
           {
               if(event[i].type==-1) {cur++;maxx=max(maxx,cur);}
               else cur--;
           }
           cout<<maxx<<endl;
         }
         return 0;
    }
    View Code
  • 相关阅读:
    怎样获取当前文档的域名
    怎样获取当前网页的URL
    怎样获取所有style节点
    怎样获取所有的script节点
    怎样获取所有的embed节点对象
    怎样获取页面中的所有图片节点
    怎样获取页面中的表单元素节点
    怎样获取页面中所有带href属性的标签集合
    怎样获取当前页面内的全屏状态的元素节点
    怎样获取当前页面的焦点聚焦元素节点
  • 原文地址:https://www.cnblogs.com/zsyacm666666/p/4909021.html
Copyright © 2011-2022 走看看