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 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
 
Source
 
----------------
暑假第二场组队赛,有点惨败。。这是dengyaolong师兄AC代码,贴过来学习一下......  = =有时候暴力真的出奇迹.....
 #include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include <algorithm>
using namespace std; int main(){
int N,M,i,j,x,y;
while(scanf("%d%d",&N,&M)&&(N||M)){
map<int,multiset<int> > row;
map<int,multiset<int> > col;
for(i=;i<N;i++){
scanf("%d%d",&x,&y);
row[x].insert(y);
col[y].insert(x);
}
for(i=;i<M;i++){
scanf("%d%d",&x,&y);
int ans=;
if(x==){
printf("%d\n",row[y].size());
for(multiset<int>::iterator itr=row[y].begin();itr!=row[y].end();itr++){
col[*itr].erase(y);
}
row[y].clear();
}else{
printf("%d\n",col[y].size());
for(multiset<int>::iterator itr=col[y].begin();itr!=col[y].end();itr++){
row[*itr].erase(y);
}
col[y].clear(); } }
puts(""); } return ;
}

hdu 4022 Bombing的更多相关文章

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

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

  2. HDU 4022 Bombing (map + multiset)

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

  3. HDU 4022 Bombing STL 模拟题

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

  4. hdu 4022 Bombing(map,multiset)

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

  5. Bombing HDU, 4022(QQ糖的消法)

    Bombing From:HDU, 4022 Submit Time Limit: 4000/2000 MS (Java/Others)      Memory Limit: 65768/65768 ...

  6. hdu 4022 STL

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

  7. hdu 5290 Bombing plan

    http://acm.hdu.edu.cn/showproblem.php?pid=5290 题意: 一棵树,每个点有一个权值wi,选择点i即可破坏所有距离点i<=wi的点,问破坏所有点 最少需 ...

  8. HDU 4022 stl multiset

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

  9. 2015 Multi-University Training Contest 1 hdu 5290 Bombing plan

    Bombing plan Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)To ...

随机推荐

  1. Python第1天

    今天主要学习内容如下: 概论,各种开发语言的对比,高级语言包括:python(开发效率高,执行效率低) Java(开发效率低,执行效率高),PHP,低级语言包括:C语言,汇编语言: Python 语言 ...

  2. IOS 发布 升级新版本

    ERROR ITMS-90725: "SDK Version Issue. ERROR ITMS-90725: "SDK Version Issue. This app was b ...

  3. 阿里云服务器 CentOS 安装Mysql 5.6

    下载:https://dev.mysql.com/downloads/file/?id=471181   第一步: 安装mysql5姿势是要先安装带有可用的mysql5系列社区版资源的rpm包 [ro ...

  4. 图集内子图压缩及 ETC2 fallback选项的作用

    今天研究发现,图集内的小图最好也是2的N次方或4的倍数 比如这个 采用ECT2 压缩后里面有些子图很花,就是压失败了 失败的原因是尺寸不合规则. 这个由16位改为32位就不花了,意思是当ECT2压缩失 ...

  5. Java Bug -- java.util.ConcurrentModificationException

    java.util.ConcurrentModificationException at java.util.ArrayList$ArrayListIterator.next(ArrayList.ja ...

  6. MySQL二进制日志(binary log)总结

    本文出处:http://www.cnblogs.com/wy123/p/7182356.html (保留出处并非什么原创作品权利,本人拙作还远远达不到,仅仅是为了链接到原文,因为后续对可能存在的一些错 ...

  7. OkHttp 同步异步操作

    OkHttp是一个Java和Android的HTTP和HTTP/2的客户端,负责发送HTTP请求以及接受HTTP响应. 一.使用OkHttp OkHttp发送请求后,可以通过同步或异步地方式获取响应. ...

  8. gcc 与 g++的区别

    原文: http://www.cnblogs.com/wb118115/p/5969775.html ------------------------------------------------- ...

  9. c++中被忽视的隐藏

    稍微懂得点oop的人都知道重载,那是多态性的重要体现!可是在c++中你能分清成员函数的重载.覆盖吗?这个好像也不难,重载存在与同一个类中,而覆盖存在于派生类于基类中!可是如果再加上隐藏呢?说实话,以前 ...

  10. JAVA中float与double的区别

    float是单精度类型,精度是8位有效数字,取值范围是10的-38次方到10的38次方,float占用4个字节的存储空间 double是双精度类型,精度是17位有效数字,取值范围是10的-308次方到 ...