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
  • 相关阅读:
    C#通过模板导出Word(文字,表格,图片) 转载
    转载:mysql新手入门安装配置:mysql 8.0.13 zip安装,初始配置,修改密码(经测试管用)
    转载:MySQL 8.0.19安装教程(windows 64位)
    VS2010上winform打包发布、打包安装程序
    asp.net core mvc权限控制:分配权限
    asp.net core mvc权限控制:权限控制介绍
    实测可用-免费屏幕录制软件下载地址
    Win10激活工具-Win7激活工具-Office激活工具-KMS激活工具汉化版x64下载-实测可用
    C#-WPF实现抽屉式风格主题框架源码-使用MaterialDesignThemes实现WPF炫酷漂亮的效果-提供Demo下载
    C#实现图片暗通道去雾算法-Demo-提供代码实例下载地址
  • 原文地址:https://www.cnblogs.com/zsyacm666666/p/4909021.html
Copyright © 2011-2022 走看看