| ||||||||||
| 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 <cstdio>
#include <string.h>
#include <vector>
using namespace std;
inline int abs(int a) {return a>0?a:(-a);}
struct place {int floor,room,time;};
struct time {int h,m,s;}
struct sche {int code,time;place a,b;};
struct user
{
int pri;
time start;
vector<place> l;
queue<sche> S;
}U[30];
int L;
void Input()
{
char buf[10];
int h,m,s,t;
while(scanf("%s",buf),(buf[0]!='.')) {
U[L].pri=buf[0]-'A';
scanf("%d:%d:%d",&U[L].start.h,&U[L].start.m,&U[L].start.s);
while(scanf("%s",buf)) {
if(strlen(buf)==1 && buf[0]=='0') break;
scanf("%d",t);
place tmp;
tmp.floor=(buf[0]-'0')*10+buf[1]-'0';
tmp.room=(buf[2]-'0')*10+buf[3]-'0';
tmp.time=t;
U[L].l.push_back(tmp);
}
L++;
}
}
sche tmp;
place Room_to_Room(int u,place last,place now) {
tmp.code=1;tmp.a.floor=tmp.b.floor=last.floor;
tmp.a.room=last.room;tmp.b.room=now.room;tmp.time=10;
U[u].S.push(tmp);
return tmp.b;
}
place Room_to_Elevater(int u,place last,place now) {
tmp.code=2;tmp.a.floor=tmp.b.floor=last.floor;
tmp.a.room=last.room;tmp.b.room=0;tmp.time=10;
U[u].S.push(tmp);
return tmp.b;
}
place Elevater_to_Room(int u,place last,place now) {
tmp.code=3;tmp.a.floor=tmp.b.floor=now.floor;
tmp.a.room=0;tmp.b.room=now.room;tmp.time=10;
U[u].S.push(tmp);
return tmp.b;
}
place Floor_to_Floor(int u,place last,place now) {
tmp.code=4;tmp.a.floor=last.floor;tmp.b.floor=now.floor;
tmp.a.room=0;tmp.b.room=0;tmp.time=30*abs(last.floor-now.floor);
U[u].S.push(tmp);
return tmp.b;
}
place Wait_Elevater_queue(int u,place last,place now) {
tmp.code=5;tmp.a.floor=tmp.b.floor=now.floor;
tmp.a.room=0;tmp.b.room=0;tmp.time=-1;
U[u].S.push(tmp);
return tmp.b;
}
place Wait_Room_queue(int u,place last,place now) {
tmp.code=6;tmp.a.floor=tmp.b.floor=now.floor;
tmp.a.room=tmp.b.room=now.room;tmp.time=-1;
U[u].S.push(tmp);
return tmp.b;
}
place IN_Room(int u,place last,place now) {
tmp.code=7;tmp.a.floor=tmp.b.floor=now.floor;
tmp.a.room=tmp.b.room=now.room;tmp.time=now.time;
U[u].S.push(tmp);
return tmp.b;
}
void Exit(int u,place last) {
if(last.floor==1) {
tmp.code=8;tmp.a.floor=1;tmp.b.floor=0;
tmp.a.room=last.room;tmp.b.room=0;tmp.time=30;
U[u].S.push(tmp);
}else {
last=Room_to_Elevater(u,last,last);
place exit;
exit.floor=1;exit.room=0;
last=Floor_to_Floor(u,last,exit);
tmp.code=8;tmp.a.floor=1;tmp.b.floor=0;
tmp.a.room=0;tmp.b.room=0;tmp.time=30;
U[u].S.push(tmp);
}
}
void Init()
{
/*
0 Entry
1 Room to Room
2 Room to Elevater
3 Elevater to Room
4 Floor to Floor (IN Elevater)
5 Wait Elevater queue
6 Wait Room queue
7 IN Room
8 Exit
*/
for(int i=0;i<L;i++) {
tmp.code=0;tmp.a.floor=tmp.a.room=0;tmp.b.floor=1;tmp.room=0;tmp.time=30;
U[i].S.push(tmp);
place last=tmp.b;
if(U[i].l[0].floor==1) {
last=Room_to_Room(i,last,U[i].l[0]);
last=Wait_Room_queue(i,U[i].l[0],U[i].l[0]);
last=IN_Room(i,U[i].l[0],U[i].l[0]);
}else {
last=Wait_Elevater_queue(i,last,last);
last=Floor_to_Floor(i,last,U[i].l[0]);
last=Elevater_to_Room(i,last,U[i].l[0]);
last=Wait_Room_queue(i,U[i].l[0],U[i].l[0]);
last=IN_Room(i,U[i].l[0],U[i].l[0]);
}
for(int j=1;j<U[i].l.size();j++) {
if(U[i].l[j].floor==last.floor) {
last=Room_to_Room(i,last,U[i].l[j]);
last=Wait_Room_queue(i,U[i].l[j],U[i].l[j]);
last=IN_Room(i,U[i].l[j],U[i].l[j]);
}else {
last=Room_to_Elevater(i,U[i].l[j],U[i].l[j]);
last=Wait_Elevater_queue(i,last,last);
last=Floor_to_Floor(i,last,U[i].l[j]);
last=Elevater_to_Room(i,last,U[i].l[j]);
last=Wait_Room_queue(i,U[i].l[j],U[i].l[j]);
last=IN_Room(i,U[i].l[j],U[i].l[j]);
}
}
Exit(i,last);
}
}
sche A[30];
bool State[30];
void Calc()
{
int timezone=0;
while(1) {
for(int i=0;i<L;i++) if(!State[i]){
if(!U[i].S.empty()) {
A[i]=U[i].S.front();
U[i].S.pop();
}
}
for(int i=0;i<L;i++) if(!State[i]){
}else {
}
}
}
int main()
{
Input();
Init();
Calc();
Output();
getchar();getchar();
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator