头像

流眼泪




离线:1个月前


最近来访(6)
用户头像
费列罗
用户头像
A1m233
用户头像
小郑同学
用户头像
Maggot
用户头像
Destiny.宿命
用户头像
yxc


流眼泪
2022-02-22 10:11

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int[] temp = Arrays
.stream(in.nextLine().split(” “))
.mapToInt(Integer::parseInt)
.toArray();
int N = temp[0], M = temp[1], T = temp[2];
// 将每一个HashMap作为一个时间
HashMap< Integer, Integer>[] arr = new HashMap[T+1];
for ( int i = 0 ; i < T+1 ; i ) {
arr[i] = new HashMap< Integer, Integer>();
}
int id, ti;
for ( int i = 0 ; i < M ; i
) {
ti = in.nextInt();
id = in.nextInt();

        arr[ti].put(id, arr[ti].getOrDefault(id, 0)+1);
    }
    ArrayList<Integer> res = new ArrayList<>();
    int[] prior = new int[N+1];
    for ( int t = 1 ; t <= T ; t++ ) {
        // 需要注意的是,在运行程序的时候,需要对于所有项目进行 sub 1 and test of prior List 
        for ( int i = 0 ; i < N+1 ; i++ ) {
            if ( arr[t].keySet().contains(i) ) {
                prior[i] += 2*arr[t].get(i);
            }
            if ( !arr[t].containsKey(i) ) {
                prior[i] = Math.max(0, prior[i]-1);
            }
            if ( prior[i] > 5 && !res.contains(i)) 
                res.add(i);
            if ( prior[i] <= 3 && res.contains(i) )
                res.remove(Integer.valueOf(i));
        }
    }
    System.out.println(res.size());



}

}