Foreign Exchange(map)

 

Sample Input

10
1 2
2 1
3 4
4 3
100 200
200 100
57 2
2 57
1 2
2 1
10
1 2
3 4
5 6
7 8
9 10
11 12
13 14
15 16
17 18
19 20
0

Sample Output

YES
NO

 


    int n,m,t;
    int i,j,k;
    map<Pair,int> mp;

int main()
{
    //IOS;
    while(~sd(n),n){
        mp.clear();
        for(i=0;i<n;i++){
            int a,b;
            sdd(a,b);
            Pair p=make_pair(a,b);
            a<b ? mp[p]++ : mp[make_pair(b,a)]--; 
        }
        bool f=1;
        /*map<Pair,int>::iterator it;
        for(it=mp.begin();it!=mp.end();it++){
            if(it->second>0){ f=0; break; }
        }*/
        for(auto it:mp){
            if(it.second>0){f=0; break;}
        }
        if(f) printf("YES\n");
        else printf("NO\n");
    }
    return 0 ;
}

第二遍使用註釋部分跑的,爲什麼 auto 和 迭代器 it 跑得一樣快呢?

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章