zoukankan      html  css  js  c++  java
  • UVa 246

    这道题在数据结构这一章里算是简单的,但是很容易WA和RE,可能得debug很长时间。

    值得注意的地方:

    1.纸牌被处理的次数中,每次发牌并且检查一次匹配,算处理一次,而不是四次

    2.查看匹配的时候,如果一次匹配成功并且删除了三张纸牌,要继续检查是否匹配,这是个循环的过程

    3.可以通过用set记录State判重,判断打平的情况

    4.纸牌收回手中时,注意纸牌摆放的顺序

    #include <bits/stdc++.h>
    using namespace std;
    
    int cnt = 0;
    deque<int> hand;
    vector<deque<int>> tab;
    set<vector<deque<int>>> s;
    
    bool input(){
    	cnt = 0; hand.clear();
    	while (true){
    		int x; cin >> x;
    		if (!x) return false;
    		hand.push_back(x);
    		if (hand.size() == 52) return true;
    	}
    }
    bool can(int a, int b, int c, deque<int> & cur){
    	int val1 = a >= 0 ? *(cur.begin() + a) : *(cur.end() + a);
    	int val2 = b >= 0 ? *(cur.begin() + b) : *(cur.end() + b);
    	int val3 = c >= 0 ? *(cur.begin() + c) : *(cur.end() + c);
    	int sum = val1 + val2 + val3;
    	return sum == 10 || sum == 20 || sum == 30;
    }
    bool match(deque<int> & cur){
    	if (can(0, 1, -1, cur)){
    		int t0 = cur.front(); cur.pop_front();
    		int t1 = cur.front(); cur.pop_front();
    		int t_1 = cur.back(); cur.pop_back();
    		hand.push_back(t0); hand.push_back(t1); hand.push_back(t_1);
    		return true;
    	}
    	if (can(0, -1, -2, cur)){
    		int t0 = cur.front(); cur.pop_front();
    		int t_1 = cur.back(); cur.pop_back();
    		int t_2 = cur.back(); cur.pop_back();
    		hand.push_back(t0); hand.push_back(t_2); hand.push_back(t_1);
    		return true;
    	}
    	if (can(-1, -2, -3, cur)){
    		int t_1 = cur.back(); cur.pop_back();
    		int t_2 = cur.back(); cur.pop_back();
    		int t_3 = cur.back(); cur.pop_back();
    		hand.push_back(t_3); hand.push_back(t_2); hand.push_back(t_1);
    		return true;
    	}
    }
    void run(){
    	tab.clear(); tab.resize(7);
    	s.clear();
    	int cur = 0;
    	while (++cnt, true) {
    		int x = hand.front(); hand.pop_front();
    		tab[cur].push_back(x);
    		while (tab[cur].size() >= 3 && match(tab[cur]));
    		if (hand.size() == 52) { printf("Win : %d
    ", cnt); return; }
    		if (hand.size() == 0) { printf("Loss: %d
    ", cnt); return; }
    		vector<deque<int>> t(tab); t.push_back(hand);
    		if (s.count(t)) { printf("Draw: %d
    ", cnt); return; }
    		else s.insert(t);
    		do {
    			cur = (cur + 1) % 7;
    		} while (tab[cur].size() == 0 && cnt >= 8);
    	}
    }
    int main()
    {
    	ios::sync_with_stdio(false);
    	while (input())
    		run();
    	return 0;
    }


  • 相关阅读:
    2021,6,10 xjzx 模拟考试
    平衡树(二)——Treap
    AtCoder Beginner Contest 204 A-E简要题解
    POJ 2311 Cutting Game 题解
    Codeforces 990G GCD Counting 题解
    NOI2021 SDPTT D2T1 我已经完全理解了 DFS 序线段树 题解
    第三届山东省青少年创意编程与智能设计大赛总结
    Luogu P6042 「ACOI2020」学园祭 题解
    联合省选2021 游记
    Codeforces 1498E Two Houses 题解 —— 如何用结论吊打标算
  • 原文地址:https://www.cnblogs.com/kunsoft/p/5312700.html
Copyright © 2011-2022 走看看