#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<math.h>
#include<iostream>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre(){freopen("c://test//input.in","r",stdin);freopen("c://test//output.out","w",stdout);}
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1,class T2>inline void gmax(T1 &a,T2 b){if(b>a)a=b;}
template <class T1,class T2>inline void gmin(T1 &a,T2 b){if(b<a)a=b;}
const int N=0,M=0,Z=1e9+7,ms63=1061109567;
int casenum,casei;
int n,m;
int a[30][30];
int q[100000];
int main()
{
while(scanf("%d",&n),n)
{
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)scanf("%d",&a[i][j]);
}
int pos=0;
int h=0,t=0;
int dis=0;
scanf("%d",&m);
while(m--)
{
char s[3];
scanf("%s",s);
if(s[0]=='U')
{
int aim;
scanf("%d",&aim);
if(t-h<7&&aim!=pos)q[t++]=aim;
}
else if(h<t)
{
dis+=a[pos][q[h]];
pos=q[h++];
for(int i=h;i<t;i++)while(i<t&&q[i]==pos)
{
--t;
for(int j=i;j<t;j++)q[j]=q[j+1];
}
}
}
printf("%d\n",dis);
}
return 0;
}
/*
【trick&&吐槽】
本来是一道简单的模拟题,然而我却错了很多次。
所以说做模拟题一定要多读题,理清思路,确保正确性。
1,"每次送人的时候,送最早上车的人,如果车上还有人拥有相同的目的地,那么会一起下车"
2,座位7个,!不!包括驾驶座>_<!我真是瞎了眼哦!
【题意】
有n(30)个地点0base。
然后给你一个矩阵,表示任意两点的距离
然后有m条指令,指令包括UP aim和GO
分别表示,当前位置有一个人上车,要到aim点下车
以及我们现在要去送最早上车的人到其目的地。
有一些规则
1,如果本来就在这个地点而且还要去这个地点,就不送了。
2,最多接纳6个乘客。
3,每次送人的时候,送最早上车的人。
4,如果到达一个地点,车上还有人拥有相同目的地的人会一起下车。
5,如果车上没有乘客却又GO指令,则忽略该指令
【类型】
模拟
【分析】
按照送人规则3,我们想要采取队列。
然而按照送人规则4,我们发现这个队列的维护还要特殊处理一下
【时间复杂度&&优化】
【数据】
3
0 1 100
1 0 100
100 100 0
10
UP 1
UP 2
UP 1
UP 1
UP 2
UP 0
UP 2
GO
GO
GO
*/
【HDU1571】【有删除操作的队列模拟】下沙小面的(1)
最新推荐文章于 2020-06-28 16:34:59 发布