本文主要是介绍P9343 一曲新词酒一杯,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
import java.util.Scanner;public class Main {static int fun(Scanner sc) {int n, m;int res = -1;int k = 0;n = sc.nextInt();// n个杯子m = sc.nextInt();// m次操作boolean[] a = new boolean[n];boolean[] v = new boolean[n];for (int i = 0; i < m; i++) {int o, x;o = sc.nextInt();x = sc.nextInt();if (res != -1)continue;if (o == 1) {if (a[x - 1] == false) {a[x - 1] = true;k++;if (k == n) {res = i + 1;}}} else {// o==2if (v[x - 1] == false) {// 防止重复分析v[x - 1] = true;if (a[x - 1] == true) {res = i + 1;} else {for (int j = 0; j < n; j++) {a[j] = true;}a[x - 1] = false;k = n - 1;}}}}return res;}public static void main(String[] args) {int n;Scanner sc = new Scanner(System.in);n = sc.nextInt();for (int i = 0; i < n; i++) {int res = fun(sc);System.out.println(res);}sc.close();}}
这篇关于P9343 一曲新词酒一杯的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!