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[] ...
随机推荐
- (转)spring ioc原理(看完后大家可以自己写一个spring)
原文地址:https://blog.csdn.net/it_man/article/details/4402245 最近,买了本Spring入门书:spring In Action .大致浏览了下感觉 ...
- PHP缓存技术相关
全页面静态化缓存也就是将页面全部生成html静态页面,用户访问时直接访问的静态页面,而不会去走php服务器解析的流程.此种方式,在CMS系统中比较常见,比如dedecms:一种比较常用的实现方式是用输 ...
- Rsync 实现服务器文件的同步——服务端的安装配置
一.安装rsync 直接使用yum命令进行安装即可. yum -y install rsync 二.配置文件 网上大多教程都说安装是默认没有配置文件的,但是经过我的尝试,yum安装下默认是有配置文件的 ...
- AVL树,C语言实现,完整代码,先贴上,讲解稍后
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<time.h> #de ...
- A1082 Read Number in Chinese (25 分)
1082 Read Number in Chinese (25 分) Given an integer with no more than 9 digits, you are supposed t ...
- 16-python基础-字典
1.字典的定义 dictionary(字典)是除列表以外python之中最灵活的数据类型. 字典同样可以存储多个数据. 通常用于存储一个物体的相关信息. 和列表的区别 列表是有序的对象集合 字典是无序 ...
- 分布式-技术专区-Redis和MySQL缓存一致性问题
1.Redis 缓存和 MySQL 数据如何实现一致性 需求起因 缓存和数据库一致性解决方案 在高并发的业务场景下,数据库大多数情况都是用户并发访问最薄弱的环节.所以,就需要使用redis做一个缓冲操 ...
- spring基于xml的事务控制
opm配置 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http: ...
- SVM 详解
https://cloud.tencent.com/developer/article/1411618 (关于hinge损失函数的定义) https://zhuanlan.zhihu.com/p/61 ...
- node.js提供的服务器live-server的使用
安装node.js的版本控制工具nvm,在终端中执行 curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/instal ...