【Noip2006T3】作业调度方案 解题报告

【题面】

洛谷p1065

【思路】

显然这是一道模拟题
而且是很烦的模拟题
我的写法大概是这样:
对于当前所需要的机器
扫描一下它的状态
有满足流程的足够的空隙在最左的地方插空
否则往最右边插
插入的区间用两个变量表示 一个记录坐标,一个记录它是左端点还是右端点
排序是按照坐标排序
扫描时如果发现一个右端点到左端点之间的距离做够就插入
如果当前坐标小于满足当前工件的最小值就continue
初次之外还有一些实现上的细节
具体可以看我的代码
虽然没有注释
变量名比较清楚 大概

【代码】
#include
using namespace std;
struct buzhidao{
    int yi,er;
} zt[25][805];
bool cmp(buzhidao x,buzhidao y)
{
    if  (x.yi!=y.yi)
        return x.yi<y.yi;
    return x.er<y.er;
}
int shunxu[405],jiqi[25][25],shijian[25][25],gjs[25];
int xianzai[25],qs[25];
int main()
{
    memset(zt,0,sizeof(zt));
    int n,m;
    scanf("%d%d",&m,&n);
    int nm=n*m;
    for  (int i=1;i<=nm;i++)
        scanf("%d",&shunxu[i]);
    for  (int i=1;i<=n;i++)
        for  (int j=1;j<=m;j++)
            scanf("%d",&jiqi[i][j]);
    for  (int i=1;i<=n;i++)
        for  (int j=1;j<=m;j++)
            scanf("%d",&shijian[i][j]);
    for  (int i=1;i<=m;i++)
        zt[i][0].yi=0,zt[i][0].er=-1;
    for  (int i=1;i<=nm;i++)
        {
            int gongjian=shunxu[i];
            int j_=++xianzai[gongjian];
            int Shijian=shijian[gongjian][j_];
            int Jiqi=jiqi[gongjian][j_];
            if  (zt[Jiqi][gjs[Jiqi]].yi<qs[gongjian])
                {
                    zt[Jiqi][gjs[Jiqi]+1].yi=qs[gongjian];
                    zt[Jiqi][gjs[Jiqi]+1].er=1;
                    zt[Jiqi][gjs[Jiqi]+2].yi=qs[gongjian]+Shijian;
                    zt[Jiqi][gjs[Jiqi]+2].er=-1;
                    qs[gongjian]+=Shijian;
                    gjs[Jiqi]+=2;
                    continue;
                }
            bool f=true;
            for  (int j=0;j<gjs[Jiqi];j++)
                {
                    if  (zt[Jiqi][j].yi<qs[gongjian])	continue;
                    if  (zt[Jiqi][j].er==1)
                        {
                            if  (zt[Jiqi][j].yi-zt[Jiqi][j-1].yi>=Shijian&&zt[Jiqi][j].yi-Shijian>=qs[gongjian])
                                {
                                    if  (qs[gongjian]>=zt[Jiqi][j-1].yi)
                                    {
                                    f=false;
                                    zt[Jiqi][gjs[Jiqi]+1].yi=qs[gongjian];
                                    zt[Jiqi][gjs[Jiqi]+1].er=1;
                                    zt[Jiqi][gjs[Jiqi]+2].yi=qs[gongjian]+Shijian;
                                    zt[Jiqi][gjs[Jiqi]+2].er=-1;
                                    qs[gongjian]=qs[gongjian]+Shijian;
                                    gjs[Jiqi]+=2;
                                    sort(zt[Jiqi]+1,zt[Jiqi]+gjs[Jiqi]+1,cmp);
                                    break;
                                    }
                                    else
                                    {
                                    f=false;
                                    zt[Jiqi][gjs[Jiqi]+1].yi=zt[Jiqi][j-1].yi;
                                    zt[Jiqi][gjs[Jiqi]+1].er=1;
                                    zt[Jiqi][gjs[Jiqi]+2].yi=zt[Jiqi][j-1].yi+Shijian;
                                    zt[Jiqi][gjs[Jiqi]+2].er=-1;
                                    qs[gongjian]=zt[Jiqi][j-1].yi+Shijian;
                                    gjs[Jiqi]+=2;
                                    sort(zt[Jiqi]+1,zt[Jiqi]+gjs[Jiqi]+1,cmp);
                                    break;
                                    }
                                }
                            continue;
                        }
                    if  (zt[Jiqi][j+1].yi-zt[Jiqi][j].yi>=Shijian||zt[Jiqi][j+1].er==0)
                        {
                            f=false;
                            zt[Jiqi][gjs[Jiqi]+1].yi=zt[Jiqi][j].yi;
                            zt[Jiqi][gjs[Jiqi]+1].er=1;
                            zt[Jiqi][gjs[Jiqi]+2].yi=zt[Jiqi][j].yi+Shijian;
                            zt[Jiqi][gjs[Jiqi]+2].er=-1;
                            qs[gongjian]=zt[Jiqi][j].yi+Shijian;
                            gjs[Jiqi]+=2;
                            sort(zt[Jiqi]+1,zt[Jiqi]+gjs[Jiqi]+1,cmp);
                            break;
                        }
                }
            if  (f)
                {
                    zt[Jiqi][gjs[Jiqi]+1].yi=zt[Jiqi][gjs[Jiqi]].yi;
                    zt[Jiqi][gjs[Jiqi]+1].er=1;
                    zt[Jiqi][gjs[Jiqi]+2].yi=zt[Jiqi][gjs[Jiqi]].yi+Shijian;
                    zt[Jiqi][gjs[Jiqi]+2].er=-1;
                    qs[gongjian]=zt[Jiqi][gjs[Jiqi]].yi+Shijian;
                    gjs[Jiqi]+=2;
                }
        }
    int Ans=-1;
    for  (int i=1;i<=n;i++)
        if  (qs[i]>=Ans)
            Ans=qs[i];
    printf("%d",Ans);
    return 0;
}

你可能感兴趣的:(解题报告)