加入收藏 | 设为首页 | 会员中心 | 我要投稿 | RSS  
您当前的位置:首页 > 经典解题 > 历届试题详解

NOIP2010提高组解题报告

时间:2011-09-14 10:39:14  来源:海平课堂  作者:Bluesea

1.translate简单模拟。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdio.h>

int queue[1001];
int used[1001];
int tail, head;
int ans = 0;

void enqueue(int n)
{
        ans++;
        queue[tail++] = n;
        used[n] = 1;
}

int exqueue(void)
{
        used[queue[head]] = 0;
        return queue[head++];
}

int main(void)
{
        int i, j;
        int m, n;
        scanf("%d%d", &m, &n);
        for(i = 0; i < n && tail - head != m; i++){
                scanf("%d", &j);
                if(!used[j]){
                        enqueue(j);
                }
        }
        while(i < n){
                scanf("%d", &j);
                if(!used[j]){
                        exqueue();
                        enqueue(j);
                }
                i++;
        }
        printf("%d\n", ans);
        return 0;
}
来顶一下
返回首页
返回首页
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表