离散化+multiset —— HDU 4400
来源:互联网 发布:白鹤祥java架构师视频 编辑:程序博客网 时间:2024/06/10 04:44
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4400
题意:给出N个地雷的坐标和其爆炸范围,使用曼哈顿距离计算。给出M个查询,每个查询引爆第
i 个地雷,求这次引爆最终会导致多少个地雷爆炸,已经爆炸的地雷不会再次爆炸。分析:标程是KD-Tree,但是高效的STL使得我们可以直接暴力做。首先因为,坐标轴的范围很大,但是地雷个数较少,所以我们可以选择离散化所有地雷的X轴坐标,然后保存下每一个X值所对应的所有地雷,因为需要使得Y轴有序并且有重复地点的地雷且地雷数在动态改变,所以我们使用multiset保存这个值。然后就是使用STL暴力查询了
AC代码:
/************************************************************************* > File Name: test.cpp > Author: Akira > Mail: qaq.febr2.qaq@gmail.com ************************************************************************/#include <iostream>#include <sstream>#include <cstdio>#include <cstring>#include <string>#include <cstdlib>#include <algorithm>#include <bitset>#include <queue>#include <stack>#include <map>#include <cmath>#include <vector>#include <set>#include <list>#include <ctime>#include <climits>typedef long long LL;typedef unsigned long long ULL;typedef long double LD;#define MST(a,b) memset(a,b,sizeof(a))#define CLR(a) MST(a,0)#define Sqr(a) ((a)*(a))using namespace std;#define MaxN 100001#define MaxM MaxN*10#define INF 0x3f3f3f3f#define PI 3.1415926535897932384626const int mod = 1E9+7;const double eps = 1e-6;#define bug cout<<88888888<<endl;#define debug(x) cout << #x" = " << x << endl;int N,m;struct Node{ LL x, y, d;}node[MaxN];struct Yaxes{ LL y; int id; Yaxes(){} Yaxes(LL y, int id):y(y),id(id){} bool operator<(const Yaxes &a) const { return y<a.y; }};int vis[MaxN];vector<LL> DSZ_x;multiset<Yaxes> S[MaxN];multiset<Yaxes>::iterator it,L,R;void init(){ DSZ_x.clear(); for(int i=0;i<=N;i++) S[i].clear(); CLR(vis);}int ans;void solve(){ int num; while(m--) { ans = 0; scanf("%d", &num); num--; queue<int> Q; if(vis[num]) { puts("0"); continue; } while(!Q.empty()) Q.pop(); Q.push(num); vis[num] = 1; while(!Q.empty()) { ans++; int tmp = Q.front(); Q.pop(); int sx = lower_bound(DSZ_x.begin(), DSZ_x.end(), node[tmp].x-node[tmp].d)-DSZ_x.begin(); int sy = upper_bound(DSZ_x.begin(), DSZ_x.end(), node[tmp].x+node[tmp].d)-DSZ_x.begin(); for(int i=sx;i<sy; i++) { int rem = node[tmp].d - abs(DSZ_x[i]-node[tmp].x); L = S[i].lower_bound(Yaxes(node[tmp].y-rem, 0)); R = S[i].upper_bound(Yaxes(node[tmp].y+rem, 0)); for(it=L; it!=R; it++) { if(vis[it->id]) continue; Q.push(it->id); vis[it->id] = 1; } S[i].erase(L,R); } } printf("%d\n", ans); }}int main(){ //std::ios::sync_with_stdio(false); int t = 1; while(~scanf("%d", &N) && N) { init(); for(int i=0;i<N;i++) { scanf("%d%d%d", &node[i].x, &node[i].y, &node[i].d); DSZ_x.push_back(node[i].x); } sort(DSZ_x.begin(), DSZ_x.end()); DSZ_x.erase(unique(DSZ_x.begin(), DSZ_x.end()), DSZ_x.end()); for(int i=0;i<N;i++) { int loc = lower_bound(DSZ_x.begin(), DSZ_x.end(), node[i].x)-DSZ_x.begin(); S[loc].insert( Yaxes(node[i].y, i)); } scanf("%d", &m); printf("Case #%d:\n", t++); solve(); } //system("pause");}
0 0
- 离散化+multiset —— HDU 4400
- poj3277city,离散化+线段树 或 stl的multiset
- Splay树 + 离散化 —— HDU 3436 Queue-jumpers
- hdu 5009 离散化
- HDU 1556 离散化
- hdu 5481 离散化
- HDU - 3634 离散化
- 离散化—vector
- Multiset(中)——STL中的multiset
- Multiset(中)——STL中的multiset
- 【dp+离散化】hdu 4028
- hdu 5009 dp+离散化
- hdu 5124 lines(离散化)
- hdu 6012 (离散化)
- HDU 5925 离散化+dfs
- hdu 5925(离散化+BFS)
- HDU 5596 GTW likes gt(巧用multiset)——BestCoder Round #66(div.1 div.2)
- HDU 2275 multiset
- node.js的generic-pool与mysql结合,mysql连接池
- Anjular组件化
- POJ 2236 Wireless Network(并差集)
- linux脚本使用-------安装madplay及MPlayer播放器脚本分析及命令参数前加“横杠”的背景解释
- crypto加密
- 离散化+multiset —— HDU 4400
- Differential Privacy差分隐私
- Linux操作系统安装与环境配置
- matlab的rem()和mod()函数
- MySQL索引优化实例说明
- 图片预加载代码
- mysql 实验论证 innodb表级锁与行级锁
- HDU 1008 Elevator ACM基础题 关键是读懂题目就OK啦
- TCP/IP四层模型和OSI七层模型的概念