本文主要是介绍题目1380:lucky number,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目1380:lucky numberimport 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(); }}
这篇关于题目1380:lucky number的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!