• 【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());
    		}
    	}
    }
    
  • 相关阅读:
    三维几何模板
    凸包
    计算几何 部分模板
    几何模板
    高斯消元模板
    tarjin求割点
    在无向图中找最短桥(tarjan)
    线段树
    错排问题
    NABCD分析
  • 原文地址:https://www.cnblogs.com/AWCXV/p/10355873.html
Copyright © 2020-2023  润新知