QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#141375#6534. Peg Solitairecy1999Compile Error//C++1.3kb2023-08-17 11:15:342023-08-17 11:15:36

Judging History

你现在查看的是最新测评结果

  • [2023-08-17 11:15:36]
  • 评测
  • [2023-08-17 11:15:34]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
	
int const maxn = 15;
int dx[4] ={1,0,-1,0};
int dy[4] ={0,1,0,-1};
struct node{
	int x,y,vis;
}p[maxn];

map<int ,map<int ,int> >mp;


int n,m,k;



bool check(int a,int b,int c,int d){
	return a>=1&&a<=n&&b>=1&&b<=n&&c>=1&&c<=m&&d>=1&&d<=m;
}


int dfs(int cnt){
	int tmk = cnt;
	for(int i = 1;i <= k;i ++){
		int x = p[i].x,y = p[i].y;
		if(p[i].vis)continue;
		for(int j = 0;j < 4;j ++){
			int tx = x + dx[j],ty = y + dy[j];
			int px = tx + dx[j],py = ty + dy[j];
			if(!check(tx,px,ty,py)||(!mp[tx][ty])||(mp[px][py]))continue;
		    int tmp = mp[tx][ty];
		    p[i].x = px,p[i].y= py;
		    p[tmp].vis = 1;
		    mp[x][y] = 0;
		    mp[px][py] = i;
		    mp[tx][ty] = 0;
		   
			tmk = min(tmk,dfs(cnt - 1));
			mp[tx][ty] = tmp;
			mp[px][py] = 0;
			p[i].x = x,p[i].y= y;
			p[tmp].vis = 0;
			mp[x][y] = i;
			
		}
	}
    return tmk;
}

int main(){
	int t;
	cin >> t;
	while(t--){
		
	
		cin >> n >> m >> k;
		ans = k;
		for(int i = 1;i <= n;i ++){
			for(int j = 1;j <= m;j ++){
				mp[i][j] = 0;
			}
		}
		for(int i = 1;i <= k;i ++){
			int x,y;
			cin >> x >> y ;
			mp[x][y] = i;
			p[i].x=  x;
			p[i].y= y;
			p[i].vis = 0;
		}
		cout << dfs(k)<<'\n';
		
	}
	return 0;
}

Details

answer.code: In function ‘int main()’:
answer.code:58:17: error: ‘ans’ was not declared in this scope; did you mean ‘abs’?
   58 |                 ans = k;
      |                 ^~~
      |                 abs