package PAT1009; import java.util.Scanner; //相乘后1000的幂最多会变成2000,所以第二个数组需要声明为2000 public class Main2 { public static void main(String[] args) { int k; int p; double q; double[] n = new double[1001]; double[] newN = new double[2001]; Scanner sc = new Scanner(System.in); k = sc.nextInt(); for(int i = 0; i < k; i++) { p = sc.nextInt(); q = sc.nextDouble(); n[p] = q; } k = sc.nextInt(); for(int i = 0; i < k; i++) { p = sc.nextInt(); q = sc.nextDouble(); for(int j = 0; j <= 1000; j++) { if(n[j] != 0) { int newP = j + p; double newQ = n[j] * q; newN[newP] += newQ; } } } int count = 0; for(int i = 0; i <= 2000; i++) { if(newN[i] != 0) { count++; } } System.out.print(count); for(int i = 2000; i >= 0; i--) { if(newN[i] != 0.0) { System.out.print(" " + i + " "); System.out.printf("%.1f", newN[i]); } } } }
PAT1009
最新推荐文章于 2021-01-30 17:47:19 发布