比赛 |
202103省实验桐柏一中普及组联赛 |
评测结果 |
AAAAAAAAAA |
题目名称 |
亡羊补牢,未为迟也 |
最终得分 |
100 |
用户昵称 |
遥时_彼方 |
运行时间 |
0.003 s |
代码语言 |
C++ |
内存使用 |
0.33 MiB |
提交时间 |
2021-03-22 20:00:51 |
显示代码纯文本
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
using namespace std;
int nc,mc;
int n[21][21];
int mn,mj;
void dg(int x,int y,int num,int em)
{
int l[10][2],lj=0;
int xt=x,yt=y;
if(xt+1>nc)
{
xt=1;
yt++;
if(yt<=mc) dg(xt,yt,num,em);
}
else dg(xt+1,yt,num,em);
n[x][y]++;
l[++lj][0]=x;
l[lj][1]=y;
num++;
if(n[x][y]==1) em--;
if(x-2>0&&y+1<=mc)
{
if(!n[x-2][y+1]) em--;
n[x-2][y+1]++;
l[++lj][0]=x-2;
l[lj][1]=y+1;
}
if(x-1>0&&y+2<=mc)
{
if(!n[x-1][y+2]) em--;
n[x-1][y+2]++;
l[++lj][0]=x-1;
l[lj][1]=y+2;
}
if(x+1<=nc&&y+2<=mc)
{
if(!n[x+1][y+2]) em--;
n[x+1][y+2]++;
l[++lj][0]=x+1;
l[lj][1]=y+2;
}
if(x+2<=nc&&y+1<=mc)
{
if(!n[x+2][y+1]) em--;
n[x+2][y+1]++;
l[++lj][0]=x+2;
l[lj][1]=y+1;
}
if(x+1<=nc&&y-2>0)
{
if(!n[x+1][y-2]) em--;
n[x+1][y-2]++;
l[++lj][0]=x+1;
l[lj][1]=y-2;
}
if(x-1>0&&y-2>0)
{
if(!n[x-1][y-2]) em--;
n[x-1][y-2]++;
l[++lj][0]=x-1;
l[lj][1]=y-2;
}
if(x-2>0&&y-1>0)
{
if(!n[x-2][y-1]) em--;
n[x-2][y-1]++;
l[++lj][0]=x-2;
l[lj][1]=y-1;
}
if(x+2<=nc&&y-1>0)
{
if(!n[x+2][y-1]) em--;
n[x+2][y-1]++;
l[++lj][0]=x+2;
l[lj][1]=y-1;
}
// cout<<x<<" "<<y<<" "<<num<<" "<<em<<" "<<mn<<" "<<mj<<endl;
if(em==0)
{
// cout<<x<<" "<<y<<" "<<num<<" "<<em<<" "<<mn<<" "<<mj<<endl;
if(num<mn)
{
mn=num;
mj=1;
}
else if(num==mn) mj++;
}
else
{
if(x+1>nc)
{
x=1;
y++;
if(y<=mc) dg(x,y,num,em);
}
else dg(x+1,y,num,em);
}
for(int i=1;i<=lj;i++) n[l[i][0]][l[i][1]]--;
return;
}
int main()
{
freopen("secretnum.in","r",stdin);
freopen("secretnum.out","w",stdout);
cin>>nc>>mc;
mn=10000;
dg(1,1,0,nc*mc);
cout<<mn<<" "<<mj<<endl;
return 0;
}