• 洛谷 P1148 拱猪计分


    【题目链接】

    洛谷 P1148 拱猪计分
    题目补充说明:
    D10与D11都可能出现,D10作用与D11相同。如果D10与D11同时出现,只算有1张D牌。
    当H1~H13都有,但D或S只有1个时:D牌作用:-100分,S牌作用:+100分。

    【题目考点】

    1. 模拟

    【解题思路】

    根据题意直接模拟
    设布尔数组h,用来记录是否有牌Hi。设布尔变量s12, d10, c10,表示是否存在S、D和C牌。
    按照题目描述,根据该玩家手中存在的牌的种类,计算分数。
    具体解释见注释。

    【题解代码】

    解法1:模拟
    #include 
    #define INF 0x3f3f3f3f
    using namespace std;
    #define N 105
    int proc(int n)//n:有n张牌 
    {
    	string s;
    	int score = 0;
    	bool h[20] = {}, s12 = false, d10 = false, c10 = false;//h[1]~p[13]:H1~H13 是否存在  
    	int pt[15] = {0,-50,-2,-3,-4,-5,-6,-7,-8,-9,-10,-20,-30,-40};//pt[i]:牌Hi的分数 
    	for(int i = 1; i <= n; ++i)
    	{
    		cin >> s;
    		if(s[0] == 'H')
    			h[stoi(s.substr(1))] = true;//标记h[i]为真 
    		else if(s[0] == 'S')
    			s12 = true;
    		else if(s[0] == 'D')//D10与D11都认为是D10 
    			d10 = true;
    		else if(s[0] == 'C')
    			c10 = true;
    	}
    	bool hasAllH = true;//是否有所有13张H牌 
    	for(int i = 1; i <= 13; ++i)
    		if(h[i] == false)
    		{
    			hasAllH = false;
    			break;
    		}
    	if(hasAllH)//如果有全部13张红心牌 
    	{
    		score = 200;//全红心牌加200 
    		if(s12 && d10)//如果同时有S牌和D牌 
    			score = 500;
    		else if(s12)//如果只有S,那么减100 
    			score -= 100;
    		else if(d10)//如果只有D,那么加100 
    			score += 100;
    		if(c10)//如果有C牌,分数乘2 
    			score *= 2;
    	}
    	else//如果并没有持有所有的红心牌 
    	{
    		for(int i = 1; i <= 13; ++i)
    			if(h[i])//如果有Hi这张牌 
    				score += pt[i];
    		if(score == 0 && !s12 && !d10 && c10)//如果只有C牌没有其它牌 
    			score += 50;
    		else
    		{
    			if(s12)//如果有S牌 
    				score -= 100;
    			if(d10)//如果有D牌 
    				score += 100;
    			if(c10)//如果有C牌 
    				score *= 2;
    		}
    	}
    	return score;
    }
    int main()
    {
    	bool isOver;
    	int n, score[5];//score[i]:某局游戏后第i名玩家的得分 
    	while(true)
    	{
    		isOver = true;
    		for(int i = 1; i <= 4; ++i)
    		{
    			cin >> n;
    			if(n != 0)
    				isOver = false;
    			score[i] = proc(n);//求出第i名玩家的得分 
    		}
    		if(isOver)//如果输入4个0,则跳出 
    			break;
    		for(int i = 1; i <= 4; ++i)//输出每位玩家的得分 
    			cout << (score[i] > 0 ? "+" : "") << score[i] << ' ';//如果是正数则输出正号 
    		cout << endl;
    	}
    	return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
  • 相关阅读:
    Flink学习20:聚合算子(sum,max,min)
    详解Java代理
    ORB-SLAM2从理论到代码实现(十):LoopClosing程序详解
    dbeaver连接MySQL数据库及错误Connection refusedconnect处理
    kkfile配置https预览文件
    Leetcode79单词搜索
    ssm好乐买超市管理系统毕业设计-附源码111743
    Oracle数据库开发者工具
    C语言——二维数组作为函数的参数,求二维数组的最大值
    YOLOv5识别图像内苹果和香蕉
  • 原文地址:https://blog.csdn.net/lq1990717/article/details/133551928