9.1 NOIP普及组试题精解(2)
9-4 soldier.c
#include <stdio.h>
#define MAXN 21
};
int n, m, x, y; //n,m为B点的行列坐标位置,x,y为马的坐标位置
] = { -, -, , , , , -, - };
] = { , , , , -, -, -, - };
void horse() //初始化马和其控制点坐标位置
{
int i;
chessboard[x][y] = -; //标记马的位置
; i < ; i++) //标记马下一步的位置
{
&& x + dx[x] <= n) && (y + dy[i] >= )
&& (y + dy[i]) <= m)
chessboard[x + dx[i]][y + dy[i]] = -;
}
}
void search() //逐步搜寻出路
{
int i, j;
; i <= n; i++) //扫描第0列的各行
{
] != -) //若没有障碍
chessboard[i][] = ; //设置该位置可走路径数为1
else
break;
}
; i <= m; i++) //扫描第0行的每列
{
][i] != -) //若不是马的控制点
chessboard[][i] = ; //设置该位置可走路径数为1
else
break;
}
; i <= n; i++) //扫描各行各列
{
; j <= m; j++)
{
) //若该位置不是马的控制点
{
][j] != -) && (chessboard[i][j - ] != -)) //上面和左边也不是马的控制点
chessboard[i][j] = chessboard[i - ][j] + chessboard[i][j - ]; //将上面和左边的路径进行累加
][j] == -) && (chessboard[i][j - ] != -)) //若上面有马控制点,而左边无马控制点
chessboard[i][j] = chessboard[i][j - ]; //保存左边路径到到当前位置
][j] != -) && (chessboard[i][j - ] == -)) //若上面无马控制点,而左边有马控制点
chessboard[i][j] = chessboard[i - ][j]; //保存上面路径到当前位置
][j] == -) && (chessboard[i][j - ] == -)) //若上面和左边都有马的控制点
chessboard[i][j] = ; //当前位置无通路
}
}
}
}
int main()
{
int i, j;
FILE *fp1, *fp2;
if ((fp1 = fopen("soldier.in", "r")) == NULL)
{
printf("不能打开文件!\n");
exit();
}
fscanf(fp1,"%d%d%d%d", &n, &m, &x, &y);
fclose(fp1);
horse(); //初始化马及其下一步的位置
search();
if ((fp2 = fopen("soldier.out", "w")) == NULL)
{
printf("不能打开文件!\n");
exit();
}
printf("%d\n", chessboard[n][m]);
fprintf(fp2,"%d\n",chessboard[n][m]);
fclose(fp2);
getch();
;
}
9-5 isbn.c
#include <stdio.h>
int main()
{
] = { "0123456789X" };
];
int i, j, sum;
FILE *fp1, *fp2;
if ((fp1 = fopen("isbn.in", "r")) == NULL)
{
printf("不能打开文件!\n");
exit();
}
fgets(str, , fp1); //从文件中读取数据
fclose(fp1); //关闭文件
sum = ;
j = ;
; i < ; i++) //计算总和
{
&& i != )
sum += (str[i] - ') * j++;
}
sum %= ; //求模
if ((fp2 = fopen("isbn.out", "w")) == NULL)
{
printf("不能打开文件!\n");
exit();
}
] == table[sum]) //校验码正确
{
fputs("Right", fp2); //输出到文件
printf("Right\n");
}
else //校验码错误
{
str[] = table[sum]; //保存正确校验码
fputs(str, fp2); //输出正确的ISBN到文件
printf("%s\n", str);
}
fclose(fp2); //关闭文件
getch();
;
}
9.1 NOIP普及组试题精解(2)的更多相关文章
- 9.1 NOIP普及组试题精解(3)
9-6 seat.c #include <stdio.h> #define MAXN 1001 void swap(int *a, int *b) //交换数据 { int t; t = ...
- 9.1 NOIP普及组试题精解(1)
9-1 series1.c #include <stdio.h> int main() { float s=0.0,k; int n; printf("输入数字k(1~15):& ...
- 9.2 NOIP提高组试题精解(2)
9-18 fruit.c #include <stdio.h> #define MAXN 10000 int Queue1[MAXN], Queue2[MAXN]; void Insert ...
- 9.2 NOIP提高组试题精解(1)
9-16 poise.c #include <stdio.h> #define MAXN 1001 int main() { ], flag[MAXN] = { }; //保存6种砝码的数 ...
- 2016.10.6初中部上午NOIP普及组比赛总结
2016.10.6初中部上午NOIP普及组比赛总结 中了病毒--病毒--病毒-- 进度: 比赛:AC+0+0+20=120 改题:AC+0+AC+20=220 Stairs 好--简--单!递推就过了 ...
- 2016.8.15上午纪中初中部NOIP普及组比赛
2016.8.15上午纪中初中部NOIP普及组比赛 链接:https://jzoj.net/junior/#contest/home/1333 这次比赛不怎么好,因为这套题目我并不是很擅长. 可同学们 ...
- 2016.9.15初中部上午NOIP普及组比赛总结
2016.9.15初中部上午NOIP普及组比赛总结 2016.09.15[初中部 NOIP普及组 ]模拟赛 又翻车了!表示时超和空超很可恨! 进度 比赛:AC+0+0+20=120 改题:AC+80+ ...
- 2016.9.10初中部上午NOIP普及组比赛总结
2016.9.10初中部上午NOIP普及组比赛总结 链接:https://jzoj.net/junior/#contest/home/1340 好不爽!翻车了!不过排名差不多在中间偏上一点, 还好不是 ...
- 2016.9.3初中部上午NOIP普及组比赛总结
2016.9.3初中部上午NOIP普及组比赛总结 链接:https://jzoj.net/junior/#contest/home/1339 这次真爽,拿了个第四!(我还被班主任叫过去1小时呢!) 进 ...
随机推荐
- 【BIEE】BIEE报表根据维度表展示事实表不存在的维度
事实表数据 维度表数据 现在报表展示如下: 这样展示报表让人感觉数据缺失了,需要显示成如下样子,感觉会比较舒服一点 那么,如何实现上面的完美操作呢? 实现步骤 分析编辑页面→表视图属性→包含仅具有空行 ...
- Hive命令详解
http://blog.itpub.net/22778222/viewspace-1119892/ 官方文档翻译 http://blog.csdn.net/hguisu/article/detail ...
- android Gallery2 onPause时候,其背景界面显示黑色
改动: Src/com/android/gallery3d/app/AbstracGalleryActivity.java OnResume()函数约290行 去掉 mGLRootView.setVi ...
- bottle的几个小坑
距离我在<web.py应用工具库:webpyext>里说要换用bottle,已经过去快两个月了--事实上在那之前我已经開始着手在换了.眼下那个用于 Backbone.js 介绍的样例程序已 ...
- 下一代Apache Hadoop MapReduce框架的架构
背景 随着集群规模和负载增加,MapReduce JobTracker在内存消耗,线程模型和扩展性/可靠性/性能方面暴露出了缺点,为此需要对它进行大整修. 需求 当我们对Hadoop MapReduc ...
- 【PyCharm编辑器】之报:Spellchecker inspection helps locate typos and misspelling in your code, comments and literals, and fix them in one click.问题
如上图,输入一个单词时会出现波浪线,报:Spellchecker inspection helps locate typos and misspelling in your code, comment ...
- 【虚拟机】WIN8.1系统虚拟机完全彻底删除
一.首先删除注册表 用管理员身份打开CMD,输入F:\>VMware-workstation-full-12.5.5-5234757.exe/clean,根据自己的虚拟机安装文件的路径进行改变( ...
- mysql 相关博客地址
MySQL概念学习与逐步上手操作系列(一套完整) https://www.cnblogs.com/zlslch/category/962962.html
- 计算机器内存数量+引入和显示ARDS成员
[1]README 1.1) 本代码在于读取内存中多个 内存段的地址范围描述符结构体(ARDS),有多少个内存段可以用: 1.2) source code and images in the blog ...
- C - The C Answer (2nd Edition) - Exercise 1-1
/* Run the "hello, world" program on your system. Experiment with leaving out parts of the ...