• poj3078


    题意:很难理解,是说一个队列,给出原始队列,并每次把原始队列中位置a的元素挪到b位置,先不考虑其余元素位置。进行了所有操作后,其余元素依次填入队列的空位,并保持前后顺序不变。问操作后的队列。题中说明每个元素只会被挪一次,而且每个要挪到的位置也只会出现一次。

    分析:可以直接模拟。我们可以用两个数组,把第一个数组中的元素挪到第二个数组的指定位置,没有挪的依次填入第二个数组即可。

    View Code
    #include <iostream>
    #include
    <cstdio>
    #include
    <cstdlib>
    #include
    <cstring>
    usingnamespace std;

    #define maxn 25
    #define maxl 20

    char name[maxn][maxl];
    int n, m;
    bool vis[maxn];
    int ans[maxn];

    int main()
    {
    //freopen("t.txt", "r", stdin);
    int t;
    scanf(
    "%d", &t);
    while (t--)
    {
    scanf(
    "%d%d", &n, &m);
    for (int i =1; i <= n; i++)
    scanf(
    "%s", name[i]);
    memset(vis,
    0, sizeof(vis));
    memset(ans,
    -1, sizeof(ans));
    for (int i =0; i < m; i++)
    {
    int a, b;
    scanf(
    "%d%d", &a, &b);
    vis[a]
    =true;
    ans[b]
    = a;
    }
    int j =1;
    for (int i =1; i <= n; i++)
    if (ans[i] ==-1)
    {
    while (vis[j])
    j
    ++;
    ans[i]
    = j;
    vis[j]
    =true;
    }
    printf(
    "%s", name[ans[1]]);
    for (int i =2; i <= n; i++)
    printf(
    " %s", name[ans[i]]);
    printf(
    "\n");
    }
    return0;
    }
  • 相关阅读:
    liunx配置jdk
    liunx 用户修改文件打开数
    goolge安装插件
    安装解压版MySQL 5.6.35
    Windows7 搭建ftp 服务
    eclipse 搭建Swt 环境
    注释正则表达式
    java excle导出合计字段值
    liunx 字符编码问题
    FreeIPA ACI (Access Control Instructions) 访问控制说明
  • 原文地址:https://www.cnblogs.com/rainydays/p/2095925.html
Copyright © 2020-2023  润新知