zoukankan      html  css  js  c++  java
  • hdu 4022(map一对多)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4022

    STL应用,一开始用multimap写的,然后实现不了,于是就看了别人用map自定义了一个一对多。。。orz。。。

    剩下的就简单了。。分别用两个这样的map容器装下 x为键,y为值,和y为键,x为值的两个容器。 然后当C==0就输出当键位d的容器大小,并且去掉另一个容器中出现的点。

    同理C==1一样。

    View Code
     1 #include<iostream>
     2 #include<map>
     3 #include<set>
     4 const int N=100010;
     5 using namespace std;
     6 int n,m;
     7 typedef map<int,multiset<int> >mp;
     8 multiset<int>::iterator iter;
     9 
    10 int main(){
    11     while(~scanf("%d%d",&n,&m)){
    12         if(n==0&&m==0)break;
    13         mp mp1,mp2;
    14         int x,y,c,d,_count;
    15         for(int i=0;i<n;i++){
    16             scanf("%d%d",&x,&y);
    17             mp1[x].insert(y);
    18             mp2[y].insert(x);
    19         }
    20         for(int i=0;i<m;i++){
    21             scanf("%d%d",&c,&d);
    22             _count=0;
    23             if(c==0){
    24                 _count=mp1[d].size();
    25                 for(iter=mp1[d].begin();iter!=mp1[d].end();iter++){
    26                     mp2[*iter].erase(d);
    27                 }
    28                 mp1[d].clear();
    29             }else if(c==1){
    30                 _count=mp2[d].size();
    31                 for(iter=mp2[d].begin();iter!=mp2[d].end();iter++){
    32                     mp1[*iter].erase(d);
    33                 }
    34                 mp2[d].clear();
    35             }
    36             printf("%d\n",_count);
    37         }
    38         printf("\n");
    39     }
    40     return 0;
    41 }
  • 相关阅读:
    hdu 2680(最短路)
    hdu 1548(最短路)
    hdu 1596(最短路变形)
    hdu 1546(dijkstra)
    hdu 3790(SPFA)
    hdu 2544(SPFA)
    CodeForces 597B Restaurant
    CodeForces 597A Divisibility
    CodeForces 598E Chocolate Bar
    CodeForces 598D Igor In the Museum
  • 原文地址:https://www.cnblogs.com/wally/p/2958324.html
Copyright © 2011-2022 走看看