HDU 4022 Bombing (STL)
来源:互联网 发布:常用排序算法包括 编辑:程序博客网 时间:2024/05/22 06:33
题意:
给出包含N个点的点集和M次操作
对于每个操作 w z
w=1时 删除 坐标y=z的点,并输出个数
w=0时 删除 坐标x=z的点,并输出个数
思路:
AVL树问题,STL实现即可
代码:
#include <bits/stdc++.h>using namespace std;const int INF=0x3f3f3f3f;typedef struct Node{ int k1; int k2; Node(int kk1=0,int kk2=0){k1=kk1;k2=kk2;} bool operator <(const Node &a)const{ if(a.k1==k1) return a.k2>k2; return a.k1>k1; }}Node;int n,m;multiset <Node> x;multiset <Node> y;multiset <Node>::iterator it,itlow,itup;void debug(){ cout<<"x :"<<endl; for(it=x.begin();it!=x.end();it++) cout<<it->k1<<' '<<it->k2<<endl; cout<<"y :"<<endl; for(it=y.begin();it!=y.end();it++) cout<<it->k1<<' '<<it->k2<<endl; cout<<"xsize: "<<x.size()<<' '<<"yszie: "<<y.size()<<endl;}int main(){ while(~scanf("%d%d",&n,&m)){ if(n==0&&m==0) break; int w,z; x.clear(); y.clear(); for(int i=0;i<n;i++){ scanf("%d%d",&w,&z); x.insert(Node(w,z)); y.insert(Node(z,w)); } for(int i=0;i<m;i++){ scanf("%d%d",&w,&z); int ans=0; //Node temp(z,INF); if(w){ if(y.empty()||y.begin()->k1>z){ cout<<0<<endl; continue; } itlow=y.upper_bound(Node(z-1,INF)); itup=y.upper_bound(Node(z,INF)); for(it=itlow;it!=itup;it++){ x.erase(x.find(Node(it->k2,z))); ans++; } y.erase(itlow,itup); cout<<ans<<endl; }else{ if(x.empty()||x.begin()->k1>z){ cout<<0<<endl; continue; } itlow=x.upper_bound(Node(z-1,INF)); itup=x.upper_bound(Node(z,INF)); for(it=itlow;it!=itup;it++){ y.erase(y.find(Node(it->k2,z))); ans++; } x.erase(itlow,itup); cout<<ans<<endl; } //debug(); } cout<<endl; }}
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.
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.
3 21 21 32 30 11 30 0
21
0 0
- HDU 4022 Bombing (STL)
- 【STL】hdu 4022 Bombing
- HDU 4022 Bombing STL/二分
- HDU 4022 Bombing STL 模拟题
- hdoj 4022Bombing( STL )
- HDU 4022Bombing 2011网络赛(二分 或 STL)
- hdu 4022 Bombing
- HDU 4022 Bombing
- HDU 4022 Bombing
- hdu 4022 Bombing
- HDU 4022 Bombing
- map hdu 4022 Bombing
- HDU 4022 Bombing
- HDU 4022 Bombing
- HDU 4022 Bombing
- HDU Bombing (STL multiset+map)
- HDU 4022 Bombing(11年上海 二分)
- HDU 4022 Bombing (map + multiset)
- RecycleView探究(1)——实现瀑布流及问题
- error while performing databases login with sqlserver driver:unable to create connection
- Python:文件
- CS231n课程笔记5.1:神经网络历史&激活函数比较
- 快速排序实例化(详细过程)
- HDU 4022 Bombing (STL)
- Linux安装Spark2.0.2步骤
- 在tomcat下,实现通过端口访问不同的网站
- 上班第二天,第一个任务
- 5.5.2
- 我的blog
- Xcode8一些新玩法
- 【leetcode】83. Remove Duplicates from Sorted List【java】
- 5.5.3