P2771 求助
  • 板块学术版
  • 楼主P_H_I_G_R_O_S
  • 当前回复0
  • 已保存回复0
  • 发布时间2022/8/15 15:20
  • 上次更新2023/10/27 15:19:07
查看原帖
P2771 求助
655280
P_H_I_G_R_O_S楼主2022/8/15 15:20

RT,除去#2都是WA,有没有dalao帮忙看一下?

P2771 题目传送

#include<iostream>
#include<cstring>
#include<algorithm>

using namespace std;

int map[2080][2080];
bool map_vis[2080][2080],road[2080][2080];

int x=1040,y=1040,lastx=1040,lasty=1040,ans=0;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

const char s[]={'N','E','S','W'};

int main(){
	memset(map,0,sizeof(map));
	memset(map_vis,false,sizeof(map_vis));
	int n,num=1;
	scanf("%d",&n);
	map_vis[1040][1040]=true;
	map[1040][1040]=1;
	
	for(int i=1;i<=n;++i){
		
		char c=getchar();
		
		for(int j=0;j<4;++j)
			if(c==s[j]){x+=dx[j],y+=dy[j]; break ;}
			
			if(!map_vis[x][y]) map[x][y]=num++;
			
			int last=map[lastx][lasty];
			int now=map[x][y];
			
			if(!road[last][now] && map_vis[x][y]) ans++;
			
			road[now][last]=road[last][now]=true;
			
			lastx=x,lasty=y,map_vis[x][y]=true;
	}
	printf("%d",ans);
	
	return 0;
}
2022/8/15 15:20
加载中...