CodeForces 514B
1 second
256 megabytes
standard input
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.
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.
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
4 0 0
1 1
2 2
2 0
-1 -1
2
2 1 2
1 1
1 0
1
Explanation to the first and second samples from the statement, respectively:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std; ///咋看吓一跳,感觉暴力不科学啊,怎么可能知道一条直线上有
///多少点,所以就去计算每个点同炮的斜率,斜率一样,就在同
///同一条直线上。
const int MAX_SIZE = 1E4 + ; int main()
{
//freopen("in.txt", "r", stdin);
int n, i;
int x, y, px, py;
double kx, ky;
bool tag;
double k[MAX_SIZE]; while(scanf("%d %d %d", &n, &x, &y) != EOF)
{
tag = false;
int j = ;
for(i = ; i < n; i++)
{
scanf("%d %d", &px, &py);
kx = px - x;
ky = py - y;
if(kx == )
tag = true;
else
k[j++] = ky / kx;
} sort(k, k+j);
int ans = (tag == true) ? : ; for(i = ; i < j-; i++)
{
if(k[i] != k[i+])
{
ans++;
}
}
ans += (i == j-) ? : ;
cout << ans << endl;
}
return ;
} //题目需要注意的地方是,在中间计算过程,要用double去存储横纵坐标的差值。
CodeForces 514B的更多相关文章
- codeforces 514B. Han Solo and Lazer Gun 解题报告
题目链接:http://codeforces.com/problemset/problem/514/B 题目意思:给出双头枪的位置(x0, y0),以及 n 个突击队成员的坐标.双头枪射击一次,可以把 ...
- 【codeforces 514B】Han Solo and Lazer Gun
[题目链接]:http://codeforces.com/contest/514/problem/B [题意] 每次攻击可以把经过自己的一条直线上的所有点都毁掉; 然后给你n个目标物的坐标 问你最少要 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
随机推荐
- angularjs自带过滤器
filter: filter过滤器第一个参数若是对象: <ul> <li ng-repeat="friend in friends | filter:{'name':'Jo ...
- 这可能是由于服务终结点绑定未使用 HTTP 协议造成的 .这还可能是由于服务器中止了 HTTP 请求上下文
一个很简单的WCF报这个异常,才发现是 Response的类无法被序列化 因为在Response类里有一个枚举 StatusType,而系统的枚举值是 从0-5,但是数据库里多了一个值为6的记录 这样 ...
- Maven+Spring MVC Spring Mybatis配置
环境: Eclipse Neon JDK1.8.0 Tomcat8.0 先决条件: Eclipse先用maven向导创建web工程.参见本站之前随笔. 本机安装完成mysql5:新建用户xuxy03设 ...
- 使用U盘重装电脑操作系统
1. 打开360软件管家,找一个软件"蚂蚁U盘启动"下载,下载好以后打开,电脑上插入U盘,我们制作一个启动U盘备用! 图片图片 按提示制作好启动盘后,保管好U盘. 找一个系统下载网 ...
- dos 固定ip命令
dos 固定ip命令 ***************************************************************************************** ...
- LoadRunner 函数之lr_xml_get_values
简单实例如 char *xml_input = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>&q ...
- [NHibernate]多对多关系(关联查询)
目录 写在前面 文档与系列文章 多对多关系关联查询 总结 写在前面 上篇文章介绍了nhibernate中对一对多关系进行关联查询的几种方式,以及在使用过程需要注意的问题.这篇文章对多对多关系的查询处理 ...
- ActiveMQ的静态网络链接
-------------------------------------------------------------------- (1)ActiveMQ的networkConnector是什么 ...
- PHP 连接 MySQL
PHP 连接 MySQL PHP 5 及以上版本建议使用以下方式连接 MySQL : MySQLi extension ("i" 意为 improved) PDO (PHP Dat ...
- Android锁屏后数据改变的解决方案
如果一个界面设置成横屏,那么锁屏再开启之后,会重新执行一遍onCreate()方法.对于这个问题的解决方案如下: 只需要在Menifest文件的activity相应标签下添加这行代码即可: andro ...