【codechef】 Chef and Piano Scales (简单题)
来源:互联网 发布:方正飞腾软件官方下载 编辑:程序博客网 时间:2024/05/17 11:59
Recently, Chef got obsessed with piano. He is a just a rookie in this stuff and can not move his fingers from one key to other fast enough. He discovered that the best way to train finger speed is to play scales.
There are different kinds of scales which are divided on the basis of their interval patterns. For instance, major scale is defined by pattern T-T-S-T-T-T-S, where ‘T’ stands for a whole tone whereas ‘S’ stands for a semitone. Two semitones make one tone. To understand how they are being played, please refer to the below image of piano’s octave – two consecutive keys differ by one semitone.
If we start playing from first key (note C), then we’ll play all white keys in a row (notes C-D-E-F-G-A-B-C – as you can see C and D differ for a tone as in pattern, and E and F differ for a semitone).
This pattern could be played some number of times (in cycle).
Each time Chef takes some type of a scale and plays using some number of octaves. Sometimes Chef can make up some scales, so please don’t blame him if you find some scale that does not exist in real world.
Formally, you have a set of 12 keys (i.e. one octave) and you have N such sets in a row. So in total, you have 12*N keys. You also have a pattern that consists of letters 'T' and 'S', where 'T' means move forward for two keys (from key x to key x + 2, and 'S' means move forward for one key (from key x to key x + 1).
Now, you can start playing from any of the 12*N keys. In one play, you can repeat the pattern as many times as you want, but you cannot go outside the keyboard.
Repeating pattern means that if, for example, you have pattern STTST, you can play STTST as well asSTTSTSTTST, as well as STTSTSTTSTSTTST, as well as any number of repeating. For this pattern, if you choose to repeat it once, if you start at some key x, you'll press keys: x (letter 'S')-> x + 1 (letter 'T')-> x + 3 (letter 'T')-> x + 5 (letter 'S') -> x + 6 (letter 'T')-> x + 8. Also 1 ≤ x, x + 8 ≤ 12*N so as to avoid going off the keyboard.
You are asked to calculate number of different plays that can be performed. Two plays differ if and only if they start at different keys or patterns are repeated different number of times.
Input
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
First line of each test case contains scale’s pattern – string s consisting of letters ‘T’ and ‘S’ only.
Second line contains one integer N – number of octaves he’ll be using.
Output
For each test case output a single number in a line corresponding to number of different scales he’ll play.
Constraints
- 1 ≤ T ≤ 105
- 1 ≤ |S| ≤ 100
- 1 ≤ n ≤ 7
Subtasks
Subtask 1: T < 10 4, N = 1
Subtask 2: No additional constraints.
Example
Input:2 TTTT1TTSTTTS3Output:436
Explanation
Example case 1. In the first case there is only one octave and Chef can play scale (not in cycle each time) starting with notes C, C#, D, D# - four together.
简单题,但是题目不容易读懂啊╮(╯▽╰)╭
http://www.codechef.com/APRIL15/problems/PIANO1/
#include<stdio.h>int main(){ int t, n,i,scales,res; char arr[101]; scanf("%d", &t); while(t--) { scanf("%s", arr); scanf("%d", &n); n=12*n; scales=0; for(i=0;arr[i]!='\0';i++) { if(arr[i]=='S') scales+=1; else scales+=2; } res=0; for(i=scales;i<n;i+=scales) { res+=n-i; } printf("%d\n", res); } return 0;}
- 【codechef】 Chef and Piano Scales (简单题)
- 【codechef】Chef and A Large Permutation(技巧题)
- codechef(MAY15)第三题Chef and Prime Divisors
- 【codechef】Chef and Strange Formula(找规律,灵活题)
- 【codechef】Chef and Polygons(灵活题,坑题)
- CodeChef:Chef and Problems(分块 & 二分)
- CodeChef:Chef and Subsequences(思维 & dfs)
- CodeChef Chef and Segments
- codechef Chef and sequence
- codechef Chef and Swaps
- Codechef Chef and Reversing
- Codechef Chef and Frogs
- Codechef Chef and Churu
- 【CodeChef】 Chef and Stones
- 【CodeChef】Chef and Interview
- codechef Chef and Churu
- codechef Chef and easy problem
- codechef Chef and Left-Right
- RSN-WLAN学习
- 验证码类
- 数据库优化
- [图像]畸变校正详解
- 在Android library中不能使用switch-case语句报错及解决方案
- 【codechef】 Chef and Piano Scales (简单题)
- Jquery表单插件ajaxForm用法详解
- 相对路径与绝对路径的区别
- SVN-CleanUp失败,提示“svn cleanup failed–previous operation has not finished"
- eclipse 改变联网方式 利用代理服务器 Network Connections
- 对SQL的优化
- android SDK更新入ADT离线安装
- 位排序-java版
- combox系列问题集