9.10 阿里笔试第二题(当时没写出来,我是菜鸟)
import java.util.Scanner; /** * @author wc * @create 2021/09/10 19:24 * @desc 9-10 阿里第二题 当时是没有写出来的 答案如果不对 请轻喷 */ public class Main2 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); // 接着a b c d long a = sc.nextLong(); long b = sc.nextLong(); long c = sc.nextLong(); long d = sc.nextLong(); long n = sc.nextLong(); while (n-- != 0) { int sum = 0; long i = sc.nextLong(); long j = sc.nextLong(); int m = 2; // System.out.println(i + " " + j); while (i > m || j > m) { m *= 2; } m /= 2; // 奇数行与奇数列要多加1 if(m!=1&&i%2==1&&j%2==1){ sum+=a; } while (m!=0) { if (i <= m && j <= m) { sum += a; } else if (i > m && j > m) { i -= m; j -= m; sum += c; } else if (i <= m && j > m) { j -= m; sum += b; } else if (i > m && j <= m) { i -= m; sum += d; } while (i<=m&&j<=m) { m /= 2; } } // System.out.println(i+" "+j); System.out.println(sum); } } }
#阿里笔试##笔试题目##阿里巴巴#