L - Access System ZOJ - 3787 (注意函数内赋值引用调用)

本文展示了一个使用C++编写的竞赛编程示例,通过时间排序算法和逻辑判断实现对一系列时间戳的有效处理,筛选出符合特定条件的时间段内的有效记录。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

L - Access System

 ZOJ - 3787 

#include<bits/stdc++.h>
using namespace std;
struct node
{
    int h,m,s,order,flag;
} a[20005];
bool cmp(node x,node y)
{
    if(x.h==y.h&&x.m==y.m)
        return x.s<y.s;
    else if(x.h==y.h)
        return x.m<y.m;
    else
        return x.h<y.h;
}
int total,Time,sum,b[20004];
bool calculate(node &temp1,node &temp2)
{
    int ans=(temp1.h-temp2.h)*3600+(temp1.m-temp2.m)*60+(temp1.s-temp2.s);
    if(ans<Time)
    {
        temp1.flag=0;
        return false;
    }
    return true;
}
int main()
{
    int t;
    char str;
    cin>>t;
    while(t--)
    {
        sum=1;
        cin>>total>>Time;
        for(int i=0; i<total; i++)
        {
            cin>>a[i].h>>str>>a[i].m>>str>>a[i].s;
            a[i].order=i+1;
            a[i].flag=1;
        }
        sort(a,a+total,cmp);
        b[sum]=a[0].order;

        for(int i=1; i<total; i++)
            for(int j=i-1; j>=0; j--)
                if(a[j].flag==1)
                {
                    if(calculate(a[i],a[j]))
                        b[++sum]=a[i].order;
                    break;
                }
        cout<<sum<<endl;
        sort(b+1,b+sum+1);
        for(int j=1; j<sum; j++)
            cout<<b[j]<<" ";
        cout<<b[sum]<<endl;
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值