解题思路:
直接开辟一个数组,用来模拟木板,数组的元素用来存储所涂的颜色。
参考代码:
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt();//木板长度(n<=100000) int m = scanner.nextInt();//涂色的次数(m<=100) int[] mb = new int[100000];//模拟模木板 int[] l = new int[m];//左端 int[] r = new int[m];//右端 int[] c = new int[m];//颜色 for (int i = 0; i < m; i++) { l[i] = scanner.nextInt(); r[i] = scanner.nextInt(); c[i] = scanner.nextInt(); } int x = scanner.nextInt();//表示询问的位置 for (int i = 0; i < m; i++) { int left = l[i]; int right = r[i]; int color = c[i]; for( int j = left; j <= right; j++) { mb[j] = color; } } System.out.println(mb[x]); } }
0.0分
0 人评分