UVa 170 - Clock Patience
题目:Clock Patience游戏,将52张扑克牌,按时钟依次分成13组(中心一组),每组4张全都背面向上,
从中间组最上面一张牌開始。翻过来设为当前值,然后取当前值相应组中最上面的背过去的牌翻过来。
取这个值为新的当前值,直到不能翻拍游戏结束。求结束时。翻过来的拍数以及最后翻过来的牌;
假设没看明确题目详细规则,百度玩一下就明确了。
分析:模拟,数据结构(DS)。设计13个栈,模拟就可以。
说明:注意题目给的牌的顺序是逆序的,╮(╯▽╰)╭。
#include <algorithm>
#include <iostream>
#include <stack> using namespace std; char Maps[] = "A23456789TJQK"; typedef struct _pnode
{
int value;
char color;
_pnode(int v, char c) {value = v; color = c;}
_pnode(){}
}pnode;
pnode cards[54]; int value(char ch)
{
if (ch >= '2' && ch <= '9')
return ch-'1';
if (ch == 'A') return 0;
if (ch == 'T') return 9;
if (ch == 'J') return 10;
if (ch == 'Q') return 11;
if (ch == 'K') return 12;
} int main()
{
char V,C;
while (cin >> V && V != '#') {
cin >> C;
stack<pnode> Q[13];
cards[0] = pnode(value(V), C);
for (int i = 1; i < 52; ++ i) {
cin >> V >> C;
cards[i] = pnode(value(V), C);
}
for (int i = 51; i >= 0; -- i)
Q[12-i%13].push(cards[i]); int count = 0, index = 12;
pnode now;
while (!Q[index].empty()) {
now = Q[index].top();
Q[index].pop();
index = now.value;
++ count;
} if (count < 10) cout << "0";
cout << count << "," << Maps[now.value] << now.color << endl;
}
return 0;
}
UVa 170 - Clock Patience的更多相关文章
- UVa 1637 - Double Patience(概率DP)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- ACM学习历程——UVA 127 "Accordian" Patience(栈;模拟)
Description ``Accordian'' Patience You are to simulate the playing of games of ``Accordian'' patie ...
- UVa 579 Clock Hands
水题.. 求任意时刻时针和分针的夹角,其结果在0°到180°之间. 这里又一次用到了sscanf()函数,确实很方便. 思路:我们分别求出时针和分针转过的角度,然后大的减小的,如果结果ans大于180 ...
- UVA 1637 Double Patience
题意:36张扑克,平分成9摞,两张数字一样的可以拿走,每次随机拿两张,问能拿光的概率. 解法:记忆化搜索,状态压缩.一开始我想在还没拿的时候概率是1,然后往全拿光推···样例过不去···后来觉得推反了 ...
- UVa 127 - "Accordian" Patience
题目:52张扑克,从左到右在平面上排列,按着如下规则处理: 1.按照从左到右的顺序,如果一张牌和左边的第一张或者第三张匹配,就把它放到对应的牌上面. 2.如果可以移动到多个位置,移动到最左端的牌上面. ...
- html5、canvas绘制本地时钟
效果图: 代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...
- HTML5新增Canvas标签及对应属性、API详解(基础一)
知识说明: HTML5新增的canvas标签,通过创建画布,在画布上创建任何想要的形状,下面将canvas的API以及属性做一个整理,并且附上时钟的示例,便于后期复习学习!Fighting! 一.标签 ...
- 数学期望和概率DP题目泛做(为了对应AD的课件)
题1: Uva 1636 Headshot 题目大意: 给出一个000111序列,注意实际上是环状的.问是0出现的概率大,还是当前是0,下一个还是0的概率大. 问题比较简单,注意比较大小: A/C & ...
- canvas 模拟时钟
<meta charset="utf-8"> <canvas width="1000" height="1000" id= ...
随机推荐
- java中与运算,或运算,异或运算,取反运算
//与运算 & 规则 :都为1时才为1 System.out.println( 7 & 9); /* * 7二进制 0111 ...
- sql server drop login failed
https://stackoverflow.com/questions/37275/sql-query-for-logins https://www.mssqltips.com/sqlserverti ...
- Getting started with ASP.NET Core MVC and Visual Studio
This tutorial will teach you the basics of building an ASP.NET Core MVC web app using Visual Studio ...
- 【POJ 4007】 Flood-it!
[题目链接] http://poj.org/problem?id=4007 [算法] IDA* [代码] #include <algorithm> #include <bitset& ...
- TensorFlow——分布式的TensorFlow运行环境
当我们在大型的数据集上面进行深度学习的训练时,往往需要大量的运行资源,而且还要花费大量时间才能完成训练. 1.分布式TensorFlow的角色与原理 在分布式的TensorFlow中的角色分配如下: ...
- 判断输入的值是否为Double
using System; using System.Collections.Generic; using System.Text; namespace TDRFactory { public cla ...
- webpack打包大概流程
webpack 步骤 1. 新建一个webpack.config.prod.js 2. 压缩bundle.js和index.html //设置为生产环境 new webpack.DefinePlugi ...
- background-attachment css3属性
<style type="text/css"> body{ margin: 0; } .zhan{ width: 100%; height: 500px; backgr ...
- 多项式拟合的cpp实现
当我们拥有一组散点图数据时,通常更愿意看到其走势. 对现有数据进行拟合,并输出拟合优度是常用的方法之一. 拟合结果正确性的验证,可以使用excel自带的功能. 下面是c++代码的实现: #ifndef ...
- sphinx with discuz
安装sphinx: sudo apt-get install sphinxsearch 配置: source discuz { type = mysql sql_host = xx.xx.xx.xx ...