zoukankan      html  css  js  c++  java
  • hdu 4022 Bombing

    Bombing

    Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)
    Total Submission(s): 2650    Accepted Submission(s): 990

    Problem Description
    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.
     
    Input
    Multiple 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.
     
    Output
    For each test case, output M lines, the ith line contains a single integer denoting the number of bases that were destroyed by the corresponding bomber in the input. Output a blank line after each test case.
     
    Sample Input
    3 2 1 2 1 3 2 3 0 1 1 3 0 0
     
    Sample Output
    2 1
     
    Source
     
    ----------------
    暑假第二场组队赛,有点惨败。。这是dengyaolong师兄AC代码,贴过来学习一下......  = =有时候暴力真的出奇迹.....
     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
    ",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
    ",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
  • 相关阅读:
    Hexo+Github 搭建一个自己的博客
    vue中sessionStorage存储的用法和问题
    vue 页面刷新
    vue渲染完页面后div滚动条定位在底部
    vue 定义全局函数
    vue filter过滤器用法
    vue中bus.$on事件被多次绑定
    vue中引入jQuery的方法
    vue2.0传值方式:父传子、子传父、非父子组件、路由跳转传参
    vue打包后显示为空白页的解决办法
  • 原文地址:https://www.cnblogs.com/imLPT/p/3941484.html
Copyright © 2011-2022 走看看