版本比较
P9107 [PA2020] Wycieczka górska 题解
正文
增加 12 行删除 12 行
7 行未改动891011121213141516171617181920212223242425262728293030313233347 行未改动42434445464647484950505152535432 行未改动87888990919192939495969798991001001011021031042 行未改动10710810911011111111211311411512 行未改动1281291301311321321331341351361371381381391401417 行未改动
code:```cpp#include<bits/stdc++.h>#define int long long //不开long long见祖宗 #define int long long //不开long long见祖宗using namespace std;char mp[202][2002];bool flag[2002][2002];//方位数组 int fx[5]= {0,1,-1,0,0}; //方位数组int fx[5]= {0,1,-1,0,0};int fy[5]= {0,0,0,1,-1};int n,m,k;struct zt { int x,y,step;};queue<zt>q;int bfs(int a,int b) { //广搜 int bfs(int a,int b) { //广搜 int ans=11451419198101145; q.push({1,1,0}); while(!q.empty()) { zt now=q.front(); q.pop(); if(now.x==n&&now.y==m) { //边界 if(now.x==n&&now.y==m) { //边界 ans=min(ans,now.step); continue; } for(int i=1; i<=4; i++) {7 行未改动 q.push({tx,ty,now.step+b}); } } } memset(flag,0,sizeof(flag)); //多测要清空 memset(flag,0,sizeof(flag)); //多测要清空 return ans;}signed main() { //输入输出优化 //输入输出优化 ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); int ta,tb,cnt=1,ans=11451419198101145; cin>>n>>m>>k;32 行未改动int fy[5]= {0,0,0,1,-1};int n,m,k;struct zt { int x,y,up,down; bool operator <(const zt &a) const { //重载运算符,比较最短步数。当步数相同时,下山次数少的总时长更少 bool operator <(const zt &a) const { //重载运算符,比较最短步数。当步数相同时,下山次数少的总时长更少 if(a.up+a.down!=up+down) return up+down<a.up+a.down; else return up<a.up; }};queue<zt>q;signed main() { //输入输出优化 //输入输出优化 ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); int a,b,cnt=0,sum=114514191981011145,t; zt ans= {0,0,11451419198101145,11451419198101145};2 行未改动 for(int j=1; j<=m; j++) cin>>mp[i][j]; q.push({1,1,0,0}); flag[1][1]=1; while(!q.empty()) { //广搜 while(!q.empty()) { //广搜 zt now=q.front(); q.pop(); if(now.x==n&&now.y==m) { ans=min(ans,now);12 行未改动 } } for(int i=1; i<=k; i++) { cin>>a>>b; t=ans.up*a+ans.down*b; //计算用时 t=ans.up*a+ans.down*b; //计算用时 if(t<sum) sum=t,cnt=0; if(t==sum) cnt++; } cout<<sum<<' '<<cnt; cout<<sum<<' '<<cnt; return 0;}```