40求助
查看原帖
40求助
681103
huaji_huaji楼主2023/9/2 15:45
#include <bits/stdc++.h>
using namespace std;
inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();}
    while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    return x*f;
}
inline void write(int x){
    if(x<0){x=-x;putchar('-');}
    if(x>9)write(x/10);
    putchar(x%10+'0');
}
int n,m,r;
int a[101][101];
int ans=0;
inline void dfs(int x,int y,int step,int t){
    if(x<1||x>n||y<1||y>n||step==r+1)return;
    a[x][y]=1;
    if(t==1)dfs(x+1,y,step+1,t);
    if(t==2)dfs(x-1,y,step+1,t);
    if(t==3)dfs(x,y+1,step+1,t);
    if(t==4)dfs(x,y-1,step+1,t);
}
inline void work(int x,int y){
    for(int i=1;i<=4;i++)dfs(x,y,0,i);
}
int main(){
    n=read();m=read();r=read();
    while(m--)work(read(),read());
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(a[i][j])ans++;
        }
    }
    write(ans);
    
    return 0;
}
2023/9/2 15:45
加载中...