- Bridge Bidding的C语言的解法
Bridge is a very complicated card game, and the bidding part is particularly difficult to master. The bidding is made even more difficult because players use different bidding conventions (meanings assigned to bids). In this problem, you are asked to write a program that suggests the first bid that should be made. The bidding conventions described below are simplified from those used by a certain person who shall remain nameless.
A bridge hand consists of 13 cards. Each card has a suit (spades, hearts, diamonds, or clubs) and a rank (A, K, Q, J, T, 9, 8, 7, 6, 5, 4, 3, 2). Here, the letter T denotes the card whose rank is 10. Before making a bid, an experienced bridge player studies the number of high card points (hcp) in the hand, as well as the distribution (the number of cards in each suit). The hcp contributed by each card is completely determined by its rank as follows:
For example, if the hand is:
Spades: A, 2
Hearts: K, J, T, 9, 2
Clubs: K, Q, 7, 4, 3
Then this hand has 13 hcp and a distribution of 5-5-2-1 (the distribution is usually listed in non-increasing order). A balanced distribution is any one of 4-3-3-3, 4-4-3-2, and 5-3-3-2.
In bridge, an opening bid is either "pass" or consists of a level (1-7) and a trump suit. The trump suits are no trump, spades, hearts, diamonds, clubs ranked in decreasing order. Once a hand has been evaluated, the player applies the following list of (simplified) rules to determine the appropriate opening bid. In cases where multiple rules apply, the first one that applies should be used. An "x" in a distribution can be substituted with any non-negative number. Multiple "x"s in a distribution are not necessarily the same.
- With at least 10 hcp and a y-x-x-x distribution (y >= 8), bid the suit with y cards at the 4 level. This is known as a preemptive bid.
- With 10-13 hcp and a 7-x-x-x distribution, bid the suit with 7 cards at the 3-level. This is known as a preemptive bid.
- With 8-9 hcp and a y-x-x-x distribution (y >= 7), bid the suit with y cards at the 2-level if the y-card suit is Spades or Hearts. This is known as a "weak-two" bid.
- With 8-11 hcp and a 6-x-x-x distribution, in which Spades or Hearts is one of the 6-card suits, bid the higher rank suit at the 2 level. This is known as a "weak-two" bid.
- With 11-15 hcp, a distribution of 4-4-4-1 or 5-4-4-0, and at least 4 spades, bid Diamonds at the 2 level. This is called the "Mini Roman Convention".
- With 15-17 hcp and a balanced distribution, bid No Trump at the 1 level provided that at least 3 suits are "stopped." A suit is considered stopped if the suit contains at least one of the following:
a K and one other;
a Q and two others; or
a J and three others;
- With 20-22 hcp and a balanced distribution, bid No Trump at the 2 level. 8.With at least 22 hcp, bid Clubs at the 2 level.
With 13-16 hcp:
a. If there is a 5-card or longer suit in Spades or Hearts, bid it at the 1 level. If both bids are possible, bid the longer suit. If both suits have the same length, bid the higher ranking suit.
b. Without a 5-card suit in Spades or Hearts, bid the longer of Diamonds or Clubs at the 1 level (whichever one has the most number of cards) . If there is a tie, bid the higher ranking suit.
With at least 17 hcp, bid the longest suit at the 1 level. If there is a tie, bid the lowest ranking suit. This is known as a "reverse".
If none of the rules above is applicable, bid Pass.
In the example above, rule 9a applies and a bid of 1 Hearts should be made.
The input consists of a number of cases. The bridge hand for each case is specified on one line, with a single space separating each of the 13 cards in the hand. Each card is given as a two-character string. The first letter is the suit (S, H, D, C) and the second character is the rank (A, K, Q, J, T, 9, 8, 7, 6, 5, 4, 3, 2). The end of input is terminated by end-of-file.
For each case, print the hand number (starting from 1), followed by a colon and a space, and then the suggested bid on a single line (see below for the exact format). Each bid is either "Pass" or a level and a suit ("No Trump", "Spades", "Hearts", "Diamonds", "Clubs") separated by a single space.
SA S2 HK HJ HT H9 H2 D3 CK CQ C7 C4 C3
SK SQ HT H8 H4 CA CQ CT C5 DK DQ DJ D8
SA SK SQ S3 S2 HT D7 D9 CA CK CQ C7 C5
Hand #1: 1 Hearts
Hand #2: 1 No Trump
Hand #3: 1 Clubs
- 博客 在中国程序员是青春饭吗？
- 博客 程序员请照顾好自己，周末病魔差点一套带走我。
- 博客 C++(数据结构与算法)78:---分而治之
- 博客 springboot+jwt实现token登陆权限认证
- 博客 技术大佬：我去，你写的 switch 语句也太老土了吧
- 博客 win10暴力查看wifi密码
- 博客 女程序员，为什么比男程序员少？？？
- 博客 副业收入是我做程序媛的3倍，工作外的B面人生是怎样的？
- 博客 MySQL数据库面试题（2020最新版）
- 博客 如果你是老板，你会不会踢了这样的员工？
- 博客 我入职阿里后，才知道原来简历这么写
- 博客 程序员写出这样的代码，能不挨骂吗？
- 博客 带了6个月的徒弟当了面试官，而身为高级工程师的我天天修Bug......
- 博客 优雅的替换if-else语句
- 博客 !大部分程序员只会写3年代码
- 博客 离职半年了，老东家又发 offer，回不回？
- 博客 2020阿里全球数学大赛：3万名高手、4道题、2天2夜未交卷
- 博客 为什么你不想学习？只想玩？人是如何一步一步废掉的
- 博客 男生更看重女生的身材脸蛋，还是思想？
- 博客 为什么程序员做外包会被瞧不起？
- 博客 当HR压你价，说你只值7K，你该怎么回答？
- 博客 面试：第十六章：Java中级开发
- 博客 早上躺尸，晚上干活：硅谷科技公司这么流行迟到？
- 博客 面试阿里p7，被按在地上摩擦，鬼知道我经历了什么？
- 博客 Python爬虫，高清美图我全都要（彼岸桌面壁纸）
- 博客 无代码时代来临，程序员如何保住饭碗？
- 博客 面试了一个 31 岁程序员，让我有所触动，30岁以上的程序员该何去何从？
- 博客 大三实习生，字节跳动面经分享，已拿Offer
- 博客 程序员垃圾简历长什么样？
- 博客 Java岗开发3年，公司临时抽查算法，离职后这几题我记一辈子