2017.2.18日的练习赛(NOIP2010)
作为一个OI届的晚辈,能接触到近七年前的NOIP考试无疑是一件令人兴奋的事情。这倒不是因为什么信仰,实在是因为只有一试四道题(而不是二试六道题),做起来让人没有“后顾”之忧。下面我们来看看:
1.机械翻译
解题报告:
不得不说,这道题作为第一题是非常“温柔”的。众所周知,“模拟”算法(如果能称作一个算法的话)是NOIP最常考的考点(没有之一)。这道题就是对一个数据结构“队列”进行模拟。
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int N=1005;
int n,m,tot=0;
int head=1,tail=0,queue[N];//head头指针、tail尾指针、queue队列(用数组模拟)
int main()
{
freopen("translate.in","r",stdin);
freopen("translate.out","w",stdout);
memset(queue,0,sizeof(queue));
scanf("%d%d",&n,&m);
while(m--)
{
int t;
scanf("%d",&t);
for(int i=head;i<=tail;i++)
if(queue[i]==t)goto h;
tot++;
queue[++tail]=t;
if(tail-head+1>n)head++;//内存占满的情况
h:;
}
printf("%d",tot);
return 0;
}
2.乌龟棋
解题报告:
看到这道题我就闻到了浓浓的动态规划的味道。众所周知,动态规划作为NOIP第二“关心”的考点,是不可能不会见到的(但是,囿于姿势水平太低,一开始是用dfs暴力做的(加上一点点剪枝))。这道题dp的思路是这样的:
先统计出走一步、两步、三步、四步的牌的个数。然后通过四个循环枚举每一种情况,这样来dp。
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int N=355;
const int M=125</