Ice Igloos Gym - 101480I (暴力技巧)
Problem I: Ice Igloos
\]
题意
给出\(n\)个圆,给出每个圆的坐标\(x\)、\(y\)以及半径\(r\)。
然后给出\(m\)条线段,问线段和几个圆相交。
思路
观察数据范围,\(0 \leq x,y \leq 500,0 < r < 1\),既然数据范围这么小,就可以直接用\(500*500\)的数组存在该点的坐标。
\(\quad\)对于查询的线段,如果\(x1 == x2\),那么就直接暴力查\([x1][y1]\)到\([x1][y2]\)内有圆的点的数量,如果\(y1==y2\),也直接暴力查\([x1][y1]\)到\([x2][y1]\)内有圆的点的数量。
\(\quad\)对于存在斜率的线段,线段上的每一个\(x\)位置直接暴力他附近的点去查这些点是否存在圆,存在圆的话是否会和线段相交,如果这个线段是上升的,查询范围就是\([x][floor(x-1)-eps]\)到\([x][ceil(x+1)+eps]\)。如果线段是下降的,查询范围就是\([x][floor(x+1)-eps]\)到\([x][ceil(x-1)+eps]\),然后特别判断一下线段开始和结束的\(x\)的查询范围,就可以了。
这样查询到的点不会特别大,是\(x2-x1\)的常数级,所以最后的复杂度就是\(O(M*500*k)\)。
/***************************************************************
> File Name : I.cpp
> Author : Jiaaaaaaaqi
> Created Time : 2019年05月06日 星期一 17时14分40秒
***************************************************************/
#include <map>
#include <set>
#include <list>
#include <ctime>
#include <cmath>
#include <stack>
#include <queue>
#include <cfloat>
#include <string>
#include <vector>
#include <cstdio>
#include <bitset>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define lowbit(x) x & (-x)
#define mes(a, b) memset(a, b, sizeof a)
#define fi first
#define se second
#define pii pair<int, int>
#define INOPEN freopen("in.txt", "r", stdin)
#define OUTOPEN freopen("out.txt", "w", stdout)
typedef unsigned long long int ull;
typedef long long int ll;
const int maxn = 5e2 + 10;
const int maxm = 1e5 + 10;
const ll mod = 1e9 + 7;
const ll INF = 1e18 + 100;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-8;
using namespace std;
int n, m;
int cas, tol, T;
long double a, b, c, k, l;
double vv[maxn][maxn];
int sgn(double x) {
if(fabs(x) <= eps) return 0;
else return x>0 ? 1 : -1;
}
void solve(int x1, int y1, int x2, int y2) {
a = y2-y1;
b = x1-x2;
c = y1*(x2-x1)+x1*(y1-y2);
double tmp = sqrt(a*a+b*b);
a /= tmp;
b /= tmp;
c /= tmp;
k = 1.0*(y2-y1)/(x2-x1);
l = y1-k*x1;
}
int x1, y1, x2, y2;
double get(double x) {
return k*x+l;
}
bool ok(int x, int y) {
double r = vv[x][y];
double dis = fabs(a*x+b*y+c);
if(sgn(dis-r) <= 0) return 1;
else return 0;
}
int main() {
for(int i=0; i<=505; i++) {
for(int j=0; j<=505; j++) {
vv[i][j] = 0.0;
}
}
scanf("%d", &n);
double r;
for(int i=1, x, y; i<=n; i++) {
scanf("%d%d%lf", &x, &y, &r);
vv[x][y] = r;
}
scanf("%d", &T);
while(T--) {
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
int ans = 0;
if(x1 == x2) {
if(y1 > y2) swap(y1, y2);
for(int j=y1; j<=y2; j++) {
if(vv[x1][j] != 0) ans++;
}
printf("%d\n", ans);
} else if(y1 == y2) {
if(x1 > x2) swap(x1, x2);
for(int i=x1; i<=x2; i++) {
if(vv[i][y1] != 0) ans++;
}
printf("%d\n", ans);
} else {
if(x1 > x2 || (x1==x2&&y1>y2)) {
swap(x1, x2);
swap(y1, y2);
}
solve(x1, y1, x2, y2);
if(y1 < y2) {
int yy = ceil(get(x1+1)+eps);
for(int i=x1; i<=x1; i++) {
for(int j=y1; j<=yy; j++) {
if(vv[i][j] <= eps) continue;
if(ok(i, j))
ans++;
}
}
for(int x=x1+1; x<x2; x++) {
int yl = floor(get(x-1)-eps);
int yr = ceil(get(x+1)+eps);
for(int i=x; i<=x; i++) {
for(int j=yl; j<=yr; j++) {
if(vv[i][j] <= eps) continue;
if(ok(i, j))
ans++;
}
}
}
yy = floor(get(x2-1)-eps);
for(int i=x2; i<=x2; i++) {
for(int j=yy; j<=y2; j++) {
if(vv[i][j] <= eps) continue;
if(ok(i, j))
ans++;
}
}
printf("%d\n", ans);
} else {
int yy = floor(get(x1+1)-eps);
for(int i=x1; i<=x1; i++) {
for(int j=yy; j<=y1; j++) {
if(vv[i][j] <= eps) continue;
if(ok(i, j))
ans++;
}
}
for(int x=x1+1; x<x2; x++) {
int yl = ceil(get(x-1)+eps);
int yr = floor(get(x+1)-eps);
for(int i=x; i<=x; i++) {
for(int j=yr; j<=yl; j++) {
if(vv[i][j] <= eps) continue;
if(ok(i, j))
ans++;
}
}
}
yy = ceil(get(x2-1)+eps);
for(int i=x2; i<=x2; i++) {
for(int j=y2; j<=yy; j++) {
if(vv[i][j] <= eps) continue;
if(ok(i, j))
ans++;
}
}
printf("%d\n", ans);
}
}
}
return 0;
}
Ice Igloos Gym - 101480I (暴力技巧)的更多相关文章
- HDU 4509 湫湫系列故事——减肥记II(线段树-区间覆盖 或者 暴力技巧)
http://acm.hdu.edu.cn/showproblem.php?pid=4509 题目大意: 中文意义,应该能懂. 解题思路: 因为题目给的时间是一天24小时,而且还有分钟.为了解题方便, ...
- Gym 101480I Ice Igloos(思维乱搞)题解
题意:给个最多500 * 500的平面,有半径最多不为1的n个圆,现在给你1e5条线段,问你每条线段和几个圆相交,时限10s 思路: 因为半径<1,那么我其实搜索的范围只要在线段附近就好了.x1 ...
- Gym 101158D(暴力)
题意:给定两个长度为N的字符串,1<=N<=4000,求满足字符串1中的某个区间所有的字母种类和个数都与字符串2中的某个区间相同最长的区间长度. 分析: 1.预处理每个串字母个数的前缀和. ...
- Codeforces Gym 100418B 暴力
Sum of sequencesTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/v ...
- HDU 2588 GCD 【Euler + 暴力技巧】
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=2588 GCD Time Limit: 2000/1000 MS (Java/Others) Mem ...
- Consonant Fencity Gym - 101612C 暴力二进制枚举 Intelligence in Perpendicularia Gym - 101612I 思维
题意1: 给你一个由小写字母构成的字符串s,你可以其中某些字符变成大写字母.如果s中有字母a,你如果想把a变成大写,那s字符串中的每一个a都要变成A 最后你需要要出来所有的字符对,s[i]和s[i-1 ...
- Gym - 101480 CERC 15:部分题目题解(队内第N次训练)
-------------------题目难度较难,但挺有营养的.慢慢补. A .ASCII Addition pro:用一定的形式表示1到9,让你计算加法. sol:模拟. solved by fz ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- 深度学习中正则化技术概述(附Python代码)
欢迎大家关注我们的网站和系列教程:http://www.tensorflownews.com/,学习更多的机器学习.深度学习的知识! 磐石 介绍 数据科学研究者们最常遇见的问题之一就是怎样避免过拟合. ...
随机推荐
- drf面试题及总结
drf面试题及总结 1.什么是前后端分离 2.什么是restful规范 3.模拟浏览器进行发送请求的工具 4.查找模板的顺序 5.什么是drf组件 6.drf组件提供的功能 7.drf继承过哪些视图类 ...
- Istio 1.4 更新了 | 感觉学不完
Istio 1.4 更新了 官网 https://istio.io/news/2019/announcing-1.4/ Istio 评选 为GitHub上增长最快的五个 开源项目之一 变更说明获取更改 ...
- js 数组sort, 多条件排序。
Array.sort(); sort()方法可以传入一个函数作为参数,然后依据该函数的逻辑,进行数组的排序. 一般用法:(数组元素从小大进行排序) var a = [9, 6, 5, 7, 11, 5 ...
- LR编写grammar中的问题和解决方法
本文主要说明LR解析过程中关于BNF的典型冲突如何在LR中解决 冲突一般分为两种: shift/reduce错误 redure/redure错误 下面分别解释两种冲突 1. shift/reduce错 ...
- SAP替代,出口U904在RGGBS000中未生成
报错.提示出口U904在RGGBS000中未生成. 一般情况下需要到 程序RGGBS000 中,在form:get_exit_titles 中增加下列代码. exits-name = 'U904. e ...
- dotnet core 之 CORS使用示例
这里列举几个经过验证的可用的CORS使用示例, 方便在需要的时候可以直接使用 示例1 #region snippet2 public void ConfigureServices(IServiceCo ...
- flyway.setBaselineOnMigrate(true);
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayWrappe ...
- python --- Socketserver N部曲(1)
曲一 socketserver 是为了简化服务器端开发而产生的,是一个高级的标准库.(背景介绍完毕,开始干) 一些概念 来自源码的一张图片,简洁又FengSao +------------+ | Ba ...
- Socker编程之TCP
一:TCP介绍 TCP协议,传输控制协议(英语:Transmission Control Protocol,缩写为 TCP)是一种面向连接的.可靠的.基于字节流的传输层通信协议,由IETF的RFC 7 ...
- Linux下搭建keepalive+nginx
一. 安装nginx(略) 二. 安装keepalive 下载http://www.keepalived.org/download.html 安装依赖包 yum install –y popt* gc ...