HDU 4022 Bombing(stl,map,multiset,iterater遍历)
#define _CRT_SECURE_NO_WARNINGS //用的是STL中的map 和 multiset 来做的,代码写起来比较简洁,也比较好容易理解。
//multiset可以允许重复
//multiset<int>::iterator it; 用来遍历 #include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<string>
#include<math.h>
#include<set>
#include<map>
using namespace std; //#define IN freopen("c:\\Users\\nit\\desktop\\input.txt", "r", stdin)
//#define OUT freopen("c:\\Users\\nit\\desktop\\output.txt", "w", stdout)
//int gcd(int a,int b){return b==0?a:gcd(b,a%b);} // 建立一个 map,从 int 到 一个 multiset 容器的映射
typedef map<int,multiset<int> > line; // 两个>间一定要加个空格
line yy,xx; //定义x,y坐标各自对应的map int bomb(line &xx, line &yy, int post)
{
multiset<int>::iterator it;
int ans = xx[post].size();
for(it=xx[post].begin(); it!=xx[post].end(); it++)
{
yy[*it].erase(post); //multiset 去除一个元素
}
xx[post].clear(); //清空multiset
return ans;
}
int main()
{
int n,m,x,y,i;
while(scanf("%d%d",&n,&m)!=EOF)
{
if(n==&&m==)break;
for(i=;i<n;i++)
{
scanf("%d%d",&x,&y);
xx[x].insert(y);
yy[y].insert(x);
}
for(i=;i<m;i++)
{
scanf("%d%d",&x,&y);
if(x==)
printf("%d\n",bomb(xx,yy,y));
else
printf("%d\n",bomb(yy,xx,y));
}
puts("");
}
return ;
}
HDU 4022 Bombing(stl,map,multiset,iterater遍历)的更多相关文章
- HDU 4022 Bombing (map + multiset)
题意: 在x,y坐标范围为10 ^ -9 ~~ 10 ^ 9的坐标轴之中,有 10W个点(注意有些点可能在同一坐标上),然后有10W个询问,处理询问按照输入顺序处理,对于每个询问a,b a == ...
- hdu 4022 Bombing(map,multiset)
题意:n个基地放在2维平面,然后m个炸弹人,每个炸弹人可以炸一行或者一列,输出每个炸弹人炸掉的基地个数. 思路:用map<int,multiset<int> >对应起来一行或者 ...
- HDU 4022 Bombing STL 模拟题
人工模拟.. #include<stdio.h> #include<iostream> #include<algorithm> #include<vector ...
- hdu 4022 Bombing
Bombing Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)Total Sub ...
- HDU 2112 HDU Today(STL MAP + Djistra)
题目链接:HDU Today 立即集训要開始,抓紧时间练练手,最短路的基础题,第一次用STL的map 题目非常水,可是错了N遍.手贱了.本题不优点理的就是把地名转化为数字 #include <i ...
- hdu 4585 Shaolin(STL map)
Problem Description Shaolin temple is very famous for its Kongfu monks.A lot of young men go to Shao ...
- Bombing HDU, 4022(QQ糖的消法)
Bombing From:HDU, 4022 Submit Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65768/65768 ...
- hdu 4022 STL
题意:给你n个敌人的坐标,再给你m个炸弹和爆炸方向,每个炸弹可以炸横排或竖排的敌人,问你每个炸弹能炸死多少个人. /* HDU 4022 G++ 1296ms */ #include<stdio ...
- POJ 3096 Surprising Strings(STL map string set vector)
题目:http://poj.org/problem?id=3096 题意:给定一个字符串S,从中找出所有有两个字符组成的子串,每当组成子串的字符之间隔着n字符时,如果没有相同的子串出现,则输出 &qu ...
随机推荐
- poj 1564 Sum It Up
题目连接 http://poj.org/problem?id=1564 Sum It Up Description Given a specified total t and a list of n ...
- 九度oj 1521 二叉树的镜像
原题链接:http://ac.jobdu.com/problem.php?pid=1521 水题,如下.. #include<algorithm> #include<iostream ...
- rm -rf删除过多文件提示参数过长
cd /var/tmp/ find . -name "*.log"|xargs rm -rf "*.log"
- [转]IIS部署托管管道模式的集成和经典区别
关于ESPS和SCSJ在Windows server 2008的问题总结 SCSJ出现的问题在于集成模式和经典模式的选择上,系统本身是没有问题的.我们在部署系统的时候,选择了集成模式,导致WebCon ...
- [转]开源中国的 IT 公司开源软件整理计划介绍
[转]开源中国的 IT 公司开源软件整理计划介绍 http://www.oschina.net/news/61534/oschina-opensource-collection-plan-for-it ...
- [Linq Expression]练习自己写绑定
源代码:TypeMapper.zip 背景 项目中,我们会经常用到各种赋值语句,比如把模型的属性赋值给UI,把视图模型的属性拷贝给Entity.如果模型属性太多,赋值也会变成苦力活.所以,框架编程的思 ...
- JAVA数据结构-----枚举
枚举(Enumeration)接口虽然它本身不属于数据结构,但它在其他数据结构的范畴里应用很广. 枚举(The Enumeration)接口定义了一种从数据结构中取回连续元素的方式. 例如,枚举定义了 ...
- Machine Learning 学习笔记 (2) —— 使用牛顿法寻找极值
本系列文章允许转载,转载请保留全文! [请先阅读][说明&总目录]http://www.cnblogs.com/tbcaaa8/p/4415055.html 1. 用牛顿法解方程 牛顿法是一种 ...
- STL学习三:deque容器
1.Deque简介 deque是“double-ended queue”的缩写,和vector一样都是STL的容器,deque是双端数组,而vector是单端的. deque在接口上和vector非常 ...
- To add private variable to this Javascript literal object
You can use number as function/variable name, the numberic name can't be accessed from parent scope, ...