zoukankan      html  css  js  c++  java
  • 【Codeforces Global Round 1 A】Parity

    【链接】 我是链接,点我呀:)
    【题意】

    给你一个k位数b进制的进制转换. 让你求出来转成10进制之后这个数字是奇数还是偶数

    【题解】

    模拟一下转换的过程,加乘的时候都记得对2取余就好

    【代码】

    import java.io.*;
    import java.util.*;
    
    public class Main {
    	
    	static int N = (int)1e5;
    	static InputReader in;
    	static PrintWriter out;
    	static int b,k;
    	static int a[];
    		
    	public static void main(String[] args) throws IOException{
    		in = new InputReader();
    		out = new PrintWriter(System.out);
    		
    		//code start from here
    		a = new int[N+10];
    		b = in.nextInt();k = in.nextInt();
    		for (int i = 1;i <= k;i++) a[i] = in.nextInt();
    		int now = 1;
    		long n = 0;
    		for (int i = k;i >= 1;i--) {
    			n = (n + a[i]*now)%2;
    			now = (now * b)%2;
    		}
    		if (n%2==1) {
    			out.println("odd");
    		}else {
    			out.println("even");
    			
    		}
    		out.close();
    	}
    
    	static class InputReader{
    		public BufferedReader br;
    		public StringTokenizer tokenizer;
    		
    		public InputReader() {
    			br = new BufferedReader(new InputStreamReader(System.in));
    			tokenizer = null;
    		}
    		
    		public String next(){
    			while (tokenizer==null || !tokenizer.hasMoreTokens()) {
    				try {
    				tokenizer = new StringTokenizer(br.readLine());
    				}catch(IOException e) {
    					throw new RuntimeException(e);
    				}
    			}
    			return tokenizer.nextToken();
    		}
    		
    		public int nextInt() {
    			return Integer.parseInt(next());
    		}
    	}
    }
    
  • 相关阅读:
    柱状图最大的矩形
    单词搜索
    最小覆盖子串
    颜色分类
    编辑距离
    X的平方根
    二进制求和
    最大子序和
    N皇后
    java8-14-时间API
  • 原文地址:https://www.cnblogs.com/AWCXV/p/10355873.html
Copyright © 2011-2022 走看看