广联达笔试 广联达秋招 广联达笔试题 0923
笔试时间:2025年9月23日
往年笔试合集:
第一题:斗地主出牌提示
斗地主牌型规则:发牌者将牌平均分给三个玩家,剩下3张牌放在桌面上作为底牌,为地主所有。牌的大小顺序从大到小为:2、A、K、Q、J、10、9、8、7、6、5、4、3。一副牌每张牌各4张。出牌时按座次顺时针出牌,每轮出牌必须按上家牌型出牌且大于上家牌面值。若出现两个玩家均放弃出牌,则由牌面最大的玩家开启新一轮出牌。
出牌规则:
- 顺子出牌,牌面值连续且大于4张以上,如4 5 6 7 8
- 炸弹出牌,同牌面值4张牌同时出牌,如K K K K,炸弹出牌可大于任意顺子牌型
- 牌面大小按2、A、K、Q、J、10、9、8、7、6、5、4、3递减。例如:单张牌型4 > 3;Q > J;顺子牌型5 6 7 8 9 > 3 4 5 6 7,炸弹牌型4 4 4 4 > 3 3 3 3 > 5 6 7 8 9
- 其他牌型规则不允许出牌
要求:按照当前玩家手中牌型,并结合当前出牌牌面值给出类似棋牌游戏中提示功能,要求提示返回玩家手中最小可出牌型组合,以列表表示。仅限当前牌面同牌型出牌或大于当前牌型的炸弹,如没有牌型可出则返回空。
输入描述
用14表示A,用15表示2,用11表示J,用12表示Q,用13表示K。10也可组成顺子。
- 第一行为任一时刻玩家手中的牌型,未洗牌
- 第二行为当前出牌轮次最新出牌牌型,用于决定玩家是否可出牌,仅限定顺子出牌
输出描述
需要输出当前玩家手中牌型最小的组合
样例输入
14,2,4,5,7,2,5,9,7,10,11,12,12,13,14,2,10,8,7
6,7,8,9,10
样例输出
[7, 8, 9, 10, 11]
参考题解
解题思路:
- 读取和整理手牌,统计每张牌的数量
- 读取上家出的牌,判断是否为炸弹
- 寻找能出的牌: 如果上家出炸弹,只能出更大的炸弹如果上家出顺子,优先找更大的顺子,找不到再考虑炸弹
- 找到最小的可出牌型组合
C++:
#include <bits/stdc++.h>
using namespace std;
vector<int> findBestPlay(vector<int>& cardCounts, vector<int>& uniqueSortedCards, vector<int>& lastPlay) {
vector<int> bestPlay;
bool isLastPlayBomb = lastPlay.size() == 4 && lastPlay[0] == lastPlay[3];
vector<int> smallestStraight;
if (!isLastPlayBomb) {
int lastPlayLen = lastPlay.size();
int lastPlayRank = lastPlay[0];
for (int startCard : uniqueSortedCards) {
if (startCard > lastPlayRank) {
bool canFormStraight = true;
for (int i = 0; i < lastPlayLen; i++) {
if (cardCounts[startCard + i] == 0) {
canFormStraight = false;
break;
}
}
if (canFormStraight) {
for (int i = 0; i < lastPlayLen; i++) {
smallestStraight.push_back(startCard + i);
}
break;
}
}
}
}
vector<int> smallestBomb;
int lastBombRank = isLastPlayBomb ? lastPlay[0] : 0;
for (int rank = 3; rank <= 15; rank++) {
if (rank > lastBombRank && cardCounts[rank] >= 4) {
for (int i = 0; i < 4; i++) {
smallestBomb.push_back(rank);
}
break;
}
}
if (isLastPlayBomb) {
if (!smallestBomb.empty()) {
bestPlay = smallestBomb;
}
} else {
if (!smallestStraight.empty()) {
bestPlay = smallestStraight;
} else if (!smallestBomb.empty()) {
bestPlay = smallestBomb;
}
}
return bestPlay;
}
int main() {
string line;
getline(cin, line);
vector<int> cardCounts(18, 0);
set<int> uniqueCardsSet;
stringstream ss(line);
string token;
while (getline(ss, token, ',')) {
int card = stoi(token);
cardCounts[card]++;
uniqueCardsSet.insert(card);
}
vector<int> uniqueSortedCards(uniqueCardsSet.begin(), uniqueCardsSet.end());
sort(uniqueSortedCards.begin(), uniqueSortedCards.end());
getline(cin, line);
vector<int> lastPlay;
stringstream ss2(line);
while (getline(ss2, token, ',')) {
lastPlay.push_back(stoi(token));
}
sort(lastPlay.begin(), lastPlay.end());
vector<int> result = findBestPlay(cardCounts, uniqueSortedCards, lastPlay);
cout << "[";
for (int i = 0; i < result.size(); i++) {
if (i > 0) cout << ",";
cout << result[i];
}
cout << "]" << endl;
return 0;
}
Java:
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String[] handStr = scanner.nextLine().split(",");
int[] cardCounts = new int[18];
Set<Integer> uniqueCardsSet = new HashSet<>();
for (String s : handStr) {
int card = Integer.parseInt(s.trim());
cardCounts[card]++;
uniqueCardsSet.add(card);
}
List<Integer> uniqueSortedCards = new ArrayList<>(uniqueCardsSet);
Collections.sort(uniqueSortedCards);
String[] lastPlayStr = scanner.nextLine().split(",");
List<Integer> lastPlay = new ArrayList<>();
for (String s : lastPlayStr) {
lastPlay.add(Integer.parseInt(s.trim()));
}
Collections.sort(lastPlay);
List<Integer> result = findBestPlay(cardCounts, uniqueSortedCards, lastPlay);
System.out.println(result.toString().replace(" ", ""));
scanner.close();
}
private static List<Integer> findBestPlay(int[] cardCounts, List<Integer> uniqueSortedCards, List<Integer> lastPlay) {
List<Integer> bestPlay = new ArrayList<>()
剩余60%内容,订阅专栏后可继续查看/也可单篇购买
2025 春招笔试合集 文章被收录于专栏
2025打怪升级记录,大厂笔试合集 C++, Java, Python等多种语言做法集合指南
查看16道真题和解析