题目链接:http://codeforces.com/problemset/problem/514/B

题目意思:给出双头枪的位置(x0, y0),以及 n 个突击队成员的坐标。双头枪射击一次,可以把它对住的方向(是直线,不是射线,因为是双头嘛)所有的人射杀掉。问将所有突击队成员消灭的最少射击数是多少。

首先要清楚的是,双头枪可以瞄准的方向是无限的,所以通过枚举所有方向是不现实的!方向其实就是对应斜率,但是没有理由把函数求出然后将士兵的位置一个一个代入来做吧~~~所以呢,直接求 k 就可以了,k 表示枪(x0, y0)和任意士兵(x, y)的斜率。即 k =(y - y0)/ (x - x0)

做的过程中要注意两个问题。 (1)k 有可能除不尽,所以要用 double 来保存。 (2)x - x0 有可能等于0,除数不能为 0 的!!但是也属于可行的一个方向,要单独判断,统计到答案中的其中一个解里。保存完所有 k 之后,去重后统计有多少个不同的 k 就是问题答案了。

  其实还有一个地方有点疑问,就是浮点数比较。本来打算用精度控制,毕竟比较的时候用 “ = ”多少是有一点误差的,但居然过了,可能数据比较弱吧,这个不太清楚,希望有能之士可以指点指点,不胜感激 [^__^]

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std; const int maxn = + ;
double k[maxn]; int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE int n;
int x0, y0, x, y;
while (scanf("%d%d%d", &n, &x0, &y0) != EOF) {
int cnt = ;
int f = ;
int ans = ;
for (int i = ; i < n; i++) {
scanf("%d%d", &x, &y);
double tx = x - x0;
double ty = y - y0;
if (tx == && !f) {
ans++;
f = ;
}
else if (tx != )
k[cnt++] = ty / tx; // 注意 cnt 不一定等于 n
} sort(k, k+cnt);
for (int i = ; i < cnt; i++) {
while (k[i] == k[i+] && i < cnt)
i++;
ans++;
}
printf("%d\n", ans);
}
return ;
}

codeforces 514B. Han Solo and Lazer Gun 解题报告的更多相关文章

  1. 【codeforces 514B】Han Solo and Lazer Gun

    [题目链接]:http://codeforces.com/contest/514/problem/B [题意] 每次攻击可以把经过自己的一条直线上的所有点都毁掉; 然后给你n个目标物的坐标 问你最少要 ...

  2. 数学 Codeforces Round #291 (Div. 2) B. Han Solo and Lazer Gun

    题目传送门 /* 水题,就是用三点共线的式子来判断射击次数 */ #include <cstdio> #include <cmath> #include <string& ...

  3. Codeforces Round #291 (Div. 2) B. Han Solo and Lazer Gun

    因为是x,y均为整数因此对于同一直线的点,其最简分数x/y是相同的(y可以为0,这里不做除法)于是将这些点不断求最简分数用pair在set中去重即可. #include <cmath> # ...

  4. codeforces 814B.An express train to reveries 解题报告

    题目链接:http://codeforces.com/problemset/problem/814/B 题目意思:分别给定一个长度为 n 的不相同序列 a 和 b.这两个序列至少有 i 个位置(1 ≤ ...

  5. codeforces 558B. Amr and The Large Array 解题报告

    题目链接:http://codeforces.com/problemset/problem/558/B 题目意思:给出一个序列,然后找出出现次数最多,但区间占用长度最短的区间左右值. 由于是边读入边比 ...

  6. codeforces 515B. Drazil and His Happy Friends 解题报告

    题目链接:http://codeforces.com/problemset/problem/515/B 题目意思:有 n 个 boy 和 m 个 girl,有 b 个 boy 和 g 个 girl ( ...

  7. codeforces 471C.MUH and House of Cards 解题报告

    题目链接:http://codeforces.com/problemset/problem/471/C 题目意思:有 n 张卡,问能做成多少种不同楼层(floor)的 house,注意这 n 张卡都要 ...

  8. codeforces C. Vasily the Bear and Sequence 解题报告

    题目链接:http://codeforces.com/problemset/problem/336/C 题目意思:给出一个递增的正整数序列 a1, a2, ..., an,要求从中选出一堆数b1, b ...

  9. codeforces A. Vasily the Bear and Triangle 解题报告

    题目链接:http://codeforces.com/problemset/problem/336/A 好简单的一条数学题,是8月9日的.比赛中没有做出来,今天看,从pupil变成Newbie了,那个 ...

随机推荐

  1. 点击每个li输出里面的内容(前端很常问的面试题之一)

    点击每个li输出里面的内容(前端很常问的面试题之一) 前端 面试 JavaScript <!DOCTYPE html> <html lang="en"> & ...

  2. POJ 2031 Building a Space Station

    3维空间中的最小生成树....好久没碰关于图的东西了.....              Building a Space Station Time Limit: 1000MS   Memory Li ...

  3. 2014牡丹江D Domination

    Domination Time Limit: 8 Seconds      Memory Limit: 131072 KB      Special Judge Edward is the headm ...

  4. 【bzoj1036】[ZJOI2008]树的统计Count

    题目描述 一棵树上有n个节点,编号分别为1到n,每个节点都有一个权值w.我们将以下面的形式来要求你对这棵树完成一些操作: I. CHANGE u t : 把结点u的权值改为t II. QMAX u v ...

  5. 如何查看 Linux是32位还是64位?

    方法一:执行命令 file /sbin/init [root@localhost jianbao]# file /sbin/init /sbin/init: ELF 32-bit LSB shared ...

  6. jQuery - 动态创建iframe并加载页面

    <html> <head> <script language="JavaScript" src="jquery-1.11.1.min.js& ...

  7. N-Queens leetcode

    The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens ...

  8. 2015安徽省赛 I.梯田

    http://xcacm.hfut.edu.cn/problem.php?id=1213 set + 搜索 姐姐是用搜索+二分做的,效率要高很多 #include<iostream> #i ...

  9. BZOJ 3942: [Usaco2015 Feb]Censoring

    Description 有两个字符串,每次用一个中取出下一位,放在一个字符串中,如果当前字符串的后缀是另一个字符串就删除. Sol KMP+栈. 用一个栈来维护新加的字符串就可以了.. 一开始我非常的 ...

  10. 可复用View的PagerAdapter

    用PagerAdapter的时候会反复调用instantiateItem和destroyItem来创建和销毁View,没有复用性.这里封装了一个可复用View的PagerAdapter,给实现类留下的 ...