Bombing HDU, 4022(QQ糖的消法)
Bombing
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)
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.
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.
case.
3 2
1 2
1 3
2 3
0 1
1 3
0 0
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糖的消法)的更多相关文章
- hdu 4022 STL
题意:给你n个敌人的坐标,再给你m个炸弹和爆炸方向,每个炸弹可以炸横排或竖排的敌人,问你每个炸弹能炸死多少个人. /* HDU 4022 G++ 1296ms */ #include<stdio ...
- hdu 4022 Bombing
Bombing Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)Total Sub ...
- HDU 4022 Bombing(stl,map,multiset,iterater遍历)
题目 参考了 1 2 #define _CRT_SECURE_NO_WARNINGS //用的是STL中的map 和 multiset 来做的,代码写起来比较简洁,也比较好容易理解. ...
- HDU 4022 Bombing (map + multiset)
题意: 在x,y坐标范围为10 ^ -9 ~~ 10 ^ 9的坐标轴之中,有 10W个点(注意有些点可能在同一坐标上),然后有10W个询问,处理询问按照输入顺序处理,对于每个询问a,b a == ...
- HDU 4022 Bombing STL 模拟题
人工模拟.. #include<stdio.h> #include<iostream> #include<algorithm> #include<vector ...
- hdu 4022 Bombing(map,multiset)
题意:n个基地放在2维平面,然后m个炸弹人,每个炸弹人可以炸一行或者一列,输出每个炸弹人炸掉的基地个数. 思路:用map<int,multiset<int> >对应起来一行或者 ...
- HDU 4022 stl multiset
orz kss太腻害了. 一.set和multiset基础 set和multiset会根据特定的排序准则,自动将元素进行排序.不同的是后者允许元素重复而前者不允许. 需要包含头文件: #include ...
- ListView获取网络数据并展示优化练习
权限: <uses-permission android:name="android.permission.INTERNET"></uses-permission ...
- asp.net Mvc 使用NPOI导出Excel文件
1.新建MVC项目,新建控制器.视图 添加控制器: 添加视图(将使用布局页前面的复选框里的勾勾去掉) 2.在Models里新建一个类 public class Shop { /// <summa ...
随机推荐
- Heritrix与Nutch对比
Nutch 开发语言:Java http://lucene.apache.org/nutch/ 简介: Apache的子项目之一,属于Lucene项目下的子项目. Nutch是一个基于Lucene,类 ...
- Xenu-web开发死链接检測工具应用
Xenu 是一款深受业界好评,并被广泛使用的死链接检測工具. 时常检測站点并排除死链接,对站点的SEO 很重要,由于大量死链接存在会减少用户和搜索引擎对站点的信任,web程序开发者还可通过其找到死链接 ...
- WPF自定义ListBox样式
<!--竖向--> <Style x:Key="ListBoxStyle1" TargetType="{x:Type ListBox}"> ...
- MongoDB--Getting Started with Java Driver
原文链接 http://docs.mongodb.org/ecosystem/tutorial/getting-started-with-java-driver/ 介绍 本文的目的是让你对怎样使用M ...
- .Net C# Windows Service于server无法启动,错误 193:0xc1
1.情况说明:的近期发展windows维修,当地win7系统正常.把server安装会失败. 图中的引导失败的例子.: 解决方法:执行->输入:eventvwr.msc 打开你的事件查看器 ...
- jsoup方法string转document
//Document doc2 = Jsoup.parseBodyFragment(element.text()); //String FieldName=doc ...
- surfaceflinger中各个layer的排序
surfaceflinger的主要工作就是负责把上层传递下来的各个不同的layer进行composition. 这里,我们来讨论一下各个layer在surfaceflinger中的上下排序关系和相关的 ...
- hdu 4771 Stealing Harry Potter's Precious
题目:给出一个二维图,以及一个起点,m个中间点,求出从起点出发,到达每一个中间的最小步数. 思路:由于图的大小最大是100*100,所以要使用bfs求出当中每两个点之间的最小距离.然后依据这些步数,建 ...
- 游戏开发实验室的内部讲座总结----c++
第三节 动态内存分配new和delete 经过调试设置断点,发现new 函数事实上还是调用的malloc函数. 第四节 引用 一个变量是能够有多个引用的,引用也是能够传递的. 常量是不能有 ...
- Socket开发
Socket开发框架之消息的回调处理 伍华聪 2016-03-31 20:16 阅读:152 评论:0 Socket开发框架之数据加密及完整性检查 伍华聪 2016-03-29 22:39 阅 ...