样例怎么多个1?

P8661 [蓝桥杯 2018 省 B] 日志统计

FanSizhe127 @ 2023-02-23 19:57:24

#include<bits/stdc++.h>
using namespace std;
struct node{
    int id;
    int t;
}a[10005];
int n,d,k;
bool cmp(node x,node y)
{
    if(x.id!=y.id)return x.id<y.id;
    return x.t<y.t;
}
int z[10005];
int h=1,tt=1,o=0;
int f[100005]={0};
int main()
{
    //cout<<f[3]<<'\n';
    for(int i=1;i<=1000;i++)f[i]=0;
    cin>>n>>d>>k;
    a[0].t=-1000;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i].t>>a[i].id;
    }
    sort(a+1,a+n+1,cmp);
    int u=0,x=0;
    for(int i=1;i<=n;i++)
    {
        h=1;tt=2;memset(z,0,sizeof(z));
        if(f[a[i].id]==1)
        {
            continue;
        }
        while(h>=tt-1)
        {
            //if(f[a[i].id]==1)break;
            if(a[o+1].id!=a[i].id)break;
            z[h+1]=a[++o].t;h++;
            //cout<<z[h]<<'\n';
            if(z[h]-z[tt]>=d)tt++;
            int x=0;
            for(int j=tt;j<=h;j++)
            {
                x++;
                if(x>=k)
                {
                    if(z[h]-z[tt]>=d)break;
                    //if(f[a[i].id]==0)
                    cout<<a[i].id<<'\n';
                    f[a[i].id]++;
                //  cout<<"t="<<tt<<" h="<<h<<" x="<<x<<" o="<<o<<" z[h]="<<z[h]<<" z[t]="<<z[tt]<<'\n';
                    break;
                }
            }
        } 
        u=0,x=0;//
        //cout<<a[i].t<<' '<<a[i].id<<'\n';
    }
}

by Minecraft123 @ 2023-03-10 18:39:33

同问,看了半天样例没搞懂什么操作


by FanSizhe127 @ 2023-03-11 21:25:15

@Minecraft123 我是问我的输出多了个1


|