UVA127 纸牌游戏 “Accordian“ Patience

知识点:模拟

这个题是第6章的,但是应该是练习链表的,但是主要还是个模拟,就用向量来写就行了,一开始肚子饿放下没写,过了一会儿再写14分钟过了,题目的意思也不难理解,就是模拟就行了

#include <bits/stdc++.h>

using namespace std;

int main() {
    string s;
    while (cin >> s && s != "#") {
        vector<string> a[52];
        a[0].push_back(s);
        for (int i = 1; i < 52; i++) {
            cin >> s; a[i].push_back(s);
        }
        vector<int> b;
        for (int i = 0; i < 52; i++) b.push_back(i);
        while (1) {
            int is_move = 0;
            for (int i = 1; i < (int) b.size(); i++) {
                int l1 = (int) a[b[i]].size();
                int l2 = (int) a[b[i - 1]].size();
                string s1 = a[b[i]][l1 - 1];
                string s2 = a[b[i - 1]][l2 - 1];
                if (i >= 3) {
                    int l3 = (int) a[b[i - 3]].size();
                    string s3 = a[b[i - 3]][l3 - 1];
                    if (s1[0] == s3[0] || s1[1] == s3[1]) {
                        a[b[i - 3]].push_back(s1);
                        a[b[i]].erase(a[b[i]].begin() + l1 - 1);
                        if (!(int) a[b[i]].size()) b.erase(b.begin() + i);
                        is_move = 1; break;
                    }
                }
                if (s1[0] == s2[0] || s1[1] == s2[1]) {
                    a[b[i - 1]].push_back(s1);
                    a[b[i]].erase(a[b[i]].begin() + l1 - 1);
                    if (!(int) a[b[i]].size()) b.erase(b.begin() + i);
                    is_move = 1; break;
                }
            }
            if (!is_move) break;
        }
        cout << (int) b.size();
        if ((int) b.size() == 1) cout << " pile remaining:";
        else cout << " piles remaining:";
        for (int i = 0; i < (int) b.size(); i++) {
            cout << " " << (int) a[b[i]].size();
        }
        cout << endl;
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值