HCW 19 Team Round (ICPC format) H Houston, Are You There?(极角排序)
题目链接:http://codeforces.com/gym/102279/problem/H
大致题意: 你在一个定点,你有个长度为R的钩子,有n个东西在其他点处,问你能勾到的东西的数量是多少?
思路:明明一道几何题,罗老板居然用gcd巧妙的A了,真是太强了。如果一件物品挡住了另一件物品,那么它是勾不到的。
首先将所有距离在R的点都拎出来,然后对于给定点进行极角排序,最后俩俩相邻比较即可确定答案。
AC代码:
#include<cmath>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const double eps = 1e-;
const int maxn = 5e5+;
int sgn(double x){
if(fabs(x) < ) return ;
else return x < ? - : ;
}
struct Point{
double x, y;
Point(){}
Point(double _x, double _y){
x = _x, y = _y;
}
void input(){
scanf("%lf%lf", &x, &y);
}
void output(){
printf("%.2f %.2f",x ,y);
}
bool operator == (Point b) const{
return sgn(x - b.x) == && sgn(y - b.y) == ;
}
bool operator < (Point b)const{
return sgn(x - b.x) == ? sgn(y - b.y < ) : x < b.x;
}
Point operator - (const Point &b)const{
return Point(x - b.x, y - b.y);
}
//叉积
double operator ^(const Point &b){
return x * b.y - y * b.x;
}
//点积
double operator *(const Point &b){
return x * b.x + y * b.y;
}
double distant(Point p){
return hypot(x - p.x, y - p.y);
} };
Point p[maxn];
struct cmp{
Point p;
cmp(const Point &p0) {p = p0;}
bool operator()(const Point &aa, const Point &bb){
Point a = aa, b = bb;
int d = sgn((a - p) ^ (b - p));
if(d == ){
return sgn(a.distant(p) - b.distant(p)) < ;
}
return d > ;
}
}; int main()
{
int n;
double x0, y0, r;
double x, y;
scanf("%lf %lf %lf %d",&x0, &y0, &r, &n);
int m = ;
Point s = Point(x0, y0), e;
while(n--){
e.input();
//printf("d = %.12f\n",e.distant(s) - r);
if(e.distant(s) - r <= )
p[m++] = e;
}
int ans = ;
sort(p, p + m, cmp(s));
for(int i = ;i < m;i++)
{
if(i == ) ans++;
else if(((p[i] - s) ^ (p[i-] - s)) != 0.0)
ans++;
}
printf("%d\n",ans);
return ;
}
附罗老板的神奇gcd:(明显代码长度短很多啊orz)
HCW 19 Team Round (ICPC format) H Houston, Are You There?(极角排序)的更多相关文章
- HCW 19 Team Round (ICPC format) B. Beggin' For A Node(树的重心,交互题)
B. Beggin' For A Node time limit per test2.0 s memory limit per test256 MB inputstandard input outpu ...
- Codeforces Round #124 (Div. 1) C. Paint Tree(极角排序)
C. Paint Tree time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Educational Codeforces Round 1 C. Nearest vectors 极角排序
Partial Tree Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/598/problem/ ...
- 2018 ICPC北京 H ac自动机
n=40的01串,求有多少m=40的01串中包含它,包含的定义是存在子串有至多一个字符不相同 600组n=15的数据 15组n=40的数据,所以我们只能支持n^5的算法. 陷入两个比较有意思的坑: 1 ...
- icpc 银川 H. Delivery Route SPFA优化
Problem Description Pony is the boss of a courier company. The company needs to deliver packages to ...
- Codeforces Round #292 (Div. 1) B. Drazil and Tiles 拓扑排序
B. Drazil and Tiles 题目连接: http://codeforces.com/contest/516/problem/B Description Drazil created a f ...
- Codeforces Round #292 (Div. 2) D. Drazil and Tiles [拓扑排序 dfs]
传送门 D. Drazil and Tiles time limit per test 2 seconds memory limit per test 256 megabytes Drazil cre ...
- Codeforces Round #404 (Div. 2)(A.水,暴力,B,排序,贪心)
A. Anton and Polyhedrons time limit per test:2 seconds memory limit per test:256 megabytes input:sta ...
- Codeforces Round #541 (Div. 2) D 并查集 + 拓扑排序
https://codeforces.com/contest/1131/problem/D 题意 给你一个n*m二维偏序表,代表x[i]和y[j]的大小关系,根据表构造大小分别为n,m的x[],y[] ...
随机推荐
- jquery与其他js冲突
var $j=JQuery.noConflict(); $j('#msg').hide();//此处$j就代表JQuery //重命名以下,把$改为$j
- 56、salesforce学习笔记(三)
Date类型 Datetime nowDatetime = Datetime.now(); Datetime datetime1 = Datetime.newInstance(2015,3,1,13, ...
- Dubbo入门到精通学习笔记(十八):使用Redis3.0集群实现Tomcat集群的Session共享
文章目录 1.单节点访问http://192.168.1.61:8082/pay-web-boss/: 2.增加多一个消费者节点:192.168.1.62,以同样的方式部署pay-web-boss工程 ...
- 2019 ACM-ICPC 南京 现场赛 H. Prince and Princess
题意 王子想要娶公主,但是需要完成一个挑战:在一些房间中找出公主在哪. 每个房间有一个人,他们彼此知道谁在哪个房间.可以问他们三种问题: 你是谁? 在某个房间是谁? 公主在哪个房间? 有三类人,一类一 ...
- 2019浙江省赛 Strings in the Pocket【manacher】
Strings in the Pocket 题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=6012 题意 给你两个字符 ...
- Rust <8>:lifetime 高级语法与 trait 关联绑定
一.生命周期关联:如下声明表示,'s >= 'c struct Parser<'c, 's: 'c> { context: &'c Context<'s>, } ...
- Django框架(二十八)—— Django缓存机制
目录 Django缓存机制 一.什么是缓存 二.Django的6中缓存方式及配置(只需要改配置文件) 1.开发调试缓存(此模式为开发调试使用,实际上不执行任何操作) 2.内存缓存(将缓存内容保存至内存 ...
- http常见状态码及其解析
HTTP状态码常见状态码及其解析 状态码 状态码英文名称 中文描述 100 Continue 继续.客户端应继续其请求 101 Switching Protocols 切换协议.服务器根据客户端的请求 ...
- spring中@注解的相关解释
@Component:@Controller:@Service:@Repository 在annotaion配置注解中用@Component来表示一个通用注释用于说明一个类是一个spring容器管理的 ...
- php调用系统命令的函数的比较
了解命令的区别并进行直观的选择 这是一篇翻译文章,原作者通过表格的形式更加直观的展现出差异并进行选择 前言 PHP有众多调用系统命令的函数,大致如下: system() exec() passthru ...