noip模拟赛 数列

分析:打个表,会发现a1,a2中较小的一个数会出现很多次,把这些数删掉,就会形成若干个等差数列,每个等差数列中新出现的数的个数是a1a2较大者除以较小者.之后取个余,继续做重复的操作就行了.

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

int n, p, k, f[1010][1010], a[1010], pos[1010];

int main()
{
    scanf("%d%d%d", &n, &p, &k);
    for (int i = 1; i <= n; i++)
        a[i] = i, pos[i] = i;
    for (int i = p; i >= 1; i--)
    {
        scanf("%d", &f[i][0]);
        for (int j = 1; j <= f[i][0]; j++)
            scanf("%d", &f[i][j]);
    }
    for (int i = 1; i <= p; i++)
        for (int j = 2; j <= f[i][0]; j++)
        {
            swap(a[pos[f[i][1]]], a[pos[f[i][j]]]);
            swap(pos[f[i][1]], pos[f[i][j]]);
        }
    for (int i = 1; i <= n; i++)
        printf("%d ", a[i]);

    return 0;
}

 

posted @ 2017-11-02 20:52  zbtrs  阅读(199)  评论(0编辑  收藏  举报