zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    视频聊天相关技术介绍
    block相关归纳
    block的作用
    block教程
    向appstore提交app流程
    ios xmpp 发送语音图片解决方案
    python 三元运算、列表推倒式、字典推倒式、生成器生成式
    python 生成器
    python 迭代器(第二次总结)
    python 迭代器
  • 原文地址:https://www.cnblogs.com/rainydays/p/2095925.html
Copyright © 2011-2022 走看看