题目1380:lucky number

来源:互联网 发布:邓玉娇刺官案 知乎 编辑:程序博客网 时间:2024/05/17 06:50

题目1380:lucky number

时间限制:3 秒

内存限制:3 兆

特殊判题:

提交:2839

解决:300

题目描述:
每个人有自己的lucky number,小A也一样。不过他的lucky number定义不一样。他认为一个序列中某些数出现的次数为n的话,都是他的lucky number。但是,现在这个序列很大,他无法快速找到所有lucky number。既然这样,他就想找到那些不是lucky number。
输入:
输入有两行.
第一行有n和m。n表示出现次数为n的是lucky number,m表示序列的长度。2<=n<=10,m<=10^6,m%n!=0。
第二行为序列元素,每个元素都是正整数。
输出:
输出那个不是lucky number的数。题目保证非lucky number只有一个。
样例输入:
2 51 1 2 2 3
样例输出:
3
import java.io.IOException;import java.io.InputStreamReader;import java.io.PrintWriter;import java.io.StreamTokenizer;import java.lang.reflect.Array;import java.util.Arrays;import java.util.Scanner;public class Main {   public static void main(String[] args) throws IOException {            Scanner cin = new Scanner(new InputStreamReader(System.in)) ;      StreamTokenizer stcin = new StreamTokenizer(System.in);      PrintWriter cout = new PrintWriter(System.out) ;            while(stcin.nextToken() != StreamTokenizer.TT_EOF){        new Task().solve(stcin, cout) ;       }      cout.flush() ;       cout.close() ;     }}class  Task{   int n , m ;      static int[] bit = new int[32] ;   static{     bit[0] = 1 ;     for(int i = 1 ; i <= 31 ; i++) bit[i] = bit[i-1]<<1 ;   }    void solve(StreamTokenizer cin , PrintWriter cout) throws IOException{        n = (int)cin.nval ;     cin.nextToken() ;  m = (int)cin.nval ;    int[] bitSize = new int[32] ;    Arrays.fill(bitSize, 0) ;    for(int i = 1 ; i <= m ; i++){      cin.nextToken() ;  int x = (int)cin.nval ;      for(int j = 0  ; j <= 31 ; j++){       bitSize[j] += (bit[j] & x) > 0 ? 1 : 0 ;      }    }        int ans = 0 ;     for(int i = 0 ; i <= 31 ; i++){      bitSize[i] %= n ;       if(bitSize[i] > 0) ans += bit[i] ;    }        cout.println(ans);       //cout.flush();    }   }




0 0