码迷,mamicode.com
首页 > 其他好文 > 详细

【Codeforces Global Round 1 A】Parity

时间:2019-02-08 10:22:01      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:java   round   asm   过程   runtime   null   oba   while   buffer   

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


给你一个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());
        }
    }
}

【Codeforces Global Round 1 A】Parity

标签:java   round   asm   过程   runtime   null   oba   while   buffer   

原文地址:https://www.cnblogs.com/AWCXV/p/10355873.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!