1 条题解
-
0
C :
#include<stdio.h> long long B[21][21]; int main(void) { int i,j,n,m,a,b; scanf("%d%d%d%d",&n,&m,&a,&b); for(i=0;i<=n;i++) for(j=0;j<=m;j++) B[i][j]=1; if(a-2>=0&&b-1>=0) B[a-2][b-1]=0; if(a-2>=0&&b+1<=m) B[a-2][b+1]=0; if(a-1>=0&&b-2>=0) B[a-1][b-2]=0; if(a-1>=0&&b+2<=m) B[a-1][b+2]=0; if(a+1<=m&&b-2>=0) B[a+1][b-2]=0; if(a+2<=n&&b-1>=0) B[a+2][b-1]=0; if(a+1<=n&&b+2<=m) B[a+1][b+2]=0; if(a+1<=n&&b+1<=m) B[a+2][b+1]=0; B[a][b]=0; for(i=0;i<=n;i++) { for(j=0;j<=m;j++) { if(B[i][j]) { if(i==0&&j==0) continue; else if(i==0) B[i][j]=B[i][j-1]; else if(j==0) B[i][j]=B[i-1][j]; else B[i][j]=B[i-1][j]+B[i][j-1]; } } } printf("%lld",B[n][m]); /*第一次是用int 后来发现有点小改成long long 之后一直错 上网查了一下下午终于在下午五点发现输出居然用%d!!! 这道题略坑,我早上11点做到17:55..只是因为这样一个错误。百密一疏呀。*/ return 0; }
C++ :
#include<iostream> using namespace std; long B[21][21];//定义棋盘 int main(){ int n,m;//目标点的坐标 int a,b;//马所在点的坐标 cin>>n>>m>>a>>b; //初始化棋盘:假设到达目标点(n,m)前每个点都可以通行设置成1 for(int i=0;i<=n;i++) for(int j=0;j<=m;j++) B[i][j]=1; //将马控制的点设置成0,代表不能通过 //控制马上边的4个点,只要不超过边届,则为控制点 if(a-2>=0&&b-1>=0) B[a-2][b-1]=0; if(a-2>=0&&b+1<=m) B[a-2][b+1]=0; if(a-1>=0&&b-2>=0) B[a-1][b-2]=0; if(a-1>=0&&b+2<=m) B[a-1][b+2]=0; //马下边的4个点,只要不超过边届,则为控制点 if(a+1<=n&&b-2>=0) B[a+1][b-2]=0; if(a+2<=n&&b-1>=0) B[a+2][b-1]=0; if(a+1<=n&&b+2<=m) B[a+1][b+2]=0; if(a+1<=n&&b+1<=m) B[a+2][b+1]=0; //马所在点不能 B[a][b]=0; for(int i=0;i<=n;i++){ for(int j=0;j<=m;j++){ //如果可行 if(B[i][j]){ if(i==0&&j==0) continue; else if(i==0) B[i][j]=B[i][j-1]; //目标点在最上面一行的时候 else if(j==0) B[i][j]=B[i-1][j];//目标点在最左边一行 else B[i][j]=B[i-1][j]+B[i][j-1];//到达目标点路径=上点路径+左点路径 } } } cout<<B[n][m]<<endl; }
Python :
sr=input().split() n=int(sr[0]) m=int(sr[1]) x=int(sr[2]) y=int(sr[3]) a=[[1 for i in range(m+1)] for j in range(n+1)] s=[[1 for i in range(m+1)] for j in range(n+1)] a[x][y]=0 s[0][0]=1 if(x+2<=n and y+1<=m): a[x+2][y+1]=0 if(x+1<=n and y+2<=m): a[x+1][y+2]=0 if(x-1>=0 and y+2<=m): a[x-1][y+2]=0 if(x-2>=0 and y+1<=m): a[x-2][y+1]=0 if(x-2>=0 and y-1>=0): a[x-2][y-1]=0 if(x-1>=0 and y-2>=0): a[x-1][y-2]=0 if(x+1<=n and y-2>=0): a[x+1][y-2]=0 if(x+2<=n and y-1>=0): a[x+2][y-1]=0 for i in range(n+1): for j in range(m+1): if(a[i][j]==0): s[i][j]=0 elif(i>0 and j>0): s[i][j]=s[i-1][j]+s[i][j-1] elif(i>0): s[i][0]=s[i-1][0] elif(j>0): s[0][j]=s[0][j-1] print(s[n][m])
- 1
信息
- ID
- 2156
- 时间
- 1000ms
- 内存
- 16MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者