hdoj1571

痛定思痛。 2021-11-22 08:54 157阅读 0赞

下沙小面的(1)

ExpandedBlockStart.gif 代码

#include < iostream >
#include < stdio.h >
#include < string .h >
using namespace std;
int NCity, T, dist[ 30 ][ 30 ], K, pn, ans, P[ 7 ], now; // dist距离,pn人数,now现在的车站
int main()
{
while (scanf( “ %d “ , & NCity) != EOF && NCity) {
pn = 0 , now = 0 , ans = 0 ;
for ( int i = 0 ; i < NCity; ++ i)
for ( int j = 0 ; j < NCity; ++ j)
scanf( “ %d “ , & dist[i][j]);
scanf( “ %d “ , & K);
char ch1, ch2;
while (K -- ) {
cin >> ch1 >> ch2;
if (ch1 == ‘ U ‘ ) { // 有人上车
scanf( “ %d “ , & T);
if (pn == 7 || T == now)
continue ; // 人満
P[pn] = T;
pn ++ ;
} else { // 开车
if (pn == 0 )
continue ;
ans += dist[now][P[ 0 ]];
now = P[ 0 ];
int tem[ 7 ];
int ptem = 0 ;
for ( int pos = 0 ; pos < pn; ++ pos) {
if (P[pos] == now) {
continue ;
}
tem[ptem ++ ] = P[pos];
}
for ( int pos = 0 ; pos < ptem; ++ pos)
P[pos] = tem[pos];
pn = ptem;
}
}
printf( “ %d\n “ , ans);
}
}

转载于:https://www.cnblogs.com/Open\_Source/archive/2010/05/09/1904954.html

发表评论

表情:
评论列表 (有 0 条评论,157人围观)

还没有评论,来说两句吧...

相关阅读