搜狐笔试第一题,测试数据有效
#include <iostream> using namespace std; const int N = 1e7+5; const int MAXN = 1005; int n , m; int x[MAXN]; int a[N]; int main() { scanf("%d %d",&n , &m); for(int i = 0 ; i < m ; i++) cin >> x[i]; a[1] = x[0]; int now = 1 , pos = 1; int v = 0; while(pos < N) { for(int j = 0; j < a[now] && j + pos < N; j++) a[j + pos] = x[v]; v = (v+1) % m; pos += a[now]; now++; if(a[1] == 1){ a[2] = x[1]; } } for(int i = 1 ; i <= n ; i++) printf("%d ",a[i]); return 0; }