SGU 477 doors

477. Doors
Time limit per test: 1.5 second(s)
Memory limit: 65536 kilobytes
input: standard
output: standard



It seems that the Museum of the Modern Technology is the only place where they don't celebrate Halloween! How can they be so far from all the mistical and mysterious? You can hardly believe that two weeks ago the Museum staff have destroyed the last detail that could bring with its ominous creak a bit of Halloween atmosphere to the realm of technology. They have replaced the old wooden doors with new automatic ones, and now they are scratching their heads over how to configure the doors. 

By the order of the Director, two automatic doors were purchased. An automatic door is characterized by parameter t, called the , which can be set to an integer value from 1 to 109 during the door installation. Then the door functions on the following principle. If a person passes through the door at time p, the door opens at time p - t and closes at time p + t. There is an exceptional case when several people go in a row with a time interval not exceeding 2 t between any two consecutive people. In this case the door opens only once, t seconds before the first person in the row, and it closes t seconds after the last person in the row has passed through it. It is very important to set the optimal values of the door parameters. On the one hand, if the doors open and close too often, it will annoy visitors. On the other hand, if both doors stay opened for a long time, visitors can get cold.

More formally, two lists of time moments are given. At the moments p1 < p2 <... < pn people have passed through the first door, and at the moments q1 < q2 <... < qm people have passed through the second one. The task is to use the given statistics to find the optimal  for the doors — t1 for the first door and t2 for the second one that satisfy the following conditions:

  • The total number of openings of the doors must be minimal possible.
  • There is no continuous interval of time that both doors are opened during this interval and its length exceeds the given value d

    Input
    The first line of the input contains three integers nm and d (1 ≤ nm ≤ 5000, 1 ≤ d ≤ 109). The second line contains numbers pi, and the third line contains numbers qi, given in the ascending order (1 ≤ piqi ≤ 109).

    Output
    Output two integers t1 and t2, separated by a single space. If there are multiple solutions, output any. If there is no solution, output "
    No solution
    ". 

    Example(s)
    sample input
    sample output
    3 2 4
    1 6 13
    7 11
    
    3 2
    


    题意:两个门分别设定t1,t2两个值,使得满足某些条件。

    题解:首先,门的t值的一定为1或者(相邻两个间隔+1) /2。那么窝们可以枚举。但是判断两个门的公共时间是最少是o(n)的,那么如果n^2枚举坑定会跪。那么仔细一看其实o(n)枚举,给出源代码。

    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<string>
    #include<algorithm>
    #include<iostream>
    #include<vector>
    #include<queue>
    #include<map>
    #include<set>
    #include<stack>
    
    #define msn(x) (memset((x),0,sizeof((x))))
    #define msx(x) (memset((x),0x7f,sizeof((x))))
    #define fuck(x) cerr << #x << " <- " << x << endl
    #define acer cout<<"sb"<<endl
    typedef int ll;
    using namespace std;
    int n,m,d;
    const int maxn=5003;
    int p[maxn],q[maxn];
    vector<int>cmp,cmq;
    struct node
    {
        ll a,b;
    };
    vector<node>t,s;
    node g;
    int ansa,ansb,ans;
    node mp(ll a,ll b)
    {
        node re;
        re.a=a,re.b=b;
        return re;
    }
    void pre1(int w)
    {
        s.clear();
        for(int i=0;i<n;i++)
        {
            ll beg=p[i]-w;
            while(i+1<n&&p[i+1]-2*w<=p[i])i++;
            ll fin=p[i]+w;
            s.push_back(mp(beg,fin));
        }
    }
    void pre2(int w)
    {
        t.clear();
        for(int i=0;i<m;i++)
        {
            ll beg=q[i]-w;
            while(i+1<m&&q[i+1]-2*w<=q[i])i++;
            ll fin=q[i]+w;
            t.push_back(mp(beg,fin));
        }
    }
    
    inline ll getintersection(node &a,node &b)
    {
        ll minn=max(a.a,b.a);
        ll maxx=min(a.b,b.b);
        return max(0,maxx-minn);
    }
    bool solve(int a,int b)
    {
        pre2(cmq[b]);
        int j=0;
        for(int i=0;i<s.size();i++)
        {
           g=s[i];
           while(j<t.size())
           {
               ll ans=getintersection(g,t[j]);
               if(ans>d)return 0;
               if(j==t.size()-1||s[i].b<t[j].b)break;
               j++;
           }
        }
        if(s.size()+t.size()<ans)
        {
            ansa=cmp[a];
            ansb=cmq[b];
            ans=s.size()+t.size();
        }
        return 1;
    }
    int main()
    {
        scanf("%d %d %d",&n,&m,&d);
        ans=10000000;
        for(int i=0;i<n;i++)
        {
            scanf("%d",&p[i]);
        }
        for(int i=0;i<m;i++)
        {
            scanf("%d",&q[i]);
        }
        for(int i=0;i+1<n;i++)
        {
            cmp.push_back((p[i+1]+1-p[i])/2);
        }
        for(int i=0;i+1<m;i++)
        {
            cmq.push_back((q[i+1]+1-q[i])/2);
        }
        cmp.push_back(1);
        cmq.push_back(1);
        sort(cmp.begin(),cmp.end());
        cmp.erase(unique(cmp.begin(),cmp.end()),cmp.end());
        sort(cmq.begin(),cmq.end());
        cmq.erase(unique(cmq.begin(),cmq.end()),cmq.end());
        pre1(1);pre2(1);
        if(!solve(0,0))
        {
            printf("No solution\n");
            return 0;
        }
        int sz=cmq.size()-1;
        for(int i=0;i<cmp.size();i++)
        {
            pre1(cmp[i]);
            while(sz>=0&&!solve(i,sz))sz--;
            if(sz<0)break;
        }
        printf("%d %d\n",ansa,ansb);
        return 0;
    }
    


标题基于SpringBoot的马术俱乐部管理系统设计与实现AI更换标题第1章引言介绍马术俱乐部管理系统的研究背景、意义、国内外研究现状、论文方法及创新点。1.1研究背景与意义阐述马术俱乐部管理系统对提升俱乐部管理效率的重要性。1.2国内外研究现状分析国内外马术俱乐部管理系统的发展现状及存在的问题。1.3研究方法以及创新点概述本文采用的研究方法,包括SpringBoot框架的应用,以及系统的创新点。第2章相关理论总结和评述与马术俱乐部管理系统相关的现有理论。2.1SpringBoot框架理论介绍SpringBoot框架的基本原理、特点及其在Web开发中的应用。2.2数据库设计理论阐述数据库设计的基本原则、方法以及在管理系统中的应用。2.3马术俱乐部管理理论概述马术俱乐部管理的基本理论,包括会员管理、课程安排等。第3章系统设计详细描述马术俱乐部管理系统的设计方案,包括架构设计、功能模块设计等。3.1系统架构设计给出系统的整体架构,包括前端、后端和数据库的交互方式。3.2功能模块设计详细介绍系统的各个功能模块,如会员管理、课程管理、预约管理等。3.3数据库设计阐述数据库的设计方案,包括表结构、字段设计以及数据关系。第4章系统实现介绍马术俱乐部管理系统的实现过程,包括开发环境、编码实现等。4.1开发环境搭建介绍系统开发所需的环境,包括操作系统、开发工具等。4.2编码实现详细介绍系统各个功能模块的编码实现过程。4.3系统测试与调试阐述系统的测试方法、测试用例以及调试过程。第5章系统应用与分析呈现马术俱乐部管理系统的应用效果,并进行性能分析。5.1系统应用情况介绍系统在马术俱乐部中的实际应用情况。5.2系统性能分析从响应时间、并发处理能力等方面对系统性能进行分析。5.3用户反馈与改进收集用户反馈,提出系统改进建议。第6章结论与展望总结马术俱乐部管理系统的设计与实现成果,并展望未来的研究
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值