zoukankan      html  css  js  c++  java
  • find your present (2) hdoj 2095

    /*
    author:谦智
    find your present (2)  hdoj 2095
    法一:用暴力
    法二:用map
    法三:
    符号是^.
    异或是个位运算符号,具体是怎么操作的请百度,这里有个特性使得他能产生一种巧方法
    a^a=0 
    0^c=c
    
    看到上面这个式子是否你懂了呢?
    没错,例如样例
    5
    1 1 3 2 2
    如果我们用异或运算计算就是
    1^1^3^2^2
    
    由于1^1=0 2^2=0,那么就只剩下了唯一的一个3了。
    如果有3个3,那么前面偶数个3由于3^3=0,势必也会只留下一个孤单的3.
    
    那么答案就只能是那个多余的数字了。 
    
    
    */
    
    //#include<iostream>
    //#include<cstdio>
    //using namespace std;
    //int main() {
    //  int n;
    //  while (scanf("%d",&n),n) {
    //    int ans = 0;
    //    for (int i = 0; i < n; i++) {
    //      int x;
    //      scanf("%d",&x);
    //      ans ^= x;
    //    }
    //    printf("%d
    ",ans);
    //  }
    //}
    
    
    
    //#include<iostream>
    //using namespace std;
    //int main() {
    //  int n;
    //  while (cin >> n, n) {
    //    int ans = 0;
    //    for (int i = 0; i < n; i++) {
    //      int x;
    //      cin >> x;
    //      ans ^= x;
    //    }
    //    cout << ans << endl;
    //  }
    //}
    
    
    
    
    //map 改题设定为c的输入输出 
    #include<iostream>
    #include<map>
    #include<cstdio>
    using namespace std;
    int main() {
      int n;
      while (scanf("%d",&n),n) {
        map<int,int> Map;
        for (int i = 0; i < n; i++) {
          int x;
          scanf("%d",&x);
          Map[x]++;
        }
        map<int,int>::iterator it = Map.begin();
        for (; it != Map.end(); it++) {
          if (it->second%2) {
            printf("%d
    ",it->first);
            break;
          }
        }
      }
    }
  • 相关阅读:
    无向图判断割点
    C
    连通图 求至少有给几个点信息才能传遍全图,至少添加几条边才能使全图联通
    线段树区间更新(set暴力)
    A
    辗转相除法(数学推理)
    Python List index()方法
    Python List extend()方法
    Python List count()方法
    Python List append()方法
  • 原文地址:https://www.cnblogs.com/dream-it-possible/p/8584964.html
Copyright © 2011-2022 走看看