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. linux 软件多版本共存

    update-alternatives 命令用于处理 Linux 系统中软件版本的切换,使其多版本共存.alternatives 的管理目录 /etc/alternatives . alternati ...

  2. 移相器——K波段有源移相器设计

    博主之前在做一款K波段有源移相器,所用工艺为smic55nmll工艺,完成了几个主要模块的仿真,现对之前的工作做个总结. K波段的频率范围是18G——27GHz,所设计移相器的工作频率范围是19G—— ...

  3. Field "details" doesn't have a default value

    [转载:原文链接http://my.oschina.net/wojibuzhu/blog/511104] MySQL 1364 错误提示:#1364 - Field "details&quo ...

  4. tomcat宕机自动重启脚本

    #!/bin/bash# 获取tomcat进程ID /usr/share/tomcatTomcatID=$(ps -ef |grep tomcat |grep -w 'tomcat'|grep -v ...

  5. Oracle排序(中文)

    一.中文排序      1. 按照笔划排序       select * from dept order by nlssort(name,'NLS_SORT=SCHINESE_STROKE_M'); ...

  6. TServerSocket组件

    主要作为服务器端的套接字管理器使用.它封装了服务器端的套接字.在打开套接字后,服务器端就处于监听状态,在接收到其它机器的连接请求后,与客户端建立连接,创建一个新的套接字,用于和客户端互传数据,此时TS ...

  7. ASP.NET 异步编程之Async await

    本文重点介绍的是.NET Framework4.5 推出的异步编程方案  async await 请先看个5分钟的微软演示的视频:视频地址: https://channel9.msdn.com/Blo ...

  8. Python基础7

    深复制 & 浅复制 列表,字符串 都有深浅复制,用 id() 函数来看 所谓“旧瓶装新酒,新瓶装旧酒”

  9. kvm第一章--概念

  10. 【转载】C#如何获取DataTable中某列的数据类型

    在C#的数据表格DataTable的操作中,有时候因为业务需要,我们需要获取到DataTable所有列或者某一列的数据类型,此时我们可以通过DataTable中的Columns属性对象的DataTyp ...