求助,只有50分!
查看原帖
求助,只有50分!
470881
郭亮20510507027楼主2022/10/10 21:18
import java.util.*;

public class Main {
	public static void main(String[] args) {
//		输入
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		String[][] career = new String[n][2];
		int[][] instr = new int[m][2];
		for(int i=0;i<n;i++) {
			career[i][0] = sc.next();
			career[i][1] = sc.next();
		}
		for(int i=0;i<m;i++) {
			instr[i][0] = sc.nextInt();
			instr[i][1] = sc.nextInt();
		}
		int index=0;
		for(int i=0;i<m;i++) {
//			如果该指令是顺时针的,则执行该指令后达到第(index+instr[i][1])%n个人
//			如果该指令是逆时针的,则执行该指令后达到第(index+n-instr[i][1])%n个人
			if(isShun(Integer.parseInt(career[index][0]),instr[i][0])) {
				index = (index+instr[i][1])%n;
			}else {
				index = (index+n-instr[i][1])%n;
			}
		}
//		(n-index)%n,而不是index,因为小人是序号从小到大,顺时针围成圆的,与题目相反
		System.out.println(career[(n-index)%n][1]);
	}
	
	
//	判断该条指令顺时针的还是逆时针的
	public static boolean isShun(int a,int b) {
//		如果小人朝内,向左寻找,则为顺时针,下面以此类推
		boolean y = ((a^b^1) == 1);//同或
		return y;
	}
}

2022/10/10 21:18
加载中...