HDU 4022 bombing (discretization)

Source: Internet
Author: User

Bombing

Time limit:4000/2000 MS (java/others) Memory limit:65768/65768 K (java/others)
Total submission (s): 3176 Accepted Submission (s): 1195


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 is a hard work in circumstances of the street battles, however, you'll be encountered a much more difficult in Stance:recounting exploits of the military. In the bombing action, the commander would dispatch a group of bombers with weapons have the huge destructive power to de Stroy all the targets in a line. Thanks to the outstanding work of our spies, the positions of all opponents ' bases had been detected and marked on the map, Consequently, the bombing plan is sent to you.
Specifically, the map is expressed as a 2d-plane with some positions of enemy ' s bases marked on. The Bombers is dispatched orderly and each of the them would bomb a vertical or horizontal line on the map. Then your commanded wants the report, how many bases would be destroyed by each bomber. Notice that a ruined base would not be taken to account when calculating the exploits of later bombers.

Inputmultiple test Cases and each test cases starts with a 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 are a pair of integers x and y separated by single space indicating the coordinate of Positi On the each opponent ' s base. The following M lines describe the bombers, each of them contains both integers C and D where C is 0 or 1 and D are an integ Er with absolute value no further than 109, if C = 0, then this bomber would bomb the line x = d, otherwise y = d. The input would end when N = M = 0 and the number of test cases are 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 de Stroyed by 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 WA took two times, because at the same point there could be multiple bases ... So with set is wrong, should use multiset and then because this problem saw Map+set realize discretization of another kind of writing my Code:
1 /*************************************************************************2 > File name:code/hdoj/4022.cpp3 > Author:111qqz4 > Email: [Email protected]5 > Created time:2015 August 01 Saturday 04:37 20 seconds6  ************************************************************************/7 8#include <iostream>9#include <iomanip>Ten#include <cstdio> One#include <algorithm> A#include <cmath> -#include <cstring> -#include <string> the#include <map> -#include <Set> -#include <queue> -#include <vector> +#include <stack> - #defineY0 ABC111QQZ + #defineY1 HUST111QQZ A #defineYn hez111qqz at #defineJ1 CUTE111QQZ - #defineTM CRAZY111QQZ - #defineLR DYING111QQZ - using namespacestd; - #defineREP (i, n) for (int i=0;i<int (n); ++i) -typedefLong LongLL; intypedef unsignedLong LongULL; - Const intn=2e5+7; to Const intINF =0x7fffffff; +  -map<int,int>xmap,ymap;34 multiset<int>x[n];35 multiset<int>y[n]; $ intMain ()Panax Notoginseng { -     intn,m; the      while(SCANF ("%d%d", &n,&m)! =EOF) +     { A     if(n==0&&m==0) Break; the      for(inti =1; I <= N; i++) +     { - x[i].clear (); $ y[i].clear (); $     } - xmap.clear (); - ymap.clear (); the     intTx,ty; -     intcntx=0, cnty=0;Wuyi      for(inti =1; I <= N; i++ ) the     { -scanf"%d%d",&tx,&ty); Wu         if(!xmap[tx]) xmap[tx]=++Cntx; -         if(!ymap[ty]) ymap[ty]=++Cnty; About X[xmap[tx]].insert (Ymap[ty]); $ Y[ymap[ty]].insert (Xmap[tx]); -     } -     intc,d; -     Set<int>:: iterator it; A      for(inti =1; I <= m; i++ ) +     { thescanf"%d%d",&c,&d); -         if(c==0) $         { theCout<<x[xmap[d]].size () <<Endl; the          for(it = X[xmap[d]].begin (); It!=x[xmap[d]].end (); it++) the         { they[*it].erase (Xmap[d]); -         } in x[xmap[d]].clear (); the         } the         Else About         { theCout<<y[ymap[d]].size () <<Endl; the          for(It =y[ymap[d]].begin (); It!=y[ymap[d]].end (); it++) the         { +x[*it].erase (Ymap[d]); -  the         }Bayi y[ymap[d]].clear (); the         } the     } -printf"\ n"); -     } the    the     return 0; the}

Another way of writing online code (the last two methods are written, the problem is too lazy to write a la La, anyway all the same)

1#include <iostream>2#include <cstring>3#include <string>4#include <cstdio>5#include <algorithm>6#include <map>7#include <Set>8 #defineMaxx 1000059 using namespacestd; 10   typedef map<int,multiset<int> > node;  One node mx; A node my; -  - intCal (Node &x,node &y,intp) the { -     intres=x[p].size (); -multiset<int>:: iterator it; -      for(It=x[p].begin (); It!=x[p].end (); it++) +     { -         //x[p].erase (*it); //It cannot be deleted, so it is invalid after it is deleted +y[*it].erase (p); A     } atX[p].clear ();//empty directly once -     returnRes; - } -  - intMain () - { in     intn,m,x,y,q,p; -      while(SCANF ("%d%d",&n,&m)) to     { +         if(n==0&&m==0) Break; - mx.clear (); My.clear (); the          while(n--) *         { $scanf"%d%d",&x,&y);Panax Notoginseng Mx[x].insert (y); - My[y].insert (x); the         } +          while(m--) A         { thescanf"%d%d",&q,&p); +             if(q==0) printf ("%d\n", Cal (Mx,my,p)); -             Elseprintf"%d\n", Cal (My,mx,p)); $         } $Puts""); -     } -     return 0; the}

HDU 4022 bombing (discretization)

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.