博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hoj2353-Card Hands
阅读量:5051 次
发布时间:2019-06-12

本文共 2443 字,大约阅读时间需要 8 分钟。

Card Hands

My Tags   (Edit)
  Source : 
  Time limit : 2 sec   Memory limit : 64 M

Submitted : 204, Accepted : 49

Jim is writing a program for statistically analyzing card games. He needs to store many different card hands in memory efficiently. Each card has one of four suits and one of thirteenvalues. In his implementation, each hand is stored as a linked list of cards in a canonical order: the cards are first ordered by suit: all the clubs come first, followed by all the diamonds, then all the hearts, and finally the spades. Within each suit, the cards are ordered by value: A, 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K. Each hand contains at most one of any given card.

The card hands are using lots of memory. Jim therefore decides to try a more efficient representation. Whenever any two lists share a common tail, they can be updated to share one copy of the tail, and the other copy can be discarded. This process can be repeated until no two lists share a common tail.

Your job is to tell Jim how many linked list nodes he needs to store all the card hands.

Input

The input contains several test cases followed by a line containing 0. The first line of each case contains the number of card hands. Each subsequent line describes a card hand. It starts with a number indicating the number of cards in the hand. The cards follow, separated by spaces, in the canonical order defined above. For each card, the value is given first, followed by the suit (C, D, H, or S). There are at most 100,000 cards in all hands.

Output

For each test case, output a line containing the number of linked list nodes needed to store all the lists.

Sample Input

33 7D AH 5S4 9C 3D 4D 5S2 AH 5S0

Sample Output

 

6 地址: 题意:给出n副牌,有顺序,如果两副牌最后一张或最后几张完全一样,那么这张牌只记一次,问有多少张牌。 要是只看题真的很难理解他在干什么,但是如果看了trie树的话就容易理解了,就是把每组输入从后往前构成一棵trie树,前缀一样的只需要一个节点,输出总结点数。理解了题意就知道了,做法就是先输入,然后倒序建立trie树,最后输出sz-1即可。。。。。貌似很简单的样子,但是debug了一晚上,一直超时,最后在伟大的室友帮助下,终于发现是memset这个东西每次要把10^5的数组清零占了太多时间,不能随便用啊,还有就是我不细心,犯一些各种小毛病,我都想放弃了的时候,终于ac了(室友的debug能力好强,要是我自己,这道题一定又无限wa下去。。.)
#include 
#include
#include
#include
#include
#include
#include
#include
using namespace std;const int MaxNode=100000;int chd[MaxNode][100];//存储节点编号int sz;//节点数int s[100000];int n;void insert() //插入一个串{ int cur = 1; for (int i = 0; i
 

 

 

转载于:https://www.cnblogs.com/2860359561snail/p/3231722.html

你可能感兴趣的文章
Windows Phone开发(7):当好总舵主 转:http://blog.csdn.net/tcjiaan/article/details/7281421...
查看>>
VS 2010打开设计器出现错误
查看>>
SQLServer 镜像功能完全实现
查看>>
Vue-详解设置路由导航的两种方法
查看>>
一个mysql主从复制的配置案例
查看>>
大数据学习系列(8)-- WordCount+Block+Split+Shuffle+Map+Reduce技术详解
查看>>
dvwa网络渗透测试环境的搭建
查看>>
Win8 安装VS2012 和 Sql Server失败问题
查看>>
过点(2,4)作一直线在第一象限与两轴围成三角形,问三角形面积的最小值?...
查看>>
java aes CBC的填充方式发现
查看>>
使用ionic cordova build android --release --prod命令打包报有如下错误及解决方法
查看>>
BZOJ 2338 HNOI2011 数矩形 计算几何
查看>>
关于页面<!DOCTYPE>声明
查看>>
【AS3代码】播放FLV视频流的三步骤!
查看>>
C++标准库vector使用(更新中...)
查看>>
cocos2d-x 2.2.6 之 .xml文件数据读取
查看>>
枚举的使用
查看>>
BZOJ 1531 二进制优化多重背包
查看>>
BZOJ 2324 (有上下界的)费用流
查看>>
python3基础06(随机数的使用)
查看>>