题目问答
题目问答简介
数据是不是弱了
试一下这组 hack
```text
10 1
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
```
查看全文
4
0
0
106
为什么有一个样例没过呀
```cpp
//13.5分
#include<bits/stdc++.h>
using namespace std;
const int N = 13;
int g[N][N]; //输入数据
int d[N][N]; //-1为未经过,1为已经过
int p[N*N]; //存储答案
int cnt; // 表示当前答案数量
int n, k;
bool flag= true;//输出答案后,用于结束递归结束程序
void dfs(int u, int x,int y)
{
if(u==n*n-1&&x==n&&y==n)
{
for(int i = 1;i<=n*n-1;i++)
cout<<p[i];
flag = false;
return;
}
int dx[8] = {-1,-1,0,1,1,1,0,-1};
int dy[8] = {0,1,1,1,0,-1,-1,-1};
for(int i = 0;i<8;i++)
{
int x1 = x+dx[i];
int y1 = y+dy[i];
if(x1>=1&&x1<=n&&y1>=1&&y1<=n&&d[x1][y1]==-1)
{
if(g[x1][y1]==g[x][y]+1||(g[x1][y1]==0&&g[x][y]==k-1))
{
//表示不交叉
if(i==1&&d[x][y+1]!=-1&&d[x-1][y]!=-1) continue;
if(i==3&&d[x][y+1]!=-1&&d[x+1][y]!=-1) continue;
if(i==5&&d[x+1][y]!=-1&&d[x][y-1]!=-1) continue;
if(i==7&&d[x-1][y]!=-1&&d[x][y-1]!=-1) continue;
d[x1][y1]=1;
p[++cnt] = i;
dfs(u+1,x1,y1);
d[x1][y1]=-1;
cnt--;
if(!flag) return;
}
}
}
}
int main()
{
cin >> n>>k;
for(int i = 1;i<=n;i++)
for(int j = 1;j<=n;j++)
cin >> g[i][j];
memset(d, -1,sizeof d);
d[1][1] = 1;
dfs(0,1,1);
if(flag) cout << "-1";
return 0;
}
```
查看全文
3
0
0
90
这个数据合法吗
10 2
0 1 0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0 1 0
0 1 0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0 1 0
0 1 0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0 1 0
0 1 0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0 1 0
0 1 0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0 1 0
查看全文
0
0
0
75
为什么第九个测试案例超时了
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 12;
int n,k;
int mp[N][N];
bool vis[N][N];
int dir[8][2] = {-1,0, -1,1, 0,1, 1,1, 1,0, 1,-1, 0,-1, -1,-1};
vector<string> res;
set<pair<pair<int,int>, pair<int,int>>> s;
string ans;
void dfs(int x,int y,int num,int cnt)
{
if(x == n && y == n && cnt != n*n)
{
return ;
}
if(cnt == n*n && x == n && y == n)
{
res.push_back(ans);
return ;
}
for(int i = 0;i<8;i++)
{
int nx = x + dir[i][0];
int ny = y + dir[i][1];
if(nx<1 || ny <1 || nx>n || ny>n || vis[nx][ny] || mp[nx][ny] != (num+1)%k) continue;
if(i%2)
{
if(s.find({{x,ny},{nx,y}}) != s.end() || s.find({{nx,y},{x,ny}}) != s.end())
{
continue;
}
}
ans += i + '0';
s.insert({{x,y},{nx,ny}});
vis[nx][ny] = true;
dfs(nx,ny,mp[nx][ny],cnt+1);
vis[nx][ny] = false;
s.erase({{x,y},{nx,ny}});
ans.pop_back();
}
}
int main()
{
cin>>n>>k;
for(int i = 1;i<=n;i++)
for(int j = 1;j<=n;j++)
cin>>mp[i][j];
vis[1][1] = true;
dfs(1,1,mp[1][1],1);
if(res.size() == 0)
{
cout<<-1;
return 0;
}
sort(res.begin(), res.end());
cout<<res[0];
return 0;
}
```
查看全文
0
0
0
17



