UVA - 10152 ShellSort

本文探讨了在栈中通过乌龟的操作将初始序列转换为目标序列的最小步骤问题。通过对比序列元素,直接输出需要调整的序列部分即可解决。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

点击打开链接

题意是在栈中乌龟有一个给初始系列和目标序列,然后求由初始序列变成目标序列最少操作的次数。

乌龟只能从当前位置爬到栈顶。

其实只要从大到小找出初始序列中编号比目标序列大的然后输出就行。

#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <string>
#include <set>
#include <functional>
#include <numeric>
#include <sstream>
//#include <stack>
#include <map>
#include <queue>

#define CL(arr, val)    memset(arr, val, sizeof(arr))

#define ll long long
#define inf 0x7f7f7f7f
#define lc l,m,rt<<1
#define rc m + 1,r,rt<<1|1
#define pi acos(-1.0)

#define L(x)    (x) << 1
#define R(x)    (x) << 1 | 1
#define MID(l, r)   (l + r) >> 1
#define Min(x, y)   (x) < (y) ? (x) : (y)
#define Max(x, y)   (x) < (y) ? (y) : (x)
#define E(x)        (1 << (x))
#define iabs(x)     (x) < 0 ? -(x) : (x)
#define OUT(x)  printf("%I64d\n", x)
#define lowbit(x)   (x)&(-x)
#define Read()  freopen("a.txt", "r", stdin)
#define Write() freopen("dout.txt", "w", stdout);
#define N 100005
using namespace std;

int main()
{
   // Read();
    int t,n,i,j;
    string s1[250],s2[250];
    cin>>t;
    while(t--)
    {
        cin>>n;
        cin.get();
        for(i=0;i<n;i++)
            getline(cin,s1[i]);
        for(i=0;i<n;i++)
            getline(cin,s2[i]);
        j=n-1;
        for(i=n-1;i>=0;i--)
        {
            if(s1[i]==s2[j]) j--;
        }
        for(i=j;i>=0;i--)
            cout<<s2[i]<<endl;
        cout<<endl;
    }
    return 0;
}


 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值