HDU 4022 bombing

Source: Internet
Author: User
Bombing

Time Limit: 4000/2000 MS (Java/others) memory limit: 65768/65768 K (Java/Others)
Total submission (s): 2650 accepted submission (s): 990

Problem descriptionit'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. I Nputmultiple 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. outputfor each test case, output M lines, the ith line contains a single integer denoting the number of bases that were destroyed The corresponding bomber in the input. output a blank line after each test case. sample input3 21 21 32 30 11 30 0 sample output21 sourcethe 36th ACM/ICPC Asia Regional Shanghai site -- online contest ---------------- the second team competition in the summer vacation, a little bad .. This is the AC code of dengyaolong, And I will post it to learn more .....
 1 #include<iostream> 2 #include<cstdio> 3 #include<string> 4 #include<cstring> 5 #include<map> 6 #include<set> 7 #include <algorithm> 8 using namespace std; 9 10 int main(){11     int N,M,i,j,x,y;12     while(scanf("%d%d",&N,&M)&&(N||M)){13         map<int,multiset<int> > row;14         map<int,multiset<int> > col;15         for(i=0;i<N;i++){16             scanf("%d%d",&x,&y);17             row[x].insert(y);18             col[y].insert(x);19         }20         for(i=0;i<M;i++){21             scanf("%d%d",&x,&y);22             int ans=0;23             if(x==0){24                 printf("%d\n",row[y].size());25                 for(multiset<int>::iterator itr=row[y].begin();itr!=row[y].end();itr++){26                     col[*itr].erase(y);27                 }28                 row[y].clear();29             }else{30                 printf("%d\n",col[y].size());31                 for(multiset<int>::iterator itr=col[y].begin();itr!=col[y].end();itr++){32                     row[*itr].erase(y);33                 }34                 col[y].clear();35                 36             }37             38         }39         puts("");40 41     }42     43     return 0;44 }
View code

 

 

HDU 4022 bombing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.