zoukankan      html  css  js  c++  java
  • 【习题 6-10 UVA

    【链接】 我是链接,点我呀:)
    【题意】

    在这里输入题意

    【题解】

    发牌的那个牌堆用一个deque,7个牌堆用vector来模拟。 然后按照题意模拟就好。 不难。

    【代码】

    /*
    1.Shoud it use long long ?
    2.Have you ever test several sample(at least therr) yourself?
    3.Can you promise that the solution is right? At least,the main ideal
    4.use the puts("") or putchar() or printf and such things?
    5.init the used array or any value?
    6.use error MAX_VALUE?
    7.use scanf instead of cin/cout?
    8.whatch out the detail input require
    */
    #include <bits/stdc++.h>
    using namespace std;
    
    const int N = 8;
    
    deque <int> dl;
    map <vector <int>, int > dic;
    vector <int> pile[N];
    bool bo[N];
    int cur;
    
    int judge() {
    	vector <int> v;
    	v.clear();
    	for (auto i = dl.begin(); i != dl.end(); i++) {
    		v.push_back((*i));
    	}
    
    	for (int i = 1; i <= 7; i++) {
    		v.push_back(0);
    		for (int x : pile[i]) {
    			v.push_back(x);
    		}
    	}
    
    	if (dic.find(v) != dic.end()) return 1;
    	dic[v] = 1;
    	return 0;
    }
    
    bool can() {
    	int len = pile[cur].size();
    	if (len<3) return false;
    
    	int ju = pile[cur][0] + pile[cur][1] + pile[cur][len-1];
    
    	if (ju == 10 || ju == 20 || ju == 30) {
    		dl.push_back(pile[cur][0]);
    		dl.push_back(pile[cur][1]);
    		dl.push_back(pile[cur][len-1]);
    
    		pile[cur].erase(pile[cur].begin());
    		pile[cur].erase(pile[cur].begin());
    		pile[cur].erase(pile[cur].end() - 1);
    		return true;
    	}
    
    	ju = pile[cur][0] + pile[cur].back() + pile[cur][len - 2];
    	if (ju == 10 || ju == 20 || ju == 30) {
    		dl.push_back(pile[cur][0]);
    		dl.push_back(pile[cur][len - 2]);
    		dl.push_back(pile[cur][len - 1]);
    
    		pile[cur].erase(pile[cur].begin());
    		pile[cur].erase(pile[cur].end() - 1);
    		pile[cur].erase(pile[cur].end() - 1);
    		return true;
    	}
    
    	ju = pile[cur][len - 3] + pile[cur][len - 2] + pile[cur].back();
    	if (ju == 10 || ju == 20 || ju == 30) {
    		dl.push_back(pile[cur][len - 3]);
    		dl.push_back(pile[cur][len - 2]);
    		dl.push_back(pile[cur][len - 1]);
    
    		pile[cur].erase(pile[cur].end() - 1);
    		pile[cur].erase(pile[cur].end() - 1);
    		pile[cur].erase(pile[cur].end() - 1);
    		return true;
    	}
    
    	return false;
    }
    
    int main() {
    	#ifdef LOCAL_DEFINE
    		freopen("F:\c++source\rush_in.txt", "r", stdin);
    				freopen("F:\c++source\rush_out.txt", "w", stdout);
    	#endif
    	ios::sync_with_stdio(0), cin.tie(0);
    	int x;
    	while (cin >> x && x) {
    		for (int i = 1; i <= 7; i++) bo[i] = true;
    		for (int i = 1; i <= 7; i++) pile[i].clear();
    		dic.clear();
    		while (!dl.empty()) dl.pop_back();
    
    		dl.push_back(x);
    		for (int i = 1; i <= 51; i++) {
    			cin >> x;
    			dl.push_back(x);
    		}
    
    		judge();
    		int tot = 0;
    
    		int ans;
    		cur = 1;
    		while (1) {
    			if (dl.empty()) { //lose
    				ans = -1;
    				break;
    			}
    			int cntalive = 0;
    			for (int i = 1; i <= 7; i++) cntalive += bo[i];
    			if (cntalive == 0) {//win
    				ans = 1;
    				break;
    			}
    
    			//deal one card
    			if (cur > 7) cur = 1;
    			while (!bo[cur]) {
    				cur++;
    				if (cur > 7) cur = 1;
    			}
    
    			pile[cur].push_back(dl.front());
    			dl.pop_front();
    
    			do {
    			} while (can());
    
    			if (pile[cur].empty()) bo[cur] = 0;
    
    			tot++;
    
    			int temp = judge();
    			if (temp == 1) {
    				ans = 0;//loop;
    				break;
    			}
    			cur++;
    		}
    
    		if (ans == 0) {
    			cout << "Draw: ";
    		}
    		else if (ans == 1) {
    			cout << "Win : ";
    		}
    		else if (ans == -1) {
    			cout << "Loss: ";
    		}
    		cout << tot << endl;
    	}
    	return 0;
    }
    
  • 相关阅读:
    actionbar中添加searchview并监听期伸缩/打开的方法
    Java基础学习总结(87)——坚持写Java等技术类博客的好处
    Nginx学习总结(3)——Nginx配置及应用场景之高级配置
    [置顶] 软件版本命名规范及各阶段说明
    戏说云计算之PaaS,IaaS,SaaS
    App后台开发运维和架构实践学习总结(4)——APP的注册和登录功能设计
    Maven学习总结(30)——Maven项目通用三级版本号说明
    Java Web学习总结(29)——Java Web中的Filter和Interceptor比较
    养成10个优秀的习惯
    Java基础学习总结(86)——Java异常处理机制Exception抛出异常时throw和throws用法详解
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7907821.html
Copyright © 2011-2022 走看看