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 10 9, 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.

写一下本人的解法,一开始想到用结构体去写,写完一个O(N)的,oj上超时。后面用map写O(logn)的,也是超时。最后把cin改成scanf才能ac。说明这道题的测试样例点很多。而scanf读入速度约为cin的10倍,这题时间要求挺严格的。

下面粘贴代码:

#include <map>
#include <iostream>
#include <set>
#include <cstdio>
using namespace std;int main() {int n, m;while (cin >> n >> m) {map<long long int, multiset<long long int > > mapx;map<long long int, multiset<long long int > > mapy;if (n == 0 && m == 0)break;long long int x, y;for (int i = 0; i < n; i++) {scanf("%lld %lld", &x, &y);mapx[y].insert(x);mapy[x].insert(y);}multiset<long long int >::iterator it;long long int choose, line;for (int i = 0; i < m; i++) {cin >> choose >> line;if (choose == 1) {cout << mapx[line].size() << endl;//用y找有几个x,输出对应数量for (it = mapx[line].begin(); it != mapx[line].end(); it++) {//输出完之后,把另一个map中的对应点删掉if (mapy[*it].empty())//不判断empty可能会报错,我的编译器会报错。continue;elsemapy[*it].erase(mapy[*it].find(line));}mapx[line].clear();//删除y=line时所有的x}if (choose == 0) {//同理用x找有几个y时cout << mapy[line].size() << endl;for (it = mapy[line].begin(); it != mapy[line].end(); it++) {if (mapx[*it].empty())continue;elsemapx[*it].erase(mapx[*it].find(line));}mapy[line].clear();}}cout << endl;}return 0;
}

HDU 4022 Bombing c++解法相关推荐

  1. HDU 4022 Bombing(11年上海 二分)

    转载请注明出处,谢谢http://blog.csdn.net/acm_cxlove/article/details/7854526       by---cxlove 题目:给出一些点,给出两个操作, ...

  2. hdu 4022 Bombing

    1002 Bombing  The 36th ACM/ICPC Asia Regional Shanghai Site -- Online Contest 本题的思路就是将点映射一下,一次加入map, ...

  3. HDU 4826 Labyrinth(DP解法)

    Problem Description 度度熊是一只喜欢探险的熊,一次偶然落进了一个m*n矩阵的迷宫,该迷宫只能从矩阵左上角第一个方格开始走,只有走到右上角的第一个格子才算走出迷宫,每一次只能走一格, ...

  4. “恰好装满求最值”背包问题的初始化解析

    [问题描述] 不同于普通的没有"恰好装满"约束的背包问题,有时我们会遇到"恰好装满求最值"的背包问题.怎么求解? 其实,也很简单,只需要对普通的没有" ...

  5. linux chown 将root改变所有者为admin,Linux用户管理 权限管理 内存管理 网络管理命令 (第四天)...

    默认添加的用户会自动加入和用户名一样的组中 su 切换用户 查看当前登陆的用户: whoami id` 查看当前用户属于哪个组:groups groupadd 组名 添加组 groupdel 组名 删 ...

  6. HDU 1006 Tick and Tick 解不等式解法

    HDU 1006 Tick and Tick 解不等式解法 一開始思考的时候认为好难的题目,由于感觉非常多情况.不知道从何入手. 想通了就不难了. 能够转化为一个利用速度建立不等式.然后解不等式的问题 ...

  7. 18行代码AC_排序 HDU - 1106(sstream简单解法)

    励志用少的代码做高效表达. Problem describe 输入一行数字,如果我们把这行数字中的'5'都看成空格,那么就得到一行用空格分割的若干非负整数(可能有些整数以'0'开头,这些头部的'0'应 ...

  8. Minimum Inversion Number HDU - 1394(求一个数字环的逆序对+多种解法)

    题意: 给出n个数(0~n-1,每个数仅出现一次),问它长为n的循环序列中逆序对最少的数量. 多种解法:暴力+树状数组+分治+规律推导公式 题目: The inversion number of a ...

  9. A/B HDU - 1576 (逆元或拓展欧几里得或数学公式)多解法求大数结果

    题意:求(A/B)%9973,但由于A很大,我们只给出n(n=A%9973)(我们给定的A必能被B整除,且gcd(B,9973) = 1). 思维:(1)逆元+扩展欧几里得算法:满足a*k≡1 (mo ...

最新文章

  1. 解决内存不可read和written的问题
  2. java基础(四) java运算顺序的深入解析
  3. Yet Another Problem About Pi
  4. PHP中文件操作相关
  5. 【App性能】:TraceView分析法
  6. 计算机标准符合,计算机专利申请要符合哪些标准
  7. (pytorch-深度学习系列)pytorch避免过拟合-权重衰减的实现-学习笔记
  8. OpenCV调整图像的亮度
  9. java自定义sql查询条件_mybatis-plus QueryWrapper自定义查询条件的实现
  10. 常用开发资源整理(更新日:2017/4/26)
  11. Maya批量随机替代插件BatchReplacerV1.0.2 下载及教程
  12. 服务器车牌识别系统,车牌识别系统数据库连接问世
  13. python获取扫描枪数据线_【转】C#中判断扫描枪输入与键盘输入
  14. 电子商务和国际贸易创新
  15. CSS3鼠标悬停图片360度旋转效果
  16. 使用 ChatGPT 将您的 Excel 工作效率提高 10 倍,您不再需要成为 Excel 向导才能变得超级高效。
  17. 浅谈动态代理和静态代理的底层原理及实现
  18. 论IE8浏览器报错:$未定义及缺少对象问题
  19. div盒子水平垂直居中以及表格的居中的方法
  20. 小米装linux双系统,小米9双系统发布

热门文章

  1. 崔西凡JavaWeb笔记day13-day15(2016年8月30日22:40:43)
  2. 虚拟化服务器内存容量与数量,中小企业该如何选择虚拟化服务器
  3. 电子工程师的设计经验笔记
  4. [review]IOS的蝙蝠侠阿甘起源
  5. 1-2 云商城架构设计
  6. ROS——多线程callback函数
  7. 兮米安装包制作工具绿色版
  8. 3D轮播切换特效 源码+注释
  9. 二分类变量相关性分析spss_SPSS学习笔记13:处理分类变量的利器,对应分析
  10. Vue 组件间通信几种方式(完整版)