DreamGrid has just found a set of Mahjong with suited tiles and a White Dragon tile in his pocket. Each suited tile has a suit (Character, Bamboo or Dot) and a rank (ranging from 1 to ), and there is exactly one tile of each rank and suit combination.
Character tiles whose rank ranges from 1 to 9
Bamboo tiles whose rank ranges from 1 to 9
Dot tiles whose rank ranges from 1 to 9
White Dragon tile
As DreamGrid is bored, he decides to play with these tiles. He first selects one of the suited tiles as the “lucky tile”, then he picks tiles from the set of tiles and sorts these tiles with the following rules:
•The “lucky tile”, if contained in the tiles, must be placed in the leftmost position.
•For two tiles and such that neither of them is the “lucky tile”, if
◦ is a Character tile and is a Bamboo tile, or
◦ is a Character tile and is a Dot tile, or
◦ is a Bamboo tile and is a Dot tile, or
◦ and have the same suit and the rank of is smaller than the rank of ,
then must be placed to the left of .
White Dragon tile is a special tile. If it’s contained in the tiles, it’s considered as the original (not-lucky) version of the lucky tile during the sorting. For example, consider the following sorted tiles, where “3 Character” is selected as the lucky tile. White Dragon tile, in this case, is considered to be the original not-lucky version of “3 Character” and should be placed between “2 Character” and “4 Character”.
As DreamGrid is quite forgetful, he immediately forgets what the lucky tile is after the sorting! Given sorted tiles, please tell DreamGrid the number of possible lucky tiles.
Input
There are multiple test cases. The first line of the input contains an integer , indicating the number of test cases. For each test case:
The first line contains two integers and (, ), indicating the number of sorted tiles and the maximum rank of suited tiles.
For the next lines, the -th line describes the -th sorted tile counting from left to right. The line begins with a capital letter (), indicating the suit of the -th tile:
•If , then an integer () follows, indicating that it’s a Character tile with rank ;
•If , then an integer () follows, indicating that it’s a Bamboo tile with rank ;
•If , then an integer () follows, indicating that it’s a Dot tile with rank ;
•If , then it’s a White Drangon tile.
It’s guaranteed that there exists at least one possible lucky tile, and the sum of in all test cases doesn’t exceed .
Output
For each test case output one line containing one integer, indicating the number of possible lucky tiles.
Sample Input
4
3 9
C 2
W
C 4
6 9
C 2
C 7
W
B 3
B 4
D 2
3 100
C 2
W
C 9
3 9
C 1
B 2
D 3
Sample Output
2
4
7
25
Hint
For the first sample, “2 Character” and “3 Character” are possible lucky tiles.
For the second sample, “8 Character”, “9 Character”, “1 Bamboo” and “2 Bamboo” are possible lucky tiles.
Author: CHEN, Shihan
Source: The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple
我是不是应该说,好题…
卡了2个小时,非常的难过,居然被非算法的铜牌题卡住。
题意:
给你一个有序的麻将序列,有三种牌面和一个白板。你有3*m个麻将,问幸运麻将有几种可能,幸运麻将应该放在最左端且不能影响给出序列的有序性。注,白板视作和幸运麻将相同。
注意给的序列不是有序的情况,那么第一个麻将必定为幸运麻将!(卡死我队,罪不容诛)
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<string>
#include<map>
#include<queue>
#include<vector>
using namespace std;
#define ll long long int
#define INF 0x3f3f3f3f
const int maxn = 1e5 + 10;
char s[maxn];
int a[maxn];
int main()
{
int T;
scanf("%d", &T);
while (T--) {
int n, m;
scanf("%d%d", &n, &m); int flag = 0;
for (int i = 1; i <= n; i++) {
getchar();
scanf("%c", &s[i]);
if (s[i] == 'W') { flag = i; }
else scanf("%d", &a[i]);
}
int ans = 0;
if (n >= 2) {
int tmp = 0;
if (s[1] == 'C') {
if (a[1] > a[2]&&s[2]=='C'){
tmp = 1;
}
}
else if (s[1] == 'B') {
if (s[2] == 'C') {
tmp = 1;
}
else if (s[2] == 'B') {
if (a[2] < a[1]) {
tmp = 1;
}
}
}
else if (s[1] == 'D') {
if (s[2] == 'C' || s[2] == 'B') tmp = 1;
else if (s[2] == 'D') {
if (a[1] > a[2]) tmp = 1;
}
}
if (tmp) {
printf("1\n"); continue;
}
}
if (flag == 0) {
ans = 3 * m - n + 1;
}
else if (flag == 1) {
if (n == 1) ans = 3 * m;
else {
if (s[2] == 'C') {
ans = a[2]-1;
}
else if (s[2] == 'B') {
ans = a[2] + m-1;
}
else {
ans = a[2] + 2 * m - 1;
}
}
}
else if (flag == n) {
if (s[n - 1] == 'C') {
ans = m - a[n - 1] + m + m;
}
else if (s[n - 1] == 'B') {
ans = m - a[n - 1] + m;
}
else if (s[n - 1] == 'D') {
ans = m - a[n - 1];
}
if (n == 2) ans++;
}
else {
if (s[flag - 1] == 'C') {
if (s[flag + 1] == 'C') {
ans = a[flag+1] - a[flag - 1]-1;
}
else if (s[flag + 1] == 'B') {
ans = m - a[flag - 1] + a[flag + 1] - 1;
}
else {
ans = 2 * m - a[flag - 1] + a[flag + 1] - 1;
}
}
else if (s[flag - 1] == 'B') {
if (s[flag + 1] == 'B') {
ans = a[flag + 1] - a[flag - 1] - 1;
}
else if (s[flag + 1] == 'D') {
ans = m - a[flag - 1] + a[flag + 1] - 1;
}
}
else
{
ans = a[flag + 1] - a[flag - 1] - 1;
}
if (flag == 2)
ans++;
}
printf("%d\n", ans);
}
return 0;
}
//_CRT_SECURE_NO_WARNINGS
1992




被折叠的 条评论
为什么被折叠?



