Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
终于过了。。。。。。。。。太感动了。。。。。。。。。(贴一下代码,虽然我已经看不懂了)#include<iostream> #include<queue> #include<math.h> #include<algorithm> using namespace std; struct R { int h; int m; int s; }room[20][20]; struct ele { int h; int m; int s; }elevator[20]; struct qu { int h; int m; int s; int status; int room; int man; int priority; qu(int a,int b,int c,int d,int e,int f,int g) { h=a; m=b; s=c; status=d; room=e; man=f; priority=g; } friend bool operator<(qu a,qu b) { if(a.h>b.h) { return true; } if(a.h<b.h) { return false; } if(a.m>b.m) { return true; } if(a.m<b.m) { return false; } if(a.s>b.s) { return true; } if(a.s<b.s) { return false; } if(a.priority>b.priority) { return true; } else { return false; } } }; struct one { int room; int time; }q2[30][1000]; struct p { int h1; int m1; int s1; int h2; int m2; int s2; int room1; int room2; int status; }q[30][10000]; struct sor { int num; int priority; friend bool cmp(struct sor a,struct sor b) { return a.priority<b.priority; } }; priority_queue<struct qu,vector<qu>>q1; void add(int &h,int &m,int &s,int length) { s+=length; if(s>=60) { m+=s/60; s=s%60; if(m>60) { h+=m/60; m=m%60; } } return; } void print1(int n,int leng) { int x=0; if(leng==2) { x=10; } else { x=1000; } if(n<x) { printf("0%d",n); } else { printf("%d",n); } return; } void print(int x,int n) { int i=0; for(i=0;i<n;i++) { print1(q[x][i].h1,2);printf(":");print1(q[x][i].m1,2);printf(":");print1(q[x][i].s1,2);printf(" "); print1(q[x][i].h2,2);printf(":");print1(q[x][i].m2,2);printf(":");print1(q[x][i].s2,2);printf(" "); switch(q[x][i].status) { case 0:printf("Entry\n");break; case 1:printf("Stay in room "); print1(q[x][i].room1,4);printf("\n");break; case 2:printf("Transfer from room "); print1(q[x][i].room2,4);printf(" to room ");print1(q[x][i].room1,4);printf("\n");break; case 3:printf("Transfer from room "); print1(q[x][i].room1,4);printf(" to elevator\n");break; case 4:printf("Stay in elevator\n");break; case 5:printf("Transfer from elevator to room ");print1(q[x][i].room1,4);printf("\n");break; case 6:printf("Waiting in front of room ");print1(q[x][i].room1,4);printf("\n");break; case 7:printf("Waiting in elevator queue\n");break; case 8:printf("Exit\n"); } } return ; } void transfer(int man,int nroom[],int length[],int &h,int &m,int &s) { q[man][length[man]].h1=h; q[man][length[man]].m1=m; q[man][length[man]].s1=s; q[man][length[man]].h2=q[man][length[man]].h1; q[man][length[man]].m2=q[man][length[man]].m1; q[man][length[man]].s2=q[man][length[man]].s1; add(q[man][length[man]].h2,q[man][length[man]].m2,q[man][length[man]].s2,10); q[man][length[man]].room1=q1.top().room; q[man][length[man]].room2=nroom[man]; nroom[man]=q1.top().room; q[man][length[man]].status=2; h=q[man][length[man]].h2; m=q[man][length[man]].m2; s=q[man][length[man]].s2; length[man]++; return ; } void inroom(int man,int ha1,int ha2,int nroom[],int length[],int now[],int len[],int h,int m,int s) { q[man][length[man]].h1=h; q[man][length[man]].m1=m; q[man][length[man]].s1=s; q[man][length[man]].h2=q[man][length[man]].h1; q[man][length[man]].m2=q[man][length[man]].m1; q[man][length[man]].s2=q[man][length[man]].s1; add(q[man][length[man]].h2,q[man][length[man]].m2,q[man][length[man]].s2,q2[man][now[man]++].time); q[man][length[man]].room1=q1.top().room; q[man][length[man]].status=1; room[ha1][ha2].h=q[man][length[man]].h2; room[ha1][ha2].m=q[man][length[man]].m2; room[ha1][ha2].s=q[man][length[man]].s2; nroom[man]=q1.top().room; if(now[man]<len[man]) { q1.push(qu(q[man][length[man]].h2,q[man][length[man]].m2,q[man][length[man]].s2,1,q2[man][now[man]].room,man,q1.top().priority)); } else { q1.push(qu(q[man][length[man]].h2,q[man][length[man]].m2,q[man][length[man]].s2,5,q1.top().room,q1.top().man,q1.top().priority)); } length[man]++; return; } void transfere(int man,int length[],int ha1,int ha2,int &h,int &m,int &s) { q[man][length[man]].h1=h; q[man][length[man]].m1=m; q[man][length[man]].s1=s; q[man][length[man]].h2=q[man][length[man]].h1; q[man][length[man]].m2=q[man][length[man]].m1; q[man][length[man]].s2=q[man][length[man]].s1; add(q[man][length[man]].h2,q[man][length[man]].m2,q[man][length[man]].s2,30*abs(ha1-ha2)); elevator[ha1].h=h; elevator[ha1].m=m; elevator[ha1].s=s; h=q[man][length[man]].h2; m=q[man][length[man]].m2; s=q[man][length[man]].s2; q[man][length[man]].status=4; length[man]++; return ; } void waite1(int man,int length[],int &h,int &m,int &s) { q[man][length[man]].h1=h; q[man][length[man]].m1=m; q[man][length[man]].s1=s; q[man][length[man]].status=7; return ; } void waite2(int man,int ha1,int length[],int &h,int &m,int &s) { q[man][length[man]].h2=h; q[man][length[man]].m2=m; q[man][length[man]].s2=s; elevator[ha1].h=h; elevator[ha1].m=m; elevator[ha1].s=s; length[man]++; return; } void rtoe(int man,int length[],int room,int &h,int &m,int &s) { q[man][length[man]].h1=h; q[man][length[man]].m1=m; q[man][length[man]].s1=s; q[man][length[man]].h2=q[man][length[man]].h1; q[man][length[man]].m2=q[man][length[man]].m1; q[man][length[man]].s2=q[man][length[man]].s1; add(q[man][length[man]].h2,q[man][length[man]].m2,q[man][length[man]].s2,10); h=q[man][length[man]].h2; m=q[man][length[man]].m2; s=q[man][length[man]].s2; q[man][length[man]].room1=room; q[man][length[man]].status=3; length[man]++; return ; } void etor(int man,int length[],int &h,int &m,int &s,int room) { q[man][length[man]].h1=h; q[man][length[man]].m1=m; q[man][length[man]].s1=s; q[man][length[man]].h2=q[man][length[man]].h1; q[man][length[man]].m2=q[man][length[man]].m1; q[man][length[man]].s2=q[man][length[man]].s1; add(q[man][length[man]].h2,q[man][length[man]].m2,q[man][length[man]].s2,10); h=q[man][length[man]].h2; m=q[man][length[man]].m2; s=q[man][length[man]].s2; q[man][length[man]].room1=room; q[man][length[man]].status=5; length[man]++; return ; } void waitr1(int man,int length[],int &h,int &m,int &s,int room) { q[man][length[man]].h1=h; q[man][length[man]].m1=m; q[man][length[man]].s1=s; q[man][length[man]].status=6; q[man][length[man]].room1=room; return ; } void waitr2(int man,int length[],int &h,int &m,int &s) { q[man][length[man]].h2=h; q[man][length[man]].m2=m; q[man][length[man]].s2=s; length[man]++; return; } void Exit(int man,int length[],int &h,int &m,int &s) { q[man][length[man]].h1=h; q[man][length[man]].m1=m; q[man][length[man]].s1=s; q[man][length[man]].h2=q[man][length[man]].h1; q[man][length[man]].m2=q[man][length[man]].m1; q[man][length[man]].s2=q[man][length[man]].s1; add(q[man][length[man]].h2,q[man][length[man]].m2,q[man][length[man]].s2,30); h=q[man][length[man]].h2; m=q[man][length[man]].m2; s=q[man][length[man]].s2; q[man][length[man]].status=8; length[man]++; return ; } int main() { int i=0,n=0,h,m,s; char man1[30]={0}; int length[30]={0}; int now[30]={0}; int len[30]={0}; int time[3]={0}; int nroom[30]={0}; //freopen("1.txt","w",stdout); while(scanf("%c",&man1[n])&&man1[n]!='.') { scanf("%d:%d:%d\n",&h,&m,&s); time[0]=h;time[1]=m;time[2]=s; add(time[0],time[1],time[2],30); q[n][0].h1=h;q[n][0].m1=m;q[n][0].s1=s;q[n][0].h2=time[0],q[n][0].m2=time[1],q[n][0].s2=time[2];length[n]++; while(scanf("%d",&h)&&h) { scanf("%d",&m); q2[n][len[n]].room=h; q2[n][len[n]++].time=m; } getchar(); nroom[n]=100+q2[n][0].room%100; if(len[n]) { q1.push(qu(time[0],time[1],time[2],1,q2[n][0].room,n,man1[n]-'A')); } n++; } while(!q1.empty()) { int ha1=q1.top().room/100,ha2=q1.top().room%100,man=q1.top().man;h=q1.top().h;m=q1.top().m;s=q1.top().s; switch(q1.top().status) { case 1: if(ha1!=nroom[man]/100) { q1.push(qu(q1.top().h,q1.top().m,q1.top().s,2,q1.top().room,q1.top().man,q1.top().priority)); q1.pop(); break; } if(q1.top().room!=nroom[man]) { transfer(man,nroom,length,h,m,s); } if(room[ha1][ha2].h<h||(room[ha1][ha2].h==h&&room[ha1][ha2].m<m)||(room[ha1][ha2].h==h&&room[ha1][ha2].m==m&&room[ha1][ha2].s<=s)) { inroom(man,ha1,ha2,nroom,length,now,len,h,m,s); } else { waitr1(man,length,h,m,s,q1.top().room); q1.push(qu(room[ha1][ha2].h,room[ha1][ha2].m,room[ha1][ha2].s,3,q1.top().room,q1.top().man,q1.top().priority)); } q1.pop(); break; case 2: if(length[man]!=1) { rtoe(man,length,nroom[man],h,m,s); } if((elevator[nroom[man]/100].h!=h||elevator[nroom[man]/100].m!=m||elevator[nroom[man]/100].s!=s)&&q1.top().s%5==0) { transfere(man,length,nroom[man]/100,ha1,h,m,s); etor(man,length,h,m,s,q1.top().room); nroom[man]=q1.top().room; q1.push(qu(h,m,s,1,q1.top().room,q1.top().man,q1.top().priority)); } else { waite1(man,length,h,m,s); int k=5-s%5; add(h,m,s,k); q1.push(qu(h,m,s,4,q1.top().room,q1.top().man,q1.top().priority)); } q1.pop(); break; case 3: if(room[ha1][ha2].h<h||(room[ha1][ha2].h==h&&room[ha1][ha2].m<m)||(room[ha1][ha2].h==h&&room[ha1][ha2].m==m&&room[ha1][ha2].s<=s)) { waitr2(man,length,h,m,s); inroom(man,ha1,ha2,nroom,length,now,len,h,m,s); } else { q1.push(qu(room[ha1][ha2].h,room[ha1][ha2].m,room[ha1][ha2].s,3,q1.top().room,q1.top().man,q1.top().priority)); } q1.pop(); break; case 4: if((elevator[nroom[man]/100].h!=h||elevator[nroom[man]/100].m!=m||elevator[nroom[man]/100].s!=s)) { waite2(man,nroom[man]/100,length,h,m,s); transfere(man,length,nroom[man]/100,ha1,h,m,s); etor(man,length,h,m,s,q1.top().room); nroom[man]=q1.top().room; q1.push(qu(h,m,s,1,nroom[man],q1.top().man,q1.top().priority)); } else { add(h,m,s,5); q1.push(qu(h,m,s,4,q1.top().room,q1.top().man,q1.top().priority)); } q1.pop(); break; case 5: if(ha1!=01) { rtoe(man,length,nroom[man],h,m,s); q1.push(qu(h,m,s,6,q1.top().room,q1.top().man,q1.top().priority)); q1.pop(); break; } else { Exit(man,length,h,m,s); q1.pop(); } break; case 6: if((elevator[nroom[man]/100].h!=h||elevator[nroom[man]/100].m!=m||elevator[nroom[man]/100].s!=s)&&q1.top().s%5==0) { transfere(man,length,1,ha1,h,m,s); q1.push(qu(h,m,s,5,100,q1.top().man,q1.top().priority)); } else { waite1(man,length,h,m,s); int k=5-s%5; add(h,m,s,k); q1.push(qu(h,m,s,7,0100,q1.top().man,q1.top().priority)); } q1.pop(); break; case 7: waitr2(man,length,h,m,s); transfere(man,length,1,nroom[man]/100,h,m,s); Exit(man,length,h,m,s); q1.pop(); } } struct sor sort1[30]; for(i=0;i<n;i++) { sort1[i].priority=man1[i]-'A'; sort1[i].num=i; } sort(sort1,sort1+n,cmp); for(i=0;i<n;i++) { printf("%c\n",man1[sort1[i].num]); print(sort1[i].num,length[sort1[i].num]); printf("\n"); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator