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. Python 监控脚本

    Python 监控脚本 整体通过psutil模块动态获取资源信息.下为示例图: #!/usr/bin/env python # -*- coding: utf-8 -*- # @Time: 2019- ...

  3. vip视频会员共享电影免费看

    vip会员在线看是一款可以观看持有会员特权的视频才能看的网站程序,小而强大,目前支持所有视频网站解析! 解析需要时间耐心等待20秒,如果加载失败,请切换接口耐心等待20秒! 找要要看的vip电影地址, ...

  4. 【题解】最大 M 子段和 Max Sum Plus Plus [Hdu1024] [51nod1052]

    [题解]最大 M 子段和 Max Sum Plus Plus [Hdu1024] [51nod1052] 传送门:最大 \(M\) 子段和 \(Max\) \(Sum\) \(Plus\) \(Plu ...

  5. java中System.err.print和System.out.print区别

    System.err.print    是报错专用输输出,有颜色标记,所有err打印的都在顶行输出 System.out.print   是标准输出,白底黑字 package iobuffer; pu ...

  6. MySQL远程连接ERROR 2003 (HY000):Can't connect to MySQL server on'XXXXX'(111) 的问题

    装了个navicat ,然后去连接mysql服务器,一直连不上,一开始以为是防火墙问题,后来防火墙都关闭, iptable服务关闭,还是不行,网上查了下:主要是因为设置了bind_address=12 ...

  7. 给定一个长度为N的数组,找出出现次数大于n/2,n/3的数,要求时间复杂度O(n),空间复杂度O(1)

    先讨论出现次数大于n/2的数字,如果这样的数字存在,那么这个数出现的次数大于其他数出现的次数的总和. 在数组A中,我们定义两个数据集合a1,a2.a1为出现次数大于n/2的数的集合,a2为其余数组成的 ...

  8. 我的第一个netcore2.2 api项目搭建(一)

    早早就想入门netcore,一直没下定决心,这次正好碰上项目服务变更,便想着入坑试试,边学边用. 目标: 一.api使用core版的SqlSugar,集成orm,实现快速开发 二.api使用Swagg ...

  9. winform+CefSharp 实现和js交互

    1:窗体加载的时候添加 webBrowser.RegisterJsObject("getuserName", new _Event()); 2:注册C#方法为js方法 /// // ...

  10. 【开发笔记】- 修改tomcat默认的编码方式

    tomcat8以后默认编码格式是utf-8:7之前的都是iso8859-1 如果默认情况下,tomcat使用的的编码方式:iso8859-1 修改tomcat下的conf/server.xml文件 找 ...