[Topic]
[thinking]
Obviously, this is a simulation problem
And it's a boring simulation
My writing is like this:
For the machine currently required
Scan its status
There is enough space to meet the process and insert it in the leftmost place
Otherwise, insert it to the far right
The inserted interval is represented by two variables: a record coordinate, a record whether it is the left end point or the right end point
Sort by coordinates
When scanning, if you find that the distance between a right end point and a left end point is enough, insert it
continue if the current coordinate is less than the minimum value of the current workpiece
There are some implementation details besides the first time
See my code for details
Although there is no comment
Variable name is clear about
[Code]
#include<bits/stdc++.h> 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; }