【习题 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;
}
【习题 6-10 UVA - 246】10-20-30的更多相关文章
- “取出数据表中第10条到第20条记录”的sql语句+selecttop用法
1.首先,select top用法: 参考问题 select top n * from和select * from的区别 select * from table -- 取所有数据,返回无序集合 sel ...
- “取出数据表中第10条到第20条记录”的sql语句+select top 使用方法
1.首先.select top使用方法: 參考问题 select top n * from和select * from的差别 select * from table -- 取全部数据.返回无序集合 ...
- c# Equal函数 and 运算符'==' (原发布 csdn 2017年10月15日 20:39:26)
1.==.!=.<.>.<= 和>= 运算符为比较运算符(comparison operator).C#语言规范5.0中文版中比较运算符的描述如下: 2.通用类型系统 3.值类 ...
- 《java入门第一季》之HashSet小案例:获取10个1至20的随机数,要求随机数不能重复
这是基于HashSet集合的唯一性. /* * 编写一个程序,获取10个1至20的随机数,要求随机数不能重复. * * 分析: * A:创建随机数对象 * B:创建一个HashSet集合 ...
- 题目:企业发放的奖金根据利润提成。 利润(I)低于或等于10万元时,奖金可提10%; 利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可可提成7.5%; 20万到40万之间时,高于20万元的部分,可提成5%; 40万到60万之间时高于40万元的部分,可提成 3%; 60万到100万之间时,高于60万元的部分,可提成1.5%; 高于100万元时,超过
题目:企业发放的奖金根据利润提成. 利润(I)低于或等于10万元时,奖金可提10%: 利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可可提成7.5%: 20万到 ...
- 代码实现:企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%; 利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可可提成7.5%; 20万到40万之间时,高于20万元的部分,可提成5%;40万到60万之间时高于40万元的部分,可提成3%; 60万到100万之间时,高于60万元的部分,可提成1.5%,高于100万元时,超过100万元
import java.util.Scanner; /* 企业发放的奖金根据利润提成.利润(I)低于或等于10万元时,奖金可提10%: 利润高于10万元,低于20万元时,低于10万元的部分按10%提成 ...
- UVA 246 - 10-20-30 (模拟+STL)
UVA 246 - 10-20-30 题目链接 题意:给52张的扑克堆,先从左往右发7张牌,之后连续不断从左往右发7张牌,假设有牌堆形成了下面3种情况(按顺序推断): 1.头两张+尾一张和为10或20 ...
- 给定整数a1、a2、a3、...、an,判断是否可以从中选出若干个数,使得它们的和等于k(k任意给定,且满足-10^8 <= k <= 10^8)。
给定整数a1.a2.a3.....an,判断是否可以从中选出若干个数,使得它们的和等于k(k任意给定,且满足-10^8 <= k <= 10^8). 分析:此题相对于本节"寻找满 ...
- gitlab 迁移、升级打怪之路:8.8.5--> 8.10.8 --> 8.17.8 --> 9.5.9 --> 10.1.4 --> 10.2.5
gitlab 迁移.升级打怪之路:8.8.5--> 8.10.8 --> 8.17.8 --> 9.5.9 --> 10.1.4 --> 10.2.5 gitlab 数据 ...
- 我的新计划 《2Dof Racing Simulator》2014/3/9 20:30:00
最近好久都没来网站上了,也没心思和时间去弄VellLock和升级V&View了.一直在蕴量这做一件大玩意. 最近一直都很忙,忙着做数电课设,还有各种实验,可是我的心思不在这些东西上,当然除了数 ...
随机推荐
- julia/pyplot 绘图加入标签和标题
julia 调用matplotlib.pyplot 须要先using pycall 先安装pycall Pkg.add("PyCall") 然后吧. . . 上代码把:(应该是通俗 ...
- Hadoop-2.6.0上的C的API訪问HDFS
在通过Hadoop-2.6.0的C的API訪问HDFS的时候,编译和执行出现了不少问题,花费了几天的时间,上网查了好多的资料,最终还是把问题给攻克了 參考文献:http://m.blog.csdn.n ...
- Outlook中设置会议的提醒
https://support.office.com/en-us/article/Set-or-remove-reminders-7a992377-ca93-4ddd-a711-851ef359792 ...
- Mysql主从级联复制
场景1 如果主节点已经运行了一段时间,且有大量数据时,如何配置并启动slave节点 通过备份恢复数据至从服务器· 复制起始位置为备份时,二进制日志文件及其POS: Mater 设置 1) 修改配置文件 ...
- OpenCV —— ROI
通过 cvResetImageRoI 函数释放ROI是非常重要的,否则其他操作将默认在ROI区域中进行 通过巧妙的使用widthStep,可以达到同ROI一样的效果 —— 如果想设置和保持一副图像的多 ...
- node内容
什么是node? node是一门技术,并不是一门新的语言.是JavaScript运行环境. node在解析JavaScript,依靠的是什么? 依靠的是谷歌浏览器中的v8引擎,所以不需要考虑兼容性,n ...
- C++中的纯虚函数
---恢复内容开始--- 在C++中的一种函数申明被称之为:纯虚函数(pure virtual function).它的申明格式如下 class CShape { public: ; }; 在什么情况 ...
- SNMP介绍,OID及MIB库
http://blog.sina.com.cn/s/blog_4502d59c0101fcy2.html
- 玩转阿里云server——安装WebserverTomcat7
1. 以root用户身份登录阿里云server 2. 使用apt-get install安装Tomcat7 sudo apt-get install tomcat7 3.安装后.Tomcat在启动时报 ...
- [React] Create a queue of Ajax requests with redux-observable and group the results.
With redux-observable, we have the power of RxJS at our disposal - this means tasks that would other ...