zoukankan      html  css  js  c++  java
  • UVA 10763 Foreign Exchange 出国交换 pair+map

    题意:给出很多对数字,看看每一对(a,b)能不能找到对应的(b,a)。

    放在贪心这其实有点像检索。

    用stl做,map+pair。

    记录每一对出现的次数,然后遍历看看对应的那一对出现的次数有没有和自己出现的此时一样即可。

    代码:

     /*
     *   Author:        illuz <iilluzen@gmail.com>
     *   Blog:          http://blog.csdn.net/hcbbt
     *   File:          uva10763.cpp
     *   Lauguage:      C/C++
     *   Create Date:   2013-08-25 09:47:55
     *   Descripton:    UVA 10763 Foreign Exchange, map
     */
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <iostream>
    #include <list>
    #include <vector>
    #include <map>
    #include <set>
    #include <deque>
    #include <queue>
    #include <stack>
    #include <utility>
    #include <algorithm>
    using namespace std;
    #define rep(i, n) for (int i = 0; i < (n); i++)
    #define repu(i, a, b) for (int i = (a); i < (b); i++)
    #define repf(i, a, b) for (int i = (a); i <= (b); i++)
    #define repd(i, a, b) for (int i = (a); i >= (b); i--)
    #define swap(a, b) {int t = a; a = b; b = t;}
    #define mc(a) memset(a, 0, sizeof(a))
    #define ms(a, i) memset(a, i, sizeof(a))
    #define sqr(x) ((x) * (x))
    #define FI(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
    typedef long long LL;
    typedef unsigned long long ULL;
    
    /****** TEMPLATE ENDS ******/
    
    const int MAXN = 500100;
    struct Pair {
    	int x, y;
    	Pair(int a, int b) : x(a), y(b) {}
    	friend bool operator < (const Pair& a, const Pair& b) {
    		return (a.x < b.x || (a.x == b.x && a.y < b.y));
    	}
    };
    map<Pair, int> m;
    int n, a, b;
    
    int main() {
    	while (scanf("%d", &n) && n) {
    		m.clear();
    		rep(i, n) {
    		   	scanf("%d%d", &a, &b);
    			m[Pair(a, b)]++;
    		}
    		bool flag = true;
    		FI(i, m) {
    		   	if (i->second != m[Pair(i->first.y, i->first.x)]) {
    				flag = false;
    //				break;
    			}
    		}
    		if (flag) printf("YES
    ");
    		else printf("NO
    ");
    	}
    	return 0;
    }


  • 相关阅读:
    用GitHub Pages搭建博客(三)
    Beta阶段项目总结
    最终团队绩效评估
    Alpha阶段项目总结
    项目发布
    Alpha版总结会议
    第二次冲刺周期站立会议(10)
    第二次冲刺周期站立会议(9)
    第二次冲刺周期站立会议(8)
    第二次冲刺周期站立会议(7)
  • 原文地址:https://www.cnblogs.com/pangblog/p/3283482.html
Copyright © 2011-2022 走看看