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

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

  1. hdu 4022 STL

    题意:给你n个敌人的坐标,再给你m个炸弹和爆炸方向,每个炸弹可以炸横排或竖排的敌人,问你每个炸弹能炸死多少个人. /* HDU 4022 G++ 1296ms */ #include<stdio ...

  2. hdu 4022 Bombing

    Bombing Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)Total Sub ...

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

    题目 参考了     1     2 #define _CRT_SECURE_NO_WARNINGS //用的是STL中的map 和 multiset 来做的,代码写起来比较简洁,也比较好容易理解. ...

  4. HDU 4022 Bombing (map + multiset)

    题意: 在x,y坐标范围为10 ^ -9 ~~ 10 ^ 9的坐标轴之中,有 10W个点(注意有些点可能在同一坐标上),然后有10W个询问,处理询问按照输入顺序处理,对于每个询问a,b    a == ...

  5. HDU 4022 Bombing STL 模拟题

    人工模拟.. #include<stdio.h> #include<iostream> #include<algorithm> #include<vector ...

  6. hdu 4022 Bombing(map,multiset)

    题意:n个基地放在2维平面,然后m个炸弹人,每个炸弹人可以炸一行或者一列,输出每个炸弹人炸掉的基地个数. 思路:用map<int,multiset<int> >对应起来一行或者 ...

  7. HDU 4022 stl multiset

    orz kss太腻害了. 一.set和multiset基础 set和multiset会根据特定的排序准则,自动将元素进行排序.不同的是后者允许元素重复而前者不允许. 需要包含头文件: #include ...

  8. ListView获取网络数据并展示优化练习

    权限: <uses-permission android:name="android.permission.INTERNET"></uses-permission ...

  9. asp.net Mvc 使用NPOI导出Excel文件

    1.新建MVC项目,新建控制器.视图 添加控制器: 添加视图(将使用布局页前面的复选框里的勾勾去掉) 2.在Models里新建一个类 public class Shop { /// <summa ...

随机推荐

  1. poj3984(经典dfs)

    题目链接:http://poj.org/problem?id=3984 分析:直接深搜从起点到终点,如何取最短路线,其实只要优先向下或向右走即可. #include <cstdio> #i ...

  2. BGP的状态机制

    Idle 状态:即空闲状态,不接受任何BGP的连接,等待Start事件的产生,如果有start事件产生,若有start事件产生,系统开启ConnectRetry定时器,向邻居发起TCP连接,并将状态变 ...

  3. AOP 之 6.1 AOP基础 ——跟我学spring3(转)

    http://jinnianshilongnian.iteye.com/blog/1418596

  4. H.O.T candy

    candy是什么意思_candy在线翻译_英语_读音_用法_例句_海词词典 candy

  5. HDU 4454 - Stealing a Cake(三分)

    我比较快速的想到了三分,但是我是从0到2*pi区间进行三分,并且漏了一种点到边距离的情况,一直WA了好几次 后来画了下图才发现,0到2*pi区间内是有两个极值的,每个半圆存在一个极值 以下是代码 #i ...

  6. Android四个多线程分析:MessageQueue实现

    Android四个多线程分析:MessageQueue的实现 罗朝辉 (http://blog.csdn.net/kesalin) CC 许可,转载请注明出处 在前面两篇文章<Android多线 ...

  7. A First Exploration Of SolrCloud

    A First Exploration Of SolrCloud Update: this article was published in August 2012, before the very ...

  8. Android画图监听接口OnPreDrawListener具体解释

    public static interface ViewTreeObserver.OnPreDrawListener 我们先看下API中的定义: 类概述: 为即将绘制视图树时运行的回调函数定义的接口. ...

  9. MFC控件(15):Tooltip

    在各种软件产品中我们经常碰到把鼠标放到一个控件上时会弹出关于该控件的一些提示信息.这就是tooltip. 在MFC中使用该功能可以使用类CToolTipCtrl.假如要让鼠标放到按钮IDC_BTN上时 ...

  10. JDBC连接数据库和释放连接

    用久了hibernate现在对于JDBC是怎么实现数据库的连接和释放,所以特地总结下关于JDBC的知识,目的是用于提醒自己很多Java的基础知识需要健全. package com.ssh.action ...