C - Cued In Gym - 101606C(模拟水题)

Snooker is a cue sport played by two players on a rectangular table. The players take turns topot a series of balls of varying colours, where each colour represents a distinct point value forpotting the ball.A player may pot any ball on the table initially, however any subsequent shots must follow apattern: if the previous ball was red, the next ball must be another colour; otherwise, if there arestill red balls left, the next ball must be red.Balls of any colour other than red are initially replaced on the table every time they are potted,and may be used again to score more points. The balls stop being replaced once all of the redballs have been potted.The values of each coloured ball are:


Snooker players are respected universally for their prowess in mental arithmetic. One sweepingglance across the table is enough to tell an experienced contestant how much they could score.For newer players, however, this is a challenge. Write a program to help calculate a score for agiven list of balls remaining on the table.

Input

    • one line containing the integers N (1 ≤ N ≤ 21), the number of balls remaining on thetable.

    • N further lines, each containing the colour of one of the balls on the table.The list of balls will not be ordered in any way and will contain at most one of each of yellow,green, brown, blue, pink and black.

Output

    Output the largest possible score the player can make.

题目:斯诺克,红球与色球交替进,只要桌上还有红球,进洞的色球就可以重新拿回桌上,直到没有红球为止,那么要得到最多的分数就要先进色球且存在的分值最高的色球,与红球交替进球直到没有红球。再将所有色球打进得分就可以。

#include <iostream>
using namespace std;
int nr=0,nb=0,np=0,nbl=0,nbr=0,ng=0,ny=0;
int main()
{
	int res=0;
	int n;
	cin>>n;
	string s;
	for(int i=0;i<n;i++){
		cin>>s;
		if(s=="red")	nr++;    //红球个数
		else if(s=="black")	nb++;    //黑球个数
		else if(s=="pink")	np++;    //粉球个数
		else if(s=="blue")	nbl++;    //黑球个数
		else if(s=="brown")	nbr++;    //棕球个数
		else if(s=="green")	ng++;    //绿球个数
		else if(s=="yellow")	ny++;    //黄球个数
	}
//	cout<<nr<<" "<<nb<<" "<<np<<" "<<nbl<<" "<<nbr<<" "<<ny<<endl;
	if(nr){    //选取存在的分数最高的色球与红球交替进球,直到红球个数为0
		if(nb){
			res+=8*nr;
		}
		else if(np){
			res+=7*nr;
		}
		else if(nbl){
			res+=6*nr;
		}
		else if(nbr){
			res+=5*nr;
		}
		else if(ng){
			res+=4*nr;
		}
		else if(ny){
			res+=3*nr;
		}
	}
	res+=nb*7+np*6+nbl*5+nbr*4+ng*3+ny*2;    //将场上色球的分数加上
	if(!nb&&!np&&!nbl&&!nbr&&!ng&&!ny)	res=1;    //如果场上没有色球,那么只能进一颗红球
	cout<<res<<endl;
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值