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;
    }
    
  • 相关阅读:
    服务器资源共享--IIS站点/虚拟目录中访问共享目录(UNC)
    sql reiserror 输出错误
    使用xib方式创建UITableViewCell,设置Label自动换行注意事项
    原生的UITableViewCell高度自适应,textLabel自动换行显示
    屏幕截取-2种模式
    NSDictionary初始化,使用@{}方法,插入nil时会报空指针异常
    Unicode解码、URL编码/解码
    解决UITableView数据没有充满屏幕时,显示多余的空白cell的问题
    UITableView的分割线不满屏的解决方法
    动态获取UIWebView的真正高度
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7907821.html
Copyright © 2011-2022 走看看