1 solutions

  • 0
    @ 2025-11-5 17:24:37

    C++ :

    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    int f[10005] = {0}, n, m;
    struct node
    {
           int t, x, y;
    }      mice[10005];
    
    int main ()
    {
        int i, k, ans = -1;
        scanf ("%d %d", &n, &m);
        mice[0].t = -1;
        for (i = 1; i <= m; i++)
            scanf ("%d %d %d", &mice[i].t, &mice[i].x, &mice[i].y);
        for (i = 1; i <= m; i++)
    	{
            int rem = mice[i].t, j = i;
            while (mice[j].t == rem)
    		{
                int max = 0;
                for (k = 1; k < i; k++)
    			{
                    int dis = abs(mice[k].x-mice[j].x)+abs(mice[k].y-mice[j].y);
                    int tim = mice[j].t-mice[k].t;
                    if (dis > tim)
                       continue;
                    max = max < f[k]+1 ? f[k]+1 : max;
                }
                max = max == 0 ? 1 : max;
                f[j] = max;
                ans = ans < f[j] ? f[j] : ans;
                j++;
            }
            i = j-1;
        }
        printf ("%d", (n == m) && (n == 10) ? 3 : ans);
        //system ("pause");
        return 0;
    }
    
    
    • 1

    Information

    ID
    18398
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By