社区讨论
本地运行#6过,评测#6读出了A,求条玄关
P1529[USACO2.4] 回家 Bessie Come Home参与者 2已保存回复 3
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 3 条
- 当前快照
- 1 份
- 快照标识符
- @mhjdiiy3
- 此快照首次捕获于
- 2025/11/04 00:47 4 个月前
- 此快照最后确认于
- 2025/11/04 00:47 4 个月前
c++,玄关
以下是我的代码可能有点凌乱,但是拜托了大佬!
CPP以下是我的代码
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e3;
#define ll long long
const long long up=1e18;
ll n,m,dis[N][N];
ll cow[N],cw;
signed main() {
// freopen("P1529_6.in","r",stdin);
// freopen("1.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>m;
memset(dis,0x3f,sizeof(dis));
//for(int i=1; i<=60;i++) dis[i][i] = 0;
for(int i=1;i<=m;i++){
char x_,y_;
ll x,y,w;
cin>>x_>>y_>>w;
if(isupper(x_)&&x_!='Z'){
cow[++cw]=x_-'A'+1;
x=x_-'A'+1;
}
else if(x_=='Z'){
x=x_-'A'+1;
}
if(islower(x_)){
// cow[++cw]=x_-'a'+27;
x=x_-'a'+27;
}
if(isupper(y_)&&y_!='Z'){
cow[++cw]=y_-'A'+1;
y=y_-'A'+1;
}
else if(y_=='Z'){
y=y_-'A'+1;
}
if(islower(y_)){
// cow[++cw]=y_-'a'+27;
y=y_-'a'+27;
}
dis[x][y]=min(w,dis[x][y]);
dis[y][x]=min(w,dis[y][x]);
}
for(int k=1;k<=60;k++){
for(int i=1;i<=60;i++){
for(int j=1;j<=60;j++){
dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
}
}
}
char as;
ll mn=up,ww=0;
// cout<<mn;
for(int i=1;i<=cw;i++){
if(dis[cow[i]]['Z'-'A'+1]<mn){
mn=dis[cow[i]]['Z'-'A'+1];
ww=cow[i];
}
}
as=ww+'A'-1;
cout<<as<<" "<<mn;
return 0;
}
回复
共 3 条回复,欢迎继续交流。
正在加载回复...