【习题 6-10 UVA - 246】10-20-30
【链接】 我是链接,点我呀:)
【题意】
【题解】
发牌的那个牌堆用一个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;
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 现代计算机视觉入门之:什么是图片特征编码
· .NET 9 new features-C#13新的锁类型和语义
· Linux系统下SQL Server数据库镜像配置全流程详解
· 现代计算机视觉入门之:什么是视频
· 你所不知道的 C/C++ 宏知识
· 不到万不得已,千万不要去外包
· C# WebAPI 插件热插拔(持续更新中)
· 会议真的有必要吗?我们产品开发9年了,但从来没开过会
· 【译】我们最喜欢的2024年的 Visual Studio 新功能
· 如何打造一个高并发系统?