编译没过wa---玄关求调

P2895 [USACO08FEB] Meteor Shower S

lucy2012 @ 2024-04-17 20:33:09

#include<bits/stdc++.h>
using namespace std;
struct where{
    int x,y;
};
queue<where> q;
int sum[310][310],when[310][310];
int d[4][2]={{0,1},{1,0},{-1,0},{0,-1}};
void minn(int a,int b,int c){
    if(a>=0&&b>=0)
        when[a][b]=min(when[a][b],c);
}
int main(){
    int m,ans=100000;
    memset(sum,-1,sizeof(sum));
    memset(when,0x7f,sizeof(when));
    cin>>m;
    for(int i=1;i<=m;i++){
        int x,y,t;
        cin>>x>>y>>t;
        min(x,y,t);
        for(int k=0;k<4;k++)
            min(x+d[k][0],y+d[k][1],t);
    }
    q.push((where){0,0});
    sum[0][0]=0;
    while(!q.empty()){
        where u=q.front();
        int ux=u.x,uy=u.y;
        q.pop();
        for(int k=0;k<4;k++){
            int x1=ux+d[k][0],y1=uy+d[k][1];
            if(x1<0||y1<0||sum[x1][y1]!=-1||sum[ux][uy]+1>=when[x1][y1])
                continue;
            sum[x1][y1]=sum[ux][uy]+1;
            where wh={x1,y1};
            q.push(wh);
        }
    }
    for(int i=0;i<=305;i++){
        for(int j=0;j<=305;j++){
            if(sum[i][j]>1000&&sum[i][j]!=-1)
                ans=min(ans,sum[i][j]);
        }
    }
    if(ans==100000)
        cout<<-1;
    else
        cout<<ans;
    return 0;
}

by I_Love_DS @ 2024-04-17 20:51:20

#include<bits/stdc++.h>
using namespace std;
struct where{
    int x,y;
};
queue<where> q;
int sum[310][310],when[310][310];
int d[4][2]={{0,1},{1,0},{-1,0},{0,-1}};
void minn(int a,int b,int c){
    if(a>=0&&b>=0)
        when[a][b]=min(when[a][b],c);
}
int main(){
    int m,ans=100000;
    memset(sum,-1,sizeof(sum));
    memset(when,0x7f,sizeof(when));
    cin>>m;
    for(int i=1;i<=m;i++){
        int x,y,t;
        cin>>x>>y>>t;
        min(x,y,t);//minn(x,y,t);
        for(int k=0;k<4;k++)
            min(x+d[k][0],y+d[k][1],t);//minn(x+d[k][0],y+d[k][1],t);
    }
    q.push((where){0,0});
    sum[0][0]=0;
    while(!q.empty()){
        where u=q.front();
        int ux=u.x,uy=u.y;
        q.pop();
        for(int k=0;k<4;k++){
            int x1=ux+d[k][0],y1=uy+d[k][1];
            if(x1<0||y1<0||sum[x1][y1]!=-1||sum[ux][uy]+1>=when[x1][y1])
                continue;
            sum[x1][y1]=sum[ux][uy]+1;
            where wh={x1,y1};
            q.push(wh);
        }
    }
    for(int i=0;i<=305;i++){
        for(int j=0;j<=305;j++){
            if(sum[i][j]>1000&&sum[i][j]!=-1)
                ans=min(ans,sum[i][j]);
        }
    }
    if(ans==100000)
        cout<<-1;
    else
        cout<<ans;
    return 0;
}

加注释的地方是你忘加了一个 n

温馨提示:库里的 min() 函数是两个形参。


by I_Love_DS @ 2024-04-17 20:52:41

@LzxQwQ

你得审题(


by lucy2012 @ 2024-04-17 20:53:36

@liuruiqing 也谢谢你啦(虽然我找到了并且我还是错了


by lucy2012 @ 2024-04-17 20:54:13

@LzxQwQ 也谢谢你了!(以关


by lucy2012 @ 2024-04-17 20:55:26

@liuruiqing 我好像早早的关注你了ya~


by I_Love_DS @ 2024-04-17 20:56:37

@lucy2012 建议你以后防手滑多看几眼自己的代码,否则 NOI 竞赛代码 200 行你根本找不到错在哪,那时候你就急了


by lucy2012 @ 2024-04-17 21:00:13

@liuruiqing 懂了!嗯嗯!


上一页 |