zoukankan      html  css  js  c++  java
  • UVA 127 链表和栈的使用

    刘汝佳的题目感觉都是比较难以处理的,就像这道题目,一看数据简直觉得头大。。。加上这个英文我也看的想死

    最后看别人博客的题意讲解才知道原来是要移牌。

    然后如果熟练的使用stack和手写链表的话,这个题目是不成问题的

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <stack>
    #define N 100
    using namespace std;
    struct node{
        char ch[3];
    };
    stack<node> arr[N];
    int next[N],pre[N];
    int t,cnt;
    void deletegap()
    {
        for (int i=0;i!=t;i=next[i])
        {
            if (arr[i].empty())
            {
                next[pre[i]]=next[i];
                pre[next[i]]=pre[i];
                return;
            }
        }
    }
    bool movement()
    {
        int i;
        for (i=next[0];i<t;i=next[i])
        {
            int f1=pre[pre[pre[i]]];
            if (f1>=0 && f1<t)
            {
    
                if (arr[i].top().ch[0]==arr[f1].top().ch[0] || arr[i].top().ch[1]==arr[f1].top().ch[1])
                {
                    arr[f1].push(arr[i].top());
                    arr[i].pop();
                    return true;
                }
            }
            int f0=pre[i];
            if (arr[i].top().ch[0]==arr[f0].top().ch[0]||arr[i].top().ch[1]==arr[f0].top().ch[1])
            {
                arr[f0].push(arr[i].top());
                arr[i].pop();
                return true;
            }
        }
        return false;
    
    }
    void solve()
    {
        while (movement())
        {
            deletegap();
        }
    }
    int main()
    {
        t=0;
        node temp;
        while (scanf("%s",temp.ch))
        {
            if (temp.ch[0]=='#')
                break;
            while (!arr[t].empty())
                arr[t].pop();
            arr[t].push(temp);
            pre[t]=t-1;
            next[t]=t+1;
            t++;
            if (t==52)
            {
              solve();
              int ans=0;
              for (int i=0;i!=t;i=next[i])
                ans++;
              if (ans==1) printf("1 pile remaining: ");
              else printf("%d piles remaining: ",ans);
              for (int j=0;j!=t;j=next[j])
              {
                  if (j) putchar(' ');
                  printf("%d",arr[j].size());
              }
              putchar('
    ');
              t=0;
            }
        }
        return 0;
    }
  • 相关阅读:
    jmeter之GUI运行原理
    jmeter之自定义java请求性能测试
    TestNG+ExtentReports生成超漂亮的测试报告(转)
    【测试设计】使用jenkins 插件Allure生成漂亮的自动化测试报告(转)
    Windows 清空剪切板
    android studio Warehouse(仓库配置)
    C/C++ string to int or int to string
    CNC FANUC define program
    CNC WEB
    CNC 法兰克加工中心CNC数控系统怎么修改程序
  • 原文地址:https://www.cnblogs.com/kkrisen/p/3460317.html
Copyright © 2011-2022 走看看