Bombing HDU, 4022(QQ糖的消法)

Bombing

From:HDU, 4022

Submit

Time Limit: 4000/2000 MS (Java/Others)      Memory Limit: 65768/65768 K (Java/Others)



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 encountered a much more difficult instance: recounting exploits of the military. In the bombing action, the commander will dispatch a group of bombers with weapons having
the huge destructive power to destroy all the targets in a line. Thanks to the outstanding work of our spy, the positions of all opponents’ bases had been detected and marked on the map, consequently, the bombing plan will be sent to you.

Specifically, the map is expressed as a 2D-plane with some positions of enemy’s bases marked on. The bombers are dispatched orderly and each of them will bomb a vertical or horizontal line on the map. Then your commanded wants you to report that how many bases
will be destroyed by each bomber. Notice that a ruined base will not be taken into account when calculating the exploits of later bombers.

Input

Multiple test cases and each test cases starts with two non-negative integer N (N<=100,000) and M (M<=100,000) denoting the number of target bases and the number of scheduled bombers respectively. In
the following N line, there is a pair of integers x and y separated by single space indicating the coordinate of position of each opponent’s base. The following M lines describe the bombers, each of them contains two integers c and d where c is 0 or 1 and
d is an integer with absolute value no more than 109, if c = 0, then this bomber will bomb the line x = d, otherwise y = d. The input will end when N = M = 0 and the number of test cases is no more than 50.

Output

For each test case, output M lines, the ith line contains a single integer denoting the number of bases that were destroyed by the corresponding bomber in the input. Output a blank line after each test
case.

Sample Input

3 2
1 2
1 3
2 3
0 1
1 3
0 0

Sample Output

2
1

题目大意:

给你n个敌人的坐标,再给你m个炸弹和爆炸方向,每个炸弹可以炸横排或竖排的敌人,问你每个炸弹能炸死多少个人。

解题思路:

用map里面嵌套multiset , 1000多ms,还是有点长的,老师说要用list ,不知是否要快点。

代码:

#include<iostream>
#include<set>
#include<map>
#include<cstdio>
#define maxN = 10010;
using namespace std;

typedef map<int,multiset<int> > def;
multiset<int>::iterator it;
int n,m;
def hang,lie;

void pop(def &a,def &b,int c){
    printf("%d\n",a[c].size());
    for(it=a[c].begin();it!=a[c].end();it++)
        b[*it].erase(c);//直接释放那个值的位置
    a[c].clear();

}

void input(){
    int x,y;
    for(int i=0;i<n;i++){
        scanf("%d%d",&x,&y);
        lie[x].insert(y);
        hang[y].insert(x);
    }
}

void solve(){
    int a,b;
     for(int i=0;i<m;i++){
        scanf("%d%d",&a,&b);
        if(a==0) pop(lie,hang,b);
        else pop(hang,lie,b);
    }
    printf("\n");
}

int main(){
    while(~scanf("%d%d",&n,&m)&&(n||m)){
        input();
        solve();
    }
    return 0;
}
时间: 2025-01-18 05:13:28

Bombing HDU, 4022(QQ糖的消法)的相关文章

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 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<

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 STL

题意:给你n个敌人的坐标,再给你m个炸弹和爆炸方向,每个炸弹可以炸横排或竖排的敌人,问你每个炸弹能炸死多少个人. 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 #include<algorithm> 14 using namespace std; 15

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

HDU 4022 stl multiset

orz kss太腻害了. 一.set和multiset基础 set和multiset会根据特定的排序准则,自动将元素进行排序.不同的是后者允许元素重复而前者不允许. 需要包含头文件: #include <set> set和multiset都是定义在std空间里的类模板: 二.set和multiset的功能 和所有关联式容器类似,通常使用平衡二叉树完成.事实上,set和multiset通常以红黑树实作而成. 自动排序的优点是使得搜寻元素时具有良好的性能,具有对数时间复杂度.但是造成的一个缺点就是

且听风吟——三小张

缺炼 “缺炼!”这不是我说的,这是兵哥说我的. 搬上来之前,我们8个人做过一次反省,张翀挨着我,快到我反省时,我问张翀,你看我这耳朵红呗?张翀说,红,你热昂?我说,没事,没事.张翀就拉上了窗帘. 到我反省了,我说,刚才我问张翀,你看我耳朵红不,张翀说红,并且很体贴的拉上了窗帘.其实我是内热,为什么?两点,一是心跳加速,血热:二是骨骼肌颤栗,产热. 到我说的时候我就很紧张,好像又不单纯是虚荣心作怪,这就有了兵哥说的“缺炼”. 确实是缺炼. 创造更大的价值 好,书接前文,上次说到卖豆角这个业务分三层