• CF291-B


    B. Han Solo and Lazer Gun
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.

    Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x0, y0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x0, y0).

    Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.

    The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.

    Input

    The first line contains three integers n, x0 и y0 (1 ≤ n ≤ 1000,  - 104 ≤ x0, y0 ≤ 104) — the number of stormtroopers on the battle field and the coordinates of your gun.

    Next n lines contain two integers each xi, yi ( - 104 ≤ xi, yi ≤ 104) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.

    Output

    Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.

    Sample test(s)
    input
    4 0 0
    1 1
    2 2
    2 0
    -1 -1
    output
    2
    input
    2 1 2
    1 1
    1 0
    output
    1
    Note

    Explanation to the first and second samples from the statement, respectively:

     给定n个敌人的位置和枪的起始位置,一枪可以射杀经过枪位置直线上的所有敌人

    问至少需要多少枪可以杀光所有敌人

    数学题,用斜率或者叉积都可以求解

    我用的是斜率,将枪的位置看成原点,求所有敌人相对枪的坐标,则敌人i的斜率为yi/xi

    枚举每个活着敌人,将和该敌人相同斜率的人都杀光,子弹数+1

    遍历完后子弹数即为答案

    #include <iostream>

    using namespace std;
    int main()
    {
        int n,x,y;
        int use[1010];
        double px[1010];
        double py[1010];
        cin>>n>>x>>y;
        for(int i=1;i<=n;i++)
        {
            cin>>px[i]>>py[i];
            px[i]-=x;
            py[i]-=y;
        }
        int res=0;
        bool flag=false;
        for(int i=1;i<=n;i++)
        {
            if(px[i]==0)
            {
                use[i]=1;
                if(!flag)
                {
                    flag=true;
                    res++;
                }
                else
                    continue;
            }
            if(!use[i])
            {
                res++;
                use[i]=1;
                double k=py[i]/px[i];
                for(int j=1;j<=n;j++)
                {
                    if(py[j]/px[j]==k&&!use[j])
                        use[j]=1;
                }
            }
        }
        cout<<res<<endl;
        return 0;
    }
    
    
    
    
    
    
  • 相关阅读:
    redhat 7 配置yum本地源
    redhat 7 安装oracle12.1
    Send Email in Robot Framework Python Using Gmail
    Robot Framework 自定义关键字 Ignore error
    Robot Framework Change chrome language
    Chrome profile manager
    Robot Framework 安装AutoItLibrary
    Robot Framework Chrome
    8 结构型模式-----桥接模式
    7 结构型模式-----适配器模式
  • 原文地址:https://www.cnblogs.com/wzsblogs/p/4293192.html
Copyright © 2020-2023  润新知