7024: Cued In
时间限制: 1 Sec 内存限制: 128 MB
提交: 134 解决: 60
[提交] [状态] [讨论版] [命题人:admin]
题目描述
Snooker is a cue sport played by two players on a rectangular table. The players take turns to pot a series of balls of varying colours, where each colour represents a distinct point value for potting the ball.
A player may pot any ball on the table initially, however any subsequent shots must follow a pattern: if the previous ball was red, the next ball must be another colour; otherwise, if there are still 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 red balls have been potted.
The values of each coloured ball are:
Snooker players are respected universally for their prowess in mental arithmetic. One sweeping glance 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 a given list of balls remaining on the table.
输入
•one line containing the integers N (1 ≤ N ≤ 21), the number of balls remaining on the table.
•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 the largest possible score the player can make.
样例输入
5
red
black
pink
red
red
样例输出
37
来源/分类
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ff first
#define ss second
#define mk make_pair
#define inf 0x3f3f3f3f
#define lson l,mid,i<<1
#define rson mid+1,r,i<<1|1
#define sz(s) (int)(s.size())
#define abs(x) ((x)<0?-(x):(x))
#define all(s) s.begin(),s.end()
#define Mem(x,y) memset(x,y,sizeof(x))
#define lowbit(x) x&-x
#define rep(i,s,e) for(int i=s;i<=e;++i)
#define rev(i,s,e) for(int i=e;i>=s;--i)
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
const double eps = 1e-8;
const int maxn = 100;
const int mod = 1e9 + 7;
int a[maxn];
void Dmake(char *s)
{
switch(s[2])
{
case 'd': a[1]++;break;
case 'l': a[2]++;break;
case 'e': a[3]++;break;
case 'o': a[4]++;break;
case 'u': a[5]++;break;
case 'n': a[6]++;break;
default: a[7]++;
}
}
int main(void)
{
IO
int n;
cin>>n;
memset(a,0,sizeof(a));
char s[100];
while(n--)
{
cin>>s;
Dmake(s);
}
int sum=0;
for(int i=7;i>1;i--)
{
if(a[1]==0) break;
if(a[i]>0){
sum+=a[1]*(i+1);
a[1]=0;
a[i]=1;
}
}
if(a[1]>0) cout<<'1'<<endl;
else
{
for(int i=2;i<=7;i++)
sum+=a[i]*i;
cout<<sum<<endl;
}
}
/*
5
red
black
pink
pink
red
*/
/**************************************************************
Problem: 7024
User: St064
Language: C++
Result: 正确
Time:0 ms
Memory:1688 kb
****************************************************************/