强迫症患者

Description

如你所知,GDUTACM集训队有那么几个强迫症患者,患者标就是其中的一个,他对每晚离开时的关灯策略很在意。 现在有N盏亮着的灯,编号分别为1,2,3...,N-1,N,患者标将进行M次关灯操作,每次他会在1到N中选取一个数字开关去关掉仍亮着的灯, 即所有编号不小于这个数字而且还在亮着的灯都会被关上,请问对于每盏灯是被哪个数字开关关掉的? (请放心,出于强迫症,所以进行M次操作后所有的灯一定都能被患者标关上~)

Input

输入的第一行为一个正整数T(T <= 10),表明接下来有T组数据。 对于每组数据只有两行,第一行为一个正整数N和一个正整数M(1 <= N, M <= 100)。 第二行有M个互不相同的数字开关b1,b2,...,bm (1≤bi≤N)。

Output

每组测试数据输出N个数,第i个数表示将第i盏灯是被哪个数字关掉的

Sample Input

1 5 4 4 3 1 2

Sample Output

1 1 3 4 4

HINT

简单模拟

 1 #include <iostream>
 2 #include <cstring>
 3 #include <cstdio>
 4 #include <string>
 5 #include <algorithm>
 6 using namespace std;
 7 #define maxn 110
 8 int mark[maxn];
 9 int T, N, M;
10 int main(){
11     scanf("%d", &T);
12     while(T--){
13         scanf("%d%d", &N, &M);
14         memset(mark, 0, sizeof(mark));
15         for(int i = 1; i <= M; i++){
16             int temp; 
17             scanf("%d", &temp);
18             for(int j = temp; j <= N; j++){
19                 if(mark[j] == 0) mark[j] = temp; 
20             }
21         }
22         for(int i = 1; i <= N; i++){
23             if(i == 1) printf("%d", mark[1]);
24             else printf(" %d", mark[i]);
25         }
26         printf("
");
27     }
28     
29     return 0;
30 }
原文地址:https://www.cnblogs.com/titicia/p/4342249.html