题意: 

      煤矿爆炸,每个煤矿有自己的x,y,d,d是他爆炸后会是d距离内的爆炸,每次输入一个爆炸的煤矿,问你这个煤矿爆炸会有多少个煤矿爆炸.

思路:

      爆炸的过程就是搜索的过程,被当前煤矿弄爆炸的煤矿可能继续去吧别的煤矿蹦爆炸,所以是搜索的过程,但直接搜会超时,所以各种STL,估计是数据水,不然我人感觉STL碰到坑人数据也得N^2,一样跪,思路是按照x离散化,1 2 3 3 4 离散化成1 2 3 4,然后每个点建立一个multiset,然后把y 和 id塞进去,按照y排序,像上面的那组,1 2 4的set里就一组数据,而3里面有两组,每次询问的时候,先找到x的范围,
x - d ,x + d,可以二分或者直接STL,然后再在找到的范围里找出满足条件的y,直接STL,这个地方二分会有点复杂,但如果想二分绝对可以,然后就这样广搜就行了....


#include<stdio.h>
#include<string.h>
#include<queue>
#include<set>
#include<algorithm> #define N 100000 + 100

using namespace
std; typedef struct NODE
{
int
y ,id;
NODE(int id_ ,int y_)
{

y = y_;
id = id_;
}
bool operator < (const
NODE &c) const
{
return
y < c.y;
}
}
NODE; typedef struct
{
int
x ,y ,d;
}
NOD; int abss(int a)
{
return
a < 0 ? -a : a;
}
NOD node[N];
int
X_hash[N] ,hash_n;
int
mark[N];
multiset<NODE>SET[N]; int BFS(int s)
{
int
ans = 0;
if(
mark[s]) return ans; mark[s] = 1;
queue<int>q;
q.push(s);
multiset<NODE>::iterator yl,yr,it;
while(!
q.empty())
{

ans ++;
int
tou ,xin;
tou = q.front();
q.pop();
int
xl = lower_bound(X_hash ,X_hash + hash_n ,node[tou].x - node[tou].d) - X_hash;
int
xr = upper_bound(X_hash ,X_hash + hash_n ,node[tou].x + node[tou].d) - X_hash;
for(int
i = xl ;i < xr ;i ++)
{
int
yy = node[tou].d - abss(node[tou].x - X_hash[i]);
yl = SET[i].lower_bound(NODE(0 ,node[tou].y - yy));
yr = SET[i].upper_bound(NODE(0 ,node[tou].y + yy));
for(
it = yl ;it != yr ;it++)
{
if(!
mark[it->id])
{

mark[it->id] = 1;
//ans ++;
q.push(it->id);
}
}

SET[i].erase(yl ,yr);
}
}
return
ans;
} int main ()
{
int
i ,j ,n ,m ,cas = 1;
while(~
scanf("%d" ,&n) && n)
{
for(
i = 0 ;i < n ;i ++)
{

scanf("%d %d %d" ,&node[i].x ,&node[i].y ,&node[i].d);
X_hash[i] = node[i].x;
}

sort(X_hash ,X_hash + n);
hash_n = unique(X_hash,X_hash + n) - X_hash;
for(
i = 0 ;i < hash_n ;i ++)
SET[i].clear();
for(
i = 0 ;i < n ;i ++)
{
int
id = lower_bound(X_hash ,X_hash + hash_n ,node[i].x) - X_hash;
//int xl = lower_bound(X_hash + 1 ,X_hash + hash_n + 1 ,node[tou].x - node[tou].d) - X_hash;
SET[id].insert(NODE(i ,node[i].y));
}

scanf("%d" ,&m);
printf("Case #%d:\n",cas ++);
memset(mark ,0 ,sizeof(mark));
for(
i = 1 ;i <= m ;i ++)
{
int
id;
scanf("%d" ,&id);
printf("%d\n" ,BFS(id-1));
}
}
return
0;
}

hdu4400 BFS+STL的更多相关文章

  1. 八数码问题(一) 暴力BFS + STL

    八数码问题是一个经典的人工智能问题.具体问题不累述了. 思路:由于存在多组测试数据,可以考虑“打表法“.所谓打表法,即枚举所有的初始情况,记录其到达终点的路径.而在这个题目中,顺序打表会调用很多次BF ...

  2. luogu题解P1032字串变换--BFS+STL:string骚操作

    题目链接 https://www.luogu.org/problemnew/show/P1032 分析 这题本来很裸的一个BFS,发现其中的字符串操作好烦啊.然后就翻大佬题解发现用STL中的strin ...

  3. POJ 1915 Knight Moves(BFS+STL)

     Knight Moves Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 20913   Accepted: 9702 ...

  4. Gym 100952F&&2015 HIAST Collegiate Programming Contest F. Contestants Ranking【BFS+STL乱搞(map+vector)+优先队列】

    F. Contestants Ranking time limit per test:1 second memory limit per test:24 megabytes input:standar ...

  5. TC-SRM391-div2-SortingGame(BFS,STL)

    Problem Statement for SortingGame Problem Statement In The Sorting Game, you are given a sequence co ...

  6. POJ 1915-Knight Moves (单向BFS &amp;&amp; 双向BFS 比)

    主题链接:Knight Moves 题意:8个方向的 马跳式走法 ,已知起点 和终点,求最短路 研究了一下双向BFS,不是非常难,和普通的BFS一样.双向BFS只是是从 起点和终点同一时候開始搜索,可 ...

  7. [C++]那些年被虐的STL

    首先很感谢**P1135奇怪的电梯 **[2.14补充:此题已被AC!然后将被我花式虐[From语]哈哈哈哈哈哈哈哈哈哈好嗨哟感觉人生已经到达了巅峰感觉人生已经到达了高潮]这道题了!在做这道题的我大致 ...

  8. LeetCode_算法及数据结构覆盖统计

    [输入]共计151道题的算法&数据结构基础数据 (见附录A) [输出-算法]其中有算法记录的共计 97道 ,统计后 结果如下  top3(递归,动态规划,回溯) 递归 动态规划 回溯 BFS ...

  9. 拼图游戏(8 puzzle)

    如图所示,这是一个九宫格(这倒是让我想起了小时候老师在黑板上教导我们的如何通过一系列的拼凑,将横行,竖行,以及斜行都拼到和相等),格子中有一个格子是空的,另外八个格子分别有数字1--8,我们的任务是将 ...

随机推荐

  1. JPEG解码——(5)反量化和逆ZigZag变换

    本篇是该系列的第五篇,承接上篇huffman解码,介绍接下来的两个步骤--反量化和逆zigzag变换,即IDCT前的两个步骤. 需要说明的是,这两个步骤可以颠倒,本人的实现是,先反量化,再逆ZigZa ...

  2. #progma pack(x)说明

    1.字节对齐(内存相关) 现代计算机中内存空间都是按照byte划分的,从理论上讲似乎对任何类型的变量的访问可以从任何地址开始,但实际情况是在访问特定变量的时候经常在特定的内存地址访问,这就需要各类型数 ...

  3. 报错问题: AtrributeError:module ‘allure’ has no attribute ‘’severity_level’

    问题:执行命令报错:pytest -s -q --alluredir report 报错问题: AtrributeError:module 'allure' has no attribute ''se ...

  4. JDBC 连接池 & Template

    数据库连接池 # 概念:其实就是一个容器(集合),存放数据库连接的容器. * 当系统初始化号以后,容器被创建,容器中会申请一些连接对象,当用户来访问数据库时,从容其中获取连接对象,用户访问完之后,会将 ...

  5. 大数据实战-Hive-技巧实战

    1.union 和 union all 前者可以去重 select sex,address from test where dt='20210218' union all select sex,add ...

  6. [unknown source] 整数拆分

    一.题目 题目描述 定义一个整数拆分序列 \(a\) 的权值为: \[\sum_{i=1}^n\sum_{j=1}^{i-1}\gcd(a_i,a_j) \] 求对于一个整数 \(n\) 所有整数拆分 ...

  7. Codeforces 976C Nested Segments

    题面: 传送门 C. Nested Segments Input file: standard input Output file: standard output Time limit: 2 secon ...

  8. (2)MySQL进阶篇SQL优化(show status、explain分析)

    1.概述 在应用系统开发过程中,由于初期数据量小,开发人员写SQL语句时更重视功能上的实现,但是当应用系统正式上线后,随着生产数据量的急剧增长,很多SQL语句开始逐渐显露出性能问题,对生产环境的影响也 ...

  9. 仿String()构造器函数 【总结】

    需求 实现以下方法: 控制台结果: 需求分析: 首先确定new调用的this和什么对象绑定,如果跟默认返回的对象绑定肯定做不到 [ ] 这样的访问,所以要在构造器内部返回一个包装过的数组 1.leng ...

  10. c++ 反汇编 循环结构

    debug do···while 23: int nSum = 0; 00A572AE C7 45 F8 00 00 00 00 mov dword ptr [nSum],0 24: int nInd ...