zoukankan      html  css  js  c++  java
  • CodeForces 514B

    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:

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <algorithm>
     4 #include <cstring>
     5 using namespace std;
     6 
     7 ///咋看吓一跳,感觉暴力不科学啊,怎么可能知道一条直线上有
     8 ///多少点,所以就去计算每个点同炮的斜率,斜率一样,就在同
     9 ///同一条直线上。
    10 const int MAX_SIZE = 1E4 + 100;
    11 
    12 int main()
    13 {
    14     //freopen("in.txt", "r", stdin);
    15     int n, i;
    16     int x, y, px, py;
    17     double kx, ky;
    18     bool tag;
    19     double k[MAX_SIZE];
    20 
    21     while(scanf("%d %d %d", &n, &x, &y) != EOF)
    22     {
    23         tag = false;
    24         int j = 0;
    25         for(i = 0; i < n; i++)
    26         {
    27             scanf("%d %d", &px, &py);
    28             kx = px - x;
    29             ky = py - y;
    30             if(kx == 0)
    31                 tag = true;
    32             else
    33                 k[j++] = ky / kx;
    34         }
    35 
    36         sort(k, k+j);
    37         int ans = (tag == true) ? 1 : 0;
    38 
    39         for(i = 0; i < j-1; i++)
    40         {
    41             if(k[i] != k[i+1])
    42             {
    43                 ans++;
    44             }
    45         }
    46         ans += (i == j-1) ? 1 : 0;
    47         cout << ans << endl;
    48     }
    49     return 0;
    50 }
    51 
    52 //题目需要注意的地方是,在中间计算过程,要用double去存储横纵坐标的差值。
    View Code
  • 相关阅读:
    odoo国际化翻译
    Odoo创建基础模块和相关内容
    odoo权限管理(二.记录管理)
    推荐的 MongoDB 安装文档
    Python Spider 抓取今日头条街拍美图
    Python Spider 抓取猫眼电影TOP100
    如何选择 SQL Server 数据库跟操作系统版本
    Mongodb 折腾笔记
    MySQLReport
    kernel TCP time wait bucket table overflow
  • 原文地址:https://www.cnblogs.com/ya-cpp/p/4362889.html
Copyright © 2011-2022 走看看