Problem I: Ice Igloos

\[Time Limit: 10 s \quad Memory Limit: 512 MiB
\]

题意

给出\(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 (暴力技巧)的更多相关文章

  1. HDU 4509 湫湫系列故事——减肥记II(线段树-区间覆盖 或者 暴力技巧)

    http://acm.hdu.edu.cn/showproblem.php?pid=4509 题目大意: 中文意义,应该能懂. 解题思路: 因为题目给的时间是一天24小时,而且还有分钟.为了解题方便, ...

  2. Gym 101480I Ice Igloos(思维乱搞)题解

    题意:给个最多500 * 500的平面,有半径最多不为1的n个圆,现在给你1e5条线段,问你每条线段和几个圆相交,时限10s 思路: 因为半径<1,那么我其实搜索的范围只要在线段附近就好了.x1 ...

  3. Gym 101158D(暴力)

    题意:给定两个长度为N的字符串,1<=N<=4000,求满足字符串1中的某个区间所有的字母种类和个数都与字符串2中的某个区间相同最长的区间长度. 分析: 1.预处理每个串字母个数的前缀和. ...

  4. Codeforces Gym 100418B 暴力

    Sum of sequencesTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/v ...

  5. HDU 2588 GCD 【Euler + 暴力技巧】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=2588 GCD Time Limit: 2000/1000 MS (Java/Others)    Mem ...

  6. Consonant Fencity Gym - 101612C 暴力二进制枚举 Intelligence in Perpendicularia Gym - 101612I 思维

    题意1: 给你一个由小写字母构成的字符串s,你可以其中某些字符变成大写字母.如果s中有字母a,你如果想把a变成大写,那s字符串中的每一个a都要变成A 最后你需要要出来所有的字符对,s[i]和s[i-1 ...

  7. Gym - 101480 CERC 15:部分题目题解(队内第N次训练)

    -------------------题目难度较难,但挺有营养的.慢慢补. A .ASCII Addition pro:用一定的形式表示1到9,让你计算加法. sol:模拟. solved by fz ...

  8. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  9. 深度学习中正则化技术概述(附Python代码)

    欢迎大家关注我们的网站和系列教程:http://www.tensorflownews.com/,学习更多的机器学习.深度学习的知识! 磐石 介绍 数据科学研究者们最常遇见的问题之一就是怎样避免过拟合. ...

随机推荐

  1. Scala Type Parameters 2

    类型关系 Scala 支持在泛型类上使用型变注释,用来表示复杂类型.组合类型的子类型关系间的相关性 协变 +T,变化方向相同,通常用在生产 假设 A extends T, 对于 Clazz[+T],则 ...

  2. c/c++封装成python包

    参考网址:https://blog.csdn.net/tiankongtiankong01/article/details/80420033 SWIG (Simplified Wrapper and ...

  3. Matlab数据标准化——mapstd、mapminmax

    Matlab神经网络工具箱中提供了两个自带的数据标准化处理的函数——mapstd和mapminmax,本文试图解析一下这两个函数的用法. 一.mapstd mapstd对应我们数学建模中常使用的Z-S ...

  4. shell-快速入门_批处理脚本编程语言

    1. Shell概述 1.1. Shell是什么 Shell是一门批处理脚本编程语言. 批处理是什么? 操作系统都分为(GUI)图形界面,命令界面(command). 命令操作的可以不用一一条执行.可 ...

  5. AD常用术语

    SMD : Surface Mounted Devices 表面贴装器件 PAD 焊盘

  6. windows2008 开启SNMP服务

    现在很多企业和公司管理服务器时都是通过网络监控软件对服务器的状态进行监控,在监控的时候大多是通过SNMP协议(简单网络管理协议)进行的,那么在我们的服务器端就需要开启此项服务,并进行简单的设置. 以下 ...

  7. Bootstrap-treeView 实际操作总结

    由于功能性需求:需要展示一个树状结构的导航界面 1.进行资源引用 <!-- Required Stylesheets --> <link href="bootstrap.c ...

  8. .NET / C# HTTP中的GET和PSOT

    需要引入using System.IO;using System.Net; public string GETs(string URL) { //创建httpWebRequest对象 HttpWebR ...

  9. c#使用SoundPlayer播放wav格式音频

    1.引用System.Media名称空间下的类SoundPlayer   SoundPlayer player = new SoundPlayer(); 2.方法调用Play(); public vo ...

  10. VMwarm下安装ubuntu的一些问题

    1.终端无法输入中文的原因(未实践)  原文地址 2.Windows10下VMwarm(V15.5)和ubuntu14.04实现复制文件(已经实践)  转载路径