90分,第一个点RE,跪求大佬指点orz
查看原帖
90分,第一个点RE,跪求大佬指点orz
1211502
TearsMeow楼主2024/9/2 23:49

问题

90分,第一个样例RE,不知道是为什么

代码

import java.io.*;
import java.util.*;


public class Main {
    static int N = 10010,n,m;
    static int[] t = new int[N],x = new int[N],y = new int[N];
    static int[] f = new int[N];
    static int Int(String s){return Integer.parseInt(s);}
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
    public static void main(String[] args)throws IOException{
        String[] arrStr = br.readLine().split(" ");
        n = Int(arrStr[0]); m = Int(arrStr[1]);
        for(int i =1;i <= m;i++){
            arrStr = br.readLine().split(" ");
            t[i] = Int(arrStr[0]);x[i] = Int(arrStr[1]);y[i] = Int(arrStr[2]);
        }
        int res = 0;
        for(int i = 1;i <= m;i++){
            f[i] = 1;
            
            for(int j =1;j < i;j++){
                if(dist(i,j) > (t[i] - t[j])) continue;
                f[i] = Math.max(f[j] + 1,f[i]);
                
            }
            res = Math.max(res, f[i]);
        }
        
        pw.println(res);
        
        pw.flush();br.close();pw.close();
    }
    static int dist(int p1,int p2) {
    	return Math.abs(x[p1] - x[p2]) + Math.abs(y[p1]- y[p2] );
    }
}

2024/9/2 23:49
加载中...