参考代码:
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; public class Main { public static void main(String[] args) throws IOException { BufferedReader read = new BufferedReader(new InputStreamReader(System.in));//java数据较多时用这个输入,我还不太熟悉,可能写的不行 int n = Integer.parseInt(read.readLine().split(" ")[0]); int[] a = new int[n]; int[] b = new int[n]; int[] c = new int[n]; String[] in1 = read.readLine().split(" "); for(int i = 0; i < n; i++) a[i] = Integer.parseInt(in1[i]); String[] in2 = read.readLine().split(" "); for(int i = 0; i < n; i++) b[i] = Integer.parseInt(in2[i]); String[] in3 = read.readLine().split(" "); for(int i = 0; i < n; i++) c[i] = Integer.parseInt(in3[i]); Arrays.sort(a); Arrays.sort(b); Arrays.sort(c); long res = 0; int p = 0; int q = 0; for(int i = 0; i < n; i++)//枚举b数组的值 { while(p < n && a[p] < b[i]) p++; while(q < n && c[q] <= b[i]) q++; res += (long)p * (n - q); } System.out.print(res); } }
0.0分
5 人评分
C语言程序设计教程(第三版)课后习题6.9 (C语言代码)浏览:760 |
C语言程序设计教程(第三版)课后习题8.7 (C语言代码)浏览:609 |
C语言训练-自由落体问题 (C语言代码)浏览:650 |
C语言训练-数字母 (C语言代码)浏览:648 |
GC的苦恼 (C语言代码)浏览:672 |
淘淘的名单 (C语言代码)浏览:1309 |
C语言训练-大、小写问题 (C语言代码)浏览:719 |
C二级辅导-等差数列 (C语言代码)浏览:891 |
A+B for Input-Output Practice (IV) (C语言代码)浏览:529 |
数列有序 (C语言代码)浏览:974 |