题意:给个最多500 * 500的平面,有半径最多不为1的n个圆,现在给你1e5条线段,问你每条线段和几个圆相交,时限10s

思路:

因为半径<1,那么我其实搜索的范围只要在线段附近就好了。x1 == x2 或者 y1 == y2这个很好理解,不解释。如果是斜率> 0的,那么对于任意的x (x1 <=  x < x2),那我的范围就是floor(yi)~ceil(yi+1),另一种斜率同理。然后我去数每一个格子有没有圆,能不能碰到我线段就行了。每个格子数完标记一下。可以偷个懒,标记为p,然后每次判是不是p,这样就省了每次都初始化。

题解虽然说最好规避sqrt,不过好像精度影响不大。

毒瘤的是输入,x1 > x2,y1 > y2。

代码:

#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include <iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 500 + 10;
const int M = maxn * 30;
const ull seed = 131;
const int INF = 0x3f3f3f3f;
const int MOD = 1000000007;
double r[maxn][maxn], k;
int vis[maxn][maxn];
double a, b;
double getY(double x){
return k * (x - a) + b;
}
bool check(double x, double y, double R){
double dis = fabs(k * x - k * a + b - y) / sqrt(k * k + 1);
if(dis <= R) return true;
return false;
}
int main(){
int n;
int x1, y1, x2, y2, ans;
memset(r, 0, sizeof(r));
memset(vis, 0, sizeof(vis));
scanf("%d", &n);
for(int i = 1; i <= n; i++){
int u, v;
double l;
scanf("%d%d%lf", &u, &v, &l);
r[u][v] = l;
}
scanf("%d", &n);
for(int p = 1; p <= n; p++){
int up, down;
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
a = x1, b = y1;
ans = 0;
k = ((double)(y2 - y1)) / ((double)(x2 - x1));
if(x1 == x2){
if(y1 > y2) swap(y1, y2);
for(int i = y1; i <= y2; i++)
if(r[x1][i] != 0) ans++;
}
else if(y1 == y2){
if(x1 > x2) swap(x1, x2);
for(int i = x1; i <= x2; i++)
if(r[i][y1] != 0) ans++;
}
else{
if(x1 > x2){
swap(x1, x2);
swap(y1, y2);
}
if(k > 0){
for(int i = x1; i < x2; i++){
up = (int)ceil(getY(i + 1));
down = (int)floor(getY(i));
if(i == x1) down = y1;
if(i == x2 - 1) up = y2;
for(int j = down; j <= up; j++){
if(r[i][j] > 0 && vis[i][j] != p && check(i, j, r[i][j])){
vis[i][j] = p;
ans++;
}
if(r[i + 1][j] > 0 && vis[i + 1][j] != p && check(i + 1, j, r[i + 1][j])){
vis[i + 1][j] = p;
ans++;
}
} }
}
else{
for(int i = x1; i < x2; i++){
up = (int)ceil(getY(i));
down = (int)floor(getY(i + 1));
if(i == x1) up = y1;
if(i == x2 - 1) down = y2;
for(int j = down; j <= up; j++){
if(r[i][j] > 0 && vis[i][j] != p && check(i, j, r[i][j])){
vis[i][j] = p;
ans++;
}
if(r[i + 1][j] > 0 && vis[i + 1][j] != p && check(i + 1, j, r[i + 1][j])){
vis[i + 1][j] = p;
ans++;
}
} }
}
}
printf("%d\n", ans);
}
return 0;
}

Gym 101480I Ice Igloos(思维乱搞)题解的更多相关文章

  1. 2017 ACM-ICPC EC-Final ShangHai(思维乱搞赛)

    感觉全是思维乱搞题. Gym - 101775J Straight Master 给你n种扑克,你每次可以出连续的3 ~ 5 张,问你能否出完. Sample Input 2 13 1 2 2 1 0 ...

  2. Codeforces Gym 100203G Good elements 暴力乱搞

    原题链接:http://codeforces.com/gym/100203/attachments/download/1702/statements.pdf 题解 考虑暴力的复杂度是O(n^3),所以 ...

  3. CodeForces - 1228D (暴力+思维+乱搞)

    题意 https://vjudge.net/problem/CodeForces-1228D 有一个n个顶点m条边的无向图,在一对顶点中最多有一条边. 设v1,v2是两个不相交的非空子集,当满足以下条 ...

  4. Aizu - 1386 Starting a Scenic Railroad Service (思维乱搞)

    给你n个区间,求: 1:最多有多少区间与同一个区间相交. 2:相交部分的最大区间数目. Sample Input 1 4 1 3 1 3 3 6 3 6 Sample Output 1 2 2 Sam ...

  5. Gym 101128A Promotions(思维 + dfs)题解

    题意:给一有向图,如果A指向B,则A是B的上级.一直i要升职那么他的上级必须都升职.现在给你一个升职人数的区间[a, b],问你升职a人时几个人必被升职,b时几个人必升职,b时几个人没有可能被升职. ...

  6. Ice Igloos Gym - 101480I (暴力技巧)

    Problem I: Ice Igloos \[ Time Limit: 10 s \quad Memory Limit: 512 MiB \] 题意 给出\(n\)个圆,给出每个圆的坐标\(x\). ...

  7. “盛大游戏杯”第15届上海大学程序设计联赛夏季赛暨上海高校金马五校赛题解&&源码【A,水,B,水,C,水,D,快速幂,E,优先队列,F,暴力,G,贪心+排序,H,STL乱搞,I,尼姆博弈,J,差分dp,K,二分+排序,L,矩阵快速幂,M,线段树区间更新+Lazy思想,N,超级快速幂+扩展欧里几德,O,BFS】

    黑白图像直方图 发布时间: 2017年7月9日 18:30   最后更新: 2017年7月10日 21:08   时间限制: 1000ms   内存限制: 128M 描述 在一个矩形的灰度图像上,每个 ...

  8. UESTC 1272 Final Pan's prime numbers(乱搞)

    题目链接 Description Final Pan likes prime numbers very much. One day, he want to find the super prime n ...

  9. [bzoj1067][SCOI2007]降雨量——线段树+乱搞

    题目大意 传送门 题解 我国古代有一句俗话. 骗分出奇迹,乱搞最神奇! 这句话在这道题上得到了鲜明的体现. 我的方法就是魔改版线段树,乱搞搞一下,首先借鉴了黄学长的建树方法,直接用一个节点维护年份的区 ...

随机推荐

  1. Mac中安装Git

    Mac 安装git 打开Mac终端输入git命令 如果出现以下代码说明已经安装 usage: git [--version] [--help] [-C <path>] [-c <na ...

  2. uni-app开发经验分享十一: uniapp iOS云打包修改权限提示语

    打包提交appstore如果用到了如下权限需要修改提示语,详细描述使用这个权限的原因,如不修改提示语appstore审核可能会被拒绝.Apple的原则是,如果一个app想要申请用户同意某个隐私信息访问 ...

  3. list中map 的value值时间排序

    public static void main(String[] args) { String sys=DateUtil.getTime().substring(0,5); System.out.pr ...

  4. IDEA、Pycharm学生免费使用(无教育邮箱)

    一.打开JetBrains学生产品网站 JetBrains Products for Learning:https://www.jetbrains.com/shop/eform/students 二. ...

  5. LOJ10013曲线

    题目描述 明明做作业的时候遇到了n  个二次函数s_i(x)=ax^2+bx+c ,他突发奇想设计了一个新的函数 f(x)=max{s_i(x)},i=1,2,...,n. 明明现在想求这个函数在 [ ...

  6. Language Guide (proto3) | proto3 语言指南(二)标量值类型

    标量值类型 标量消息字段可以具有以下类型之一 -- 下表显示了.proto文件中指定的类型,以及自动生成的类中相应的类型: .proto Type 说明 C++ Type Java Type Pyth ...

  7. 基于navicat的数据库导入导出

    1.右键当前数据库,选择转储SQL文件 选择导出sql的存放路径 2.新建统一命名的数据库,右键运行SQL文件 3,.选择要导入的SQL文件后如图

  8. vue3.0初尝试

  9. OSPF优化

    1.点对点(背靠背)的优化 两台设备直连(逻辑上的直连). 将OSPF宣告接口配置为点对点模式,不用选举DR.减少20S时间 interface Ethernet0/1 ip ospf network ...

  10. SSL与HTTPS协议

    1.SSL 1.1 什么是SSL SSL(Secure Sockets Layer 安全套接层),及其继任者传输层安全(Transport Layer Security,TLS)是为网络通信提供安全及 ...