Untitled

mail@pastecode.io avatar
unknown
c_cpp
a month ago
2.8 kB
1
Indexable
Never
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n;
    scanf("%d", &n);

    long long *arr = calloc(n, sizeof(long long));
    for (int i = 0; i < n; i++)
    {
        scanf("%lld", &arr[i]);
    }

    long long x, d, r;
    while (scanf("%lld %lld %lld", &x, &d, &r) != EOF)
    {
        long long index = -1;
        for (int i = 0; i < n; i++)
        {
            if (arr[i] == x)
            {
                index = i; // 找到x
                break;
            }
        }

        if (index == -1)
        {
            continue;
        }
        else
        {
            long long LD = -1, RD = -1,founded = 0;
            // 左邊
            for (int i = index - 1; i >= index - d && i >= 0; i--)
            {
                if (arr[i] >= arr[index] - r && arr[i] <= arr[index] + r)
                {
                    
                    LD = i;
                    founded = 1;
                    break;
                }
            }

            // 右邊
            for (int i = index + 1; i <= index + d && i <= n - 1; i++)
            {
                if (arr[i] >= arr[index] - r && arr[i] <= arr[index] + r)
                {
                    
                    RD = i;
                    founded = 1;
                    break;
                }else{
                    //printf("[%d,%d,%d]",arr[index] - r,arr[i],arr[index] + r);
                }
            }

            if (founded == 1)
            {
               arr[index] = -1;
            }
            

            if (LD != -1 && RD != -1)
            {
                //printf("S1\n");
                if (index - LD == index - RD || index - LD <= RD - index)
                {
                    //printf("P1\n");
                    arr[LD] = -1;
                }
                else
                {
                    //printf("P2\n");
                    arr[RD] = -1;
                    //printf("%d %d\n",RD,index);
                }
            }else if(LD != -1){
                //printf("S2\n");
                arr[LD] = -1;
            }else{
                //printf("S3\n");
                arr[RD] = -1;
            }

            int newLength = 0;
            for (int i = 0; i < n; i++)
            {
                if (arr[i] != -1)
                {
                    arr[newLength++] = arr[i];
                }
            }
            n = newLength;
        }
    }

    if (n == 0)
    {
        printf("Wonderful\n");
    }

    for (size_t i = 0; i < n; i++)
    {
        if (arr[i] != -1)
        {
            printf("%lld ", arr[i]);
        }
    }

    return 0;
}
Leave a Comment