HDU 4022 Bombing STL 模拟题

手动模拟。。

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
#include<map>
using namespace std;
#define N 10100
#define inf 1000000010
map<int,int>x,y;
struct X{
	int x,y;
	bool operator<(const X&a)const{
		if(a.x==x)return a.y>y;
		return a.x>x;
	}
	X(int a=0,int b=0):x(a),y(b){}
}tmpx;
struct Y{
	int x,y;
	bool operator<(const Y&a)const{
		if(a.y==y)return a.x>x;
		return a.y>y;
	}
	Y(int a=0,int b=0):x(a),y(b){}
}tmpy;
multiset<Y>sety;
multiset<Y>::iterator py, ty;
multiset<X>setx;
multiset<X>::iterator px, tx;
int main(){
	int n, m, u, v;
	while(scanf("%d %d",&n,&m),n+m){
		x.clear();
		y.clear();
		setx.clear();
		sety.clear();
		while(n--){
			scanf("%d %d",&u,&v);
			x[u]++;
			y[v]++;
			setx.insert(X(u,v));
			sety.insert(Y(u,v));
		}
		while(m--){
			scanf("%d %d",&u,&v);
			if(u==0){
				if(x.find(v)==x.end()){puts("0");continue;}
				printf("%d\n",x.find(v)->second);
				x.erase(v);
				for(px=setx.lower_bound(X(v,-inf));px!=setx.end();)
				{
					tmpx = *px;
					if(tmpx.x!=v)break;
					py = sety.lower_bound(Y(tmpx.x,tmpx.y));	sety.erase(py);
					y[tmpx.y]--;
					tx = px;
					px++;
					setx.erase(tx);
				}
			}
			else {
				if(y.find(v)==y.end()){puts("0");continue;}
				printf("%d\n",y.find(v)->second);
				y.erase(v);
				for(py=sety.lower_bound(Y(-inf,v));py!=sety.end();)
				{
					tmpy = *py;
					if(tmpy.y!=v)break;
					px = setx.lower_bound(X(tmpy.x,tmpy.y));
					setx.erase(px);
					x[tmpy.x]--;
					ty = py;
					py++;
					sety.erase(ty);
				}
			}
		}
		puts("");
	}
	return 0;
}

HDU 4022 Bombing STL 模拟题

时间: 2024-10-09 20:27:29

HDU 4022 Bombing STL 模拟题的相关文章

HDU 4028 The time of a day STL 模拟题

暴力出奇迹.. #include<stdio.h> #include<iostream> #include<algorithm> #include<vector> #include<cmath> #include<queue> #include<set> #include<map> using namespace std; #define ll __int64 #define N 42 ll n,m,ans;

HDU 4022 Bombing(stl,map,multiset,iterater遍历)

题目 参考了     1     2 #define _CRT_SECURE_NO_WARNINGS //用的是STL中的map 和 multiset 来做的,代码写起来比较简洁,也比较好容易理解. //multiset可以允许重复 //multiset<int>::iterator it; 用来遍历 #include<stdio.h> #include<string.h> #include<algorithm> #include<iostream&g

HDU 4022 Bombing(基本算法-水题)

Bombing Problem Description It's a cruel war which killed millions of people and ruined series of cities. In order to stop it, let's bomb the opponent's base. It seems not to be a hard work in circumstances of street battles, however, you'll be encou

hdu 4022 Bombing (离散化)

Bombing Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)Total Submission(s): 3176    Accepted Submission(s): 1195 Problem Description It’s a cruel war which killed millions of people and ruined series of cities. In

hdu 4022 Bombing

Bombing Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)Total Submission(s): 2650    Accepted Submission(s): 990 Problem Description It’s a cruel war which killed millions of people and ruined series of cities. In o

Bombing HDU - 4022

Bombing HDU - 4022 题意:给出n个目标,m个炸弹,每个炸弹可以炸一行或者一列,问每一个炸弹摧毁了多少目标. 可以用STL做,也可以二分做. 这是kuangbin的代码~ 用STL很简洁,但是慢 1 /* 2 HDU 4022 3 G++ 1296ms 4 5 6 */ 7 8 9 #include<stdio.h> 10 #include<iostream> 11 #include<set> 12 #include<map> 13 #inc

hdu 5641 King&#39;s Phone(暴力模拟题)

Problem Description In a military parade, the King sees lots of new things, including an Andriod Phone. He becomes interested in the pattern lock screen. The pattern interface is a 3×3 square lattice, the three points in the first line are labeled as

HDU 4930 Fighting the Landlords(扯淡模拟题)

Fighting the Landlords 大意: 斗地主....   分别给出两把手牌,肯定都合法.每张牌大小顺序是Y (i.e. colored Joker) > X (i.e. Black & White Joker) > 2 > A (Ace) > K (King) > Q (Queen) > J (Jack) > T (10) > 9 > 8 > 7 > 6 > 5 > 4 > 3. 给你8种组合:1.

HDU 4925 Apple Tree(模拟题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4925 解题报告:给你n*m的土地,现在对每一块土地有两种操作,最多只能在每块土地上进行两种操作,第一种是种苹果树操作,第二种是施肥操作,种苹果树操作可以使得该块地 长出一个苹果,施肥操作可以使得与这块土地相邻的土地的苹果产量变为原来的两倍,问可以得到的最多的苹果数量是多少? 例如一个4*4的土地,用1表示在该土地上做第一种操作,0表示在该土地上做第二种操作,可以得到最多苹果的操作如下: 0 1 0