马拦过河卒(NOIP)
2015-07-05 11:20
246 查看
马拦过河卒(NOIP)
Time Limit:7000MS Memory Limit:65536K
Description
如图,A点有一个过河卒,需要走到目标 B点。卒行走规则:可以向下、或者向右。同时在棋盘上的任一点有一个对方的马(如上图的C点),该马所在的点和所有跳跃一步可达的点称为对方马的控制点。例如上图 C点上的马可以控制 9个点(图中的P1,P2 … P8和 C)。卒不能通过对方马的控制点。
棋盘用坐标表示,A点(0,0)、B点(n,m)(n,m为不超过 17的整数,并由键盘输入),同样马的位置坐标是需要给出的(约定: C<>A,同时C<>B)。现在要求你计算出卒从 A点能够到达 B点的路径的条数。
Input
输入B点的坐标(n,m)以及对方马的坐标(X,Y)
Output
屏幕输出一个整数(路径的条数)。
Sample Input
Sample Output
Source
NOIP2002 普及组
Time Limit:7000MS Memory Limit:65536K
Description
如图,A点有一个过河卒,需要走到目标 B点。卒行走规则:可以向下、或者向右。同时在棋盘上的任一点有一个对方的马(如上图的C点),该马所在的点和所有跳跃一步可达的点称为对方马的控制点。例如上图 C点上的马可以控制 9个点(图中的P1,P2 … P8和 C)。卒不能通过对方马的控制点。
棋盘用坐标表示,A点(0,0)、B点(n,m)(n,m为不超过 17的整数,并由键盘输入),同样马的位置坐标是需要给出的(约定: C<>A,同时C<>B)。现在要求你计算出卒从 A点能够到达 B点的路径的条数。
Input
输入B点的坐标(n,m)以及对方马的坐标(X,Y)
Output
屏幕输出一个整数(路径的条数)。
Sample Input
6 6 3 2
Sample Output
17
Source
NOIP2002 普及组
#include <stdio.h> #define maxn 19 int n, m; int g[maxn][maxn]; bool flag[maxn][maxn]; int tx[9]={0, -2, -2, -1, -1, 1, 1, 2, 2}; int ty[9]={0, -1, 1, -2, 2, -2, 2, -1, 1}; void _read(int& d) { char t=getchar();bool f=false; while(t<'0'||t>'9') {if(t=='-') f=true; t=getchar();} for(d=0;t<='9'&&t>='0';t=getchar()) d=d*10+t-'0'; if(f) d=-d; } void _out(int d) { int o[30],top=1; if(d==0){putchar('0');return ;} if(d<0) {putchar('-');d=-d;} while(d) { o[top++]=d%10; d/=10; } for(--top;top;--top) putchar('0'+o[top]); } void biaoji(int x, int y) { if(x>0&&x<=n&&y>0&&y<=m) flag[x][y]=1; } void rec(int x, int y) { if(flag[x-1][y]) g[x][y]+=g[x-1][y]; else { rec(x-1, y); g[x][y]+=g[x-1][y]; } if(flag[x][y-1]) g[x][y]+=g[x][y-1]; else { rec(x, y-1); g[x][y]+=g[x][y-1]; } flag[x][y]=1; } int main() { int x, y, i; _read(n), _read(m), _read(x), _read(y); n++; m++; x++; y++; for(i=0; i<9; i++) biaoji(x+tx[i], y+ty[i]); for(i=0; i<=m+1; i++) flag[0][i]=1; for(i=0; i<=n+1; i++) flag[i][0]=1; g[1][1]=1; flag[1][1]=1; rec(n, m); _out(g [m]); return 0; }
相关文章推荐
- NSBundle 的常用方法
- <VirtualHost *:80>配置文件
- 范围要找个时间记住
- 【原创】FltGetFileNameInformation蓝屏分析
- NSHomeDirectory(); 动态获取路径
- 建立GridView Column
- SWIG and Android
- 计算几何(转)
- 架构师速成6.4-开发框架
- 算法导论学习---红黑树详解之插入(C语言实现)
- 架构师速成6.4-开发框架 分类: 架构师速成 2015-07-05 11:18 402人阅读 评论(0) 收藏
- API设计准则(转)
- 二维代数几何原理
- 提高HTML5 canvas性能的几种方法(转)
- 【USACO1.5.1】Number Triangles 数字金字塔
- 【原创】调用系统函数里面蓝屏例子
- MIT线性代数--推广意义的向量空间
- 第七节:将类型序列化为不同的类型以及将类型反序列化为不同的对象
- [Android L]SEAndroid开放设备文件结点权限(读或写)方法(涵盖常用操作:sys/xxx、proc/xxx、SystemProperties)热门干货
- 【原创】FltSendMessage蓝屏分析