P1563 玩具谜题:https://www.luogu.com.cn/problem/P1563
import java.util.*;
class Node{
String name = "";
int direction = 0;
Node(int direction, String name){
this.name = name;
this.direction = direction;
}
}
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();//小人
int m = scan.nextInt();//指令条数
Node[] node = new Node[n];
for (int i = 0; i < n; i ++){
node[i] = new Node(scan.nextInt(), scan.next());
}
int step = 0;
for (int i = 0; i < m; i ++){
int ans = scan.nextInt();
int num = scan.nextInt();
if ((ans == 0 && node[step].direction == 0) || (ans == 1 && node[step].direction == 1))
step = (step + n - num) % n;
else if ((ans == 0 && node[step].direction == 1) || (ans == 1 && node[step].direction == 0))
step = (step + num + n) % n;
}
System.out.print(node[step].name);
}
}
P1068 分数线划定
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int m = scan.nextInt();
Map<Integer, Integer> map = new HashMap<>();
for (int i = 0; i < n; i ++)
map.put(scan.nextInt(), scan.nextInt());
int t = (int) (m * 1.5);
List<Map.Entry<Integer, Integer>> list = new ArrayList<>(map.entrySet());
//按分数从大到小排序 若分数一样则按学号从小到大排序
list.sort(new Comparator<Map.Entry<Integer, Integer>>() {
@Override
public int compare(Map.Entry<Integer, Integer> o1, Map.Entry<Integer, Integer> o2) {
if (o1.getValue() < o2.getValue())
return 1;
else if (o1.getValue()==o2.getValue())
return o1.getKey().compareTo(o2.getKey());
else
return -1;
}
});
int num = list.get(t-1).getValue();
int count = 0;
for (int i = 0; i < n; i ++){
if (list.get(i).getValue() >= num)
count ++;
}
System.out.println(num + " " + count);
for (int i = 0; i < count; i ++){
System.out.println(list.get(i).getKey() + " " + list.get(i).getValue());
}
}
}