当前位置: 代码迷 >> 综合 >> HDOJ 2103 Family planning
  详细解决方案

HDOJ 2103 Family planning

热度:92   发布时间:2023-10-21 18:54:10.0

HDACM 2103

注意:在break之前需 i++ 还有m不一定小于n 用long型值计算

import java.util.Scanner;public class Main{public static void main(String[] args) {long ans[] = new long[31];for (int i = 1; i < ans.length; i++) {ans[i] = ans[i-1]+10000*(long)Math.pow(2, i-1);}Scanner sc = new Scanner(System.in);int t = sc.nextInt();while (t-- > 0) {int m = sc.nextInt();int n = sc.nextInt();int baby[] = new int[n];for (int i = 0; i < n; i++) {baby[i] = sc.nextInt();}int i = 0;for (; i <(m<n?m:n); i++) {if (baby[i] == 0) {continue;}if (baby[i]==1) {i++;break;}}System.out.println(ans[n-i]+" RMB");}sc.close();}
}