Search is not available for this dataset
name
stringlengths
2
112
description
stringlengths
29
13k
source
int64
1
7
difficulty
int64
0
25
solution
stringlengths
7
983k
language
stringclasses
4 values
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
l=[0]*150 a,b,c=input().split() l[ord(a[1])]+=1 l[ord(b[1])]+=1 l[ord(c[1])]+=1 var={} var[1]=0 for i in range(120): if i==115: if var[1]<l[i]: var[1]=l[i] var[2]='s' if i==112: if var[1]<l[i]: var[1]=l[i] var[2]='p' if i==109: if var[1]<l[i]: var[1]=l[i] var[2]='m' cha=0 chb=0 n=[] m=[] if var[1]==1: print(2) else: if var[1]==2: if a[1]==var[2]: cha+=1 if b[1]==var[2]: chb+=1 if cha==1: if abs(int(a[0])-int(b[0]))==0 or abs(int(a[0])-int(b[0]))==1 or abs(int(a[0])-int(b[0]))==2: print(1) else: print(2) if c[1]==var[2]: if cha==1: if abs(int(a[0])-int(c[0]))==0 or abs(int(a[0])-int(c[0]))==1 or abs(int(a[0])-int(c[0]))==2: print(1) else: print(2) else: if abs(int(c[0])-int(b[0]))==0 or abs(int(c[0])-int(b[0]))==1 or abs(int(c[0])-int(b[0]))==2: print(1) else: print(2) else: n.append(int(a[0])) n.append(int(b[0])) n.append(int(c[0])) m.append(int(a[0])) m.append(int(b[0])) m.append(int(c[0])) n.sort() m.sort() n=list(set(n)) if len(n)==1: print(0) elif len(n)==2: print(1) else: if n[1]-n[0]==1 and n[2]-n[1]==1: print(0) elif (n[1]-n[0]==1 or n[1]-n[0]==2 or n[2]-n[1]==1 or n[2]-n[1]==2): print(1) else: print(2)
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
a=input().split() a.sort() flag1=3 if(a[0]==a[1] and a[1]==a[2]): flag1=0 elif(a[0]==a[1]): flag1=1 elif(a[1]==a[2]): flag1=1 else: flag1=2 flag2=3 if(a[0][1]==a[1][1] and a[1][1]==a[2][1]): if(int(a[1][0])-int(a[0][0])==1 and int(a[2][0])-int(a[1][0])==1): flag2=0 elif(int(a[1][0])-int(a[0][0])==1 or int(a[1][0])-int(a[0][0])==2): flag2=1 elif(int(a[2][0])-int(a[1][0])==1 or int(a[2][0])-int(a[1][0])==2): flag2=1 else: flag2=2 elif(a[0][1]==a[1][1]): if(int(a[1][0])-int(a[0][0])==1 or int(a[1][0])-int(a[0][0])==2): flag2=1 else: flag2=2 elif(a[1][1]==a[2][1]): if(int(a[2][0])-int(a[1][0])==1 or int(a[2][0])-int(a[1][0])==2): flag2=1 else: flag2=2 elif(a[0][1]==a[2][1]): if(int(a[2][0])-int(a[0][0])==1 or int(a[2][0])-int(a[0][0])==2): flag2=1 else: flag2=2 else: flag2=2 print(min(flag1,flag2))
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
from collections import defaultdict sa = input().split() groups = defaultdict(list) for el in sa: groups[el[-1]].append(int(el[0])) test_arrays = [] for i in range(1, 8): test_arrays.append([i, i+1, i+2]) min_card = 2 for elements in groups.values(): els = sorted(elements) for i in range(1, 10): count = els.count(i) if count == 3: print(0);exit() if count == 2: print(1);exit() for ta in test_arrays: m = 3 for i in ta: if i in els: m-=1 if m < min_card: min_card = m if m == 0: print(0);exit() print(min_card)
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
A = input().split() p = [0] * 10 s = [0] * 10 m = [0] * 10 #ๅˆปๅญใ‚’ไฝœใ‚‹ใฎใซไฝ•ๆžšใ„ใ‚‹ใ‹ for i in A: if i[1] == 'p': p[int(i[0])] += 1 elif i[1] == 's': s[int(i[0])] += 1 elif i[1] == 'm': m[int(i[0])] += 1 ans1 = max(max(s), max(m), max(p)) ans2 = 0 for x in p, s, m: for i in range(1, 8): #ใ‚‚ใ—1ใŒ็ซ‹ใฃใฆใ„ใŸใ‚‰ใ€sumๅ†…ใฎใƒชใ‚นใƒˆใซ1ใ‚’่ฟฝๅŠ  #้ †ๅญใงใ‚‚ๅˆปๅญใงใ‚‚้–ขไฟ‚ใชใ„ t = sum([1 for j in x[i:i+3] if j]) if t > ans2: ans2 = t print(3-max(ans1, ans2))
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
s = input().split() b = [] b.append((s[0][1], int(s[0][0]))) b.append((s[1][1], int(s[1][0]))) b.append((s[2][1], int(s[2][0]))) b.sort() if (b[0][0] == b[1][0] and b[1][0] == b[2][0]): if (b[0] == b[1] and b[1] == b[2]): print(0) elif (b[0][1] + 1 == b[1][1] and b[1][1] + 1 == b[2][1]): print(0) elif (b[0] == b[1]): print(1) elif (b[1] == b[2]): print(1) elif b[0][1] + 1 == b[1][1]: print(1) elif b[0][1] + 2 == b[1][1]: print(1) elif b[1][1] + 1 == b[2][1]: print(1) elif b[1][1] + 2 == b[2][1]: print(1) elif b[0][1] + 1 == b[2][1]: print(1) elif b[0][1] + 2 == b[2][1]: print(1) else: print(2) elif (b[0][0] != b[1][0] and b[1][0] != b[2][0] and b[2][0] != b[0][0]): print(2) elif b[0][0] == b[1][0]: if b[0] == b[1]: print(1) elif b[0][1] + 1 == b[1][1]: print(1) elif b[0][1] + 2 == b[1][1]: print(1) else: print(2) elif b[1][0] == b[2][0]: if (b[1] == b[2]): print(1) elif b[1][1] + 1 == b[2][1]: print(1) elif b[1][1] + 2 == b[2][1]: print(1) else: print(2) else: print(2)
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
#include <bits/stdc++.h> using namespace std; long long gcd(long long a_, long long b_) { if (b_ > a_) swap(b_, a_); return (b_ == 0 ? a_ : gcd(b_, a_ % b_)); } int n, arr[15][10]; char c; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(NULL); for (long long i = 0; i < 3; i++) { cin >> n >> c; if (c == 'm') { arr[n][0]++; } else if (c == 'p') { arr[n][1]++; } else { arr[n][2]++; } } for (int i = 1; i < 10; i++) { for (int j = 0; j < 3; j++) { if (arr[i][j] == 3) { cout << 0 << "\n"; return 0; } } } for (int i = 1; i < 10; i++) { for (int j = 0; j < 3; j++) { if (arr[i][j] == 1 && arr[i + 1][j] == 1 && arr[i + 2][j] == 1) { cout << 0 << "\n"; return 0; } } } for (int i = 1; i < 10; i++) { for (int j = 0; j < 3; j++) { if (arr[i][j] == 2) { cout << 1 << "\n"; return 0; } } } for (int i = 1; i < 10; i++) { for (int j = 0; j < 3; j++) { if (arr[i][j] == 1 && (arr[i + 1][j] == 1 || arr[i + 2][j] == 1)) { cout << 1 << "\n"; return 0; } } } cout << 2 << "\n"; return 0; }
CPP
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
import math import sys import collections # imgur.com/Pkt7iIf.png def ii(): return int(input()) def mi(): return map(int, input().split()) def li(): return list(map(int, input().split())) d = sorted(input().split()) n = sorted([int(x[0]) for x in d]) m = sorted([x[1] for x in d]) dic = {'s':[], 'p':[], 'm':[]} for i in d: dic[i[1]].append(int(i[0])) nr = 1 for i in dic: if len(dic[i]) == 2: if 0 < dic[i][1] - dic[i][0] <= 2: nr = 2 if len(dic[i]) == 3: if dic[i][1] - dic[i][0] == dic[i][2] - dic[i][1] == 1: nr = 3 break if 0 < dic[i][1] - dic[i][0] <= 2: nr = 2 if 0 < dic[i][2] - dic[i][1] <= 2: nr = 2 if 0 < dic[i][2] - dic[i][0] <= 2: nr = 2 mr = 1 for i in range(1, 3): if d[i] == d[i-1]: mr += 1 #print(mr, nr) print(min(3 - mr, 3 - nr))
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; const int mod = 1e9 + 7; const int maxn = 1e6 + 5; string s[3]; bool isShun1(int i, int j) { return (s[i][1] == s[j][1] && s[i][0] == s[j][0] - 1); } bool isShun2(int i, int j) { return (s[i][1] == s[j][1] && s[i][0] == s[j][0] - 2); } int main() { cin >> s[0] >> s[1] >> s[2]; sort(s, s + 3); int ans = 2; if (s[0] == s[1] && s[1] == s[2]) ans = 0; else if (s[0] == s[1] || s[1] == s[2] || s[0] == s[2]) ans = 1; if (isShun1(0, 1) || isShun1(1, 2) || isShun1(0, 2)) ans = min(ans, 1); if (isShun2(0, 1) || isShun2(1, 2) || isShun2(0, 2)) ans = min(ans, 1); if (isShun1(0, 1) && isShun1(1, 2)) ans = 0; cout << ans << '\n'; }
CPP
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
n1, n2, n3 = input().split() n1, n2, n3 = sorted([n1, n2, n3]) if ord(n1[1]) == ord(n2[1]) == ord(n3[1]): if n1 == n2 == n3 or (int(n1[0]) + 2 == int(n2[0]) + 1 == int(n3[0])): print(0) else: if n1[1] == n2[1] or n2[1] == n3[1] or n1[1] == n3[1]: if n1 == n2 or n2 == n3 or int(n1[0]) + 1 == int(n2[0]) or int(n1[0]) + 2 == int(n2[0]) or int(n2[0]) + 1 == int(n3[0]) or int(n2[0]) + 2 == int(n3[0]) or int(n1[0]) + 1 == int(n3[0]) or int(n1[0]) + 2 == int(n3[0]): print(1) else: print(2) else: print(2) elif n1[1] == n2[1] or n2[1] == n3[1] or n1[1] == n3[1]: if n2[1] == n3[1]: n1, n2 = n2, n3 if n1[1] == n3[1]: n1, n2 = n1, n3 if n1 == n2 or int(n1[0]) + 1 == int(n2[0]) or int(n1[0]) + 2 == int(n2[0]): print(1) else: print(2) else: print(2)
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
a=map(str,raw_input().split()) m=[0 for i in range(9)] p=[0 for i in range(9)] s=[0 for i in range(9)] for i in a: if i[1]=='m': m[int(i[0])-1]+=1 elif i[1]=="p": p[int(i[0])-1]+=1 else: s[int(i[0])-1]+=1 ans=2 con=0 con1=0 k=0 for i in m: k+=1 if i==3: ans=0 break if i==2: ans=min(ans,1) break if i==1: con+=1 ans=min(ans,2) if k<8: if m[k]==0: if m[k+1]!=0: con1=max(con1,2) if i==0: con1=max(con,con1) con=0 con1=max(con,con1) con=0 k=0 for i in p: k+=1 if i==3: ans=0 break if i==2: ans=min(ans,1) break if i==1: ans=min(ans,2) con+=1 if k<8: if p[k]==0: if p[k+1]!=0: con1=max(con1,2) if i==0: con1=max(con,con1) con=0 con1=max(con,con1) con=0 k=0 for i in s: k+=1 if i==3: ans=0 break if i==2: ans=min(ans,1) break if i==1: ans=min(ans,2) con+=1 if k<8: if s[k]==0: if s[k+1]!=0: con1=max(con1,2) if i==0: con1=max(con,con1) con=0 con1=max(con,con1) con=0 print min(ans,3-con1)
PYTHON
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
while True: try: a,b,c=map(str,input().split()) lis = a+b+c teli=[a,b,c] teli.sort() #print(teli) d1=int(teli[1][0])-int(teli[0][0]) d2=int(teli[2][0])-int(teli[1][0]) d3=int(teli[2][0])-int(teli[0][0]) flag, end = False, False if((d1==0 and d2==0)or(d1==1 and d2 == 1)): flag=True if(flag): if(lis.count(lis[1])==3): print("0") continue if(d1==0 or d1==1 or d1==2): if(teli[0][1]==teli[1][1]): print("1") continue if(d2==1 or d2==0 or d2==2): if(teli[1][1]==teli[2][1]): print("1") continue if(d3==0 or d3==1 or d3 == 2): if(teli[0][1]==teli[2][1]): print("1") continue print("2") except EOFError: break
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
a=[[],[],[]] s=input().split(" ") for i in range(len(s)): if(s[i][1]=='m'): a[0].append(int(s[i][0])) elif(s[i][1]=='p'): a[1].append(int(s[i][0])) else: a[2].append(int(s[i][0])) ko=10 for i in range(len(a)): a[i]=sorted(a[i]) c=0 for j in range(1,len(a[i])): if(a[i][j]==a[i][j-1]): c+=1 if(c==1): ko=min(ko,1) elif(c==2): ko=min(ko,0) else: if(len(a[i])>0): ko=min(ko,2) ans=ko ko=10 for i in range(len(a)): a[i]=sorted(a[i]) c=0 for j in range(1,len(a[i])): if(a[i][j]==a[i][j-1]+1): c+=1 if(c==1): ko=min(ko,1) elif(c==2): ko=min(ko,0) elif(len(a[i])>1 and (a[i][0]+2==a[i][1])): ko=min(ko,1) elif(len(a[i])>2 and (a[i][1]+2==a[i][2])): ko=min(ko,1) else: if(len(a[i])>0): ko=min(ko,2) print(min(ans,ko))
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
t = input().split() t.sort() if t.count(t[0]) == 3: print('0') elif t.count(t[0]) == 2 or t.count(t[1]) == 2: print('1') else: num = list(map(int, [t[0][0], t[1][0], t[2][0]])) suit = [t[0][1], t[1][1], t[2][1]] if len(set(suit)) == 3: print('2') elif len(set(suit)) == 1: if num[1] == num[0] + 1 or num[2] == num[1] + 1: if num[2] == num[0] + 2: print('0') else: print('1') elif num[1] == num[0] + 2 or num[2] == num[1] + 2: print('1') else: print('2') else: if suit[0] == suit[1]: if num[1] - num[0] in [1, 2]: print('1') else: print('2') elif suit[1] == suit[2]: if num[2] - num[1] in [1, 2]: print('1') else: print('2') else: if num[2] - num[0] in [1, 2]: print('1') else: print('2')
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
i = input().split() sets = {"m": [], "p": [], "s": []} def check(n): m = sets[n] m.sort() mmin = 2 for n in range(1, len(m)): if m.__contains__(m[n]-1) and m.__contains__(m[n]-2): mmin = min(0, mmin) elif m.__contains__(m[n]-1) or m.__contains__(m[n]-2): mmin = min(1, mmin) mmin = min(3-m.count(m[n]), mmin) return mmin for card in i: sets[card[-1]].append(int(card[:-1])) print(max(0, min(map(check, sets.keys()))))
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
import sys tiles = sys.stdin.read().split() numbers = [int(tile[0]) for tile in tiles] letters = [tile[1] for tile in tiles] def two(i1, i2): if numbers[i1] == numbers[i2]: return 1 difference = abs(numbers[i1] - numbers[i2]) if difference == 1 or difference == 2: return 1 return 2 def solve(): if letters[0] == letters[1] == letters[2]: if numbers[0] == numbers[1] == numbers[2]: return 0 numbers.sort() if numbers[0] == numbers[1] - 1 == numbers[2] - 2: return 0 return min(two(0, 1), two(1, 2)) elif letters[0] == letters[1]: return two(0, 1) elif letters[1] == letters[2]: return two(1, 2) elif letters[0] == letters[2]: return two(0, 2) return 2 print(solve())
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
from collections import Counter s=input().split() c=Counter(s) # print(c[]) mini=max(list(c.values())) # print(list(c.values())) if max(list(c.values()))>=3: print(0) else: su,m,p=[],[],[] for i in s: if i[1]=='p': p.append(int(i[0])) elif i[1]=='s': su.append(int(i[0])) else: m.append(int(i[0])) su.sort() m.sort() p.sort() c11,c1,c2,c3=0,0,0,0 # print(su,mp) for j in range(len(su)-1): if (su[j+1]-su[j])==1: c1 = c1+1 if (su[j+1]-su[j])==2: c11+=1 for j in range(len(m)-1): if (m[j+1]-m[j])==1: c2+=1 if (m[j+1]-m[j])==2: c11+=1 for j in range(len(p)-1): if (p[j+1]-p[j])==1: c3+=1 if (p[j+1]-p[j])==2: c11+=1 if c1>1 or c2>1 or c3>1: print(0) elif c1==1 or c2==1 or c3==1 or c11>0: print(1) else: print(min(3-mini,2))
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.Comparator; public class codeforces{ public static int batabc(int[][] XD){ int max=0; for(int i=0;i<9;i++){ for(int j=0;j<3;j++) max=Math.max(max,XD[i][j]); } if(max==3) return 0; if(max==2) return 1; for(int i=0;i<7;i++){ for(int j=0;j<3;j++){ if(XD[i][j]==XD[i+1][j] && XD[i][j]==XD[i+2][j] && XD[i][j]==1) return 0; if(XD[i][j]==XD[i+2][j] && XD[i][j]==1) return 1; } } for(int i=0;i<8;i++){ for(int j=0;j<3;j++){ if(XD[i][j]==XD[i+1][j] && XD[i][j]==1) return 1; } } return 2; } public static void main(String[] args) throws IOException{ InputStreamReader isr=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(isr); PrintWriter out=new PrintWriter(System.out); StringBuilder str=new StringBuilder(); String[] lol=br.readLine().split(" "); int[][] dp=new int[9][3]; for(int i=0;i<3;i++){ if(lol[i].charAt(1)=='m') dp[Integer.parseInt(lol[i].substring(0,1))-1][0]++; else if(lol[i].charAt(1)=='p') dp[Integer.parseInt(lol[i].substring(0,1))-1][1]++; else dp[Integer.parseInt(lol[i].substring(0,1))-1][2]++; } out.println(batabc(dp)); out.close(); } }
JAVA
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
from sys import stdin,stdout I = lambda : map(int,stdin.readline().split()) P = lambda x: stdout.write(str(x)+" ") st = raw_input().split() p,m,s = [],[],[] for i in st: if i[1] == 'm': m.append(int(i[0])) elif i[1] == 'p': p.append(int(i[0])) if i[1] == 's': s.append(int(i[0])) k,sh,sh2 = 0,0,0 p.sort() m.sort() s.sort() for i in range(len(p)-1): k = max(p.count(p[i]),k) if p[i]+1 == p[i+1]: sh+=1 if p[i]+2 == p[i+1]: sh2=1 for i in range(len(s)-1): k = max(s.count(s[i]),k) if s[i]+1 == s[i+1]: sh+=1 if s[i]+2 == s[i+1]: sh2=1 for i in range(len(m)-1): k = max(m.count(m[i]),k) if m[i]+1 == m[i+1]: sh+=1 if m[i]+2 == m[i+1]: sh2=1 print 3-max(k,sh+1,sh2+1)
PYTHON
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
#!/usr/bin/env python3 import sys def rint(): return map(int, sys.stdin.readline().split()) #lines = stdin.readlines() def is_koutsu(): if si[0] == si[1] and si[1] == si[2]: if sc[0] == sc[1] and sc[1] == sc[2]: return True return False def is_shuntsu(): tmp = sorted(si) if sc[0] == sc[1] and sc[1] == sc[2]: if tmp[2] == tmp[1] +1 and tmp[1] == tmp[0]+1: return True return False def is_two_same(): if s[0] == s[1] or s[0] == s[2] or s[1] == s[2]: return True else: return False def is_two_adj(): if abs(si[0] - si[1]) == 1 and sc[0] == sc[1]: return True elif abs(si[0] - si[2]) == 1 and sc[0] == sc[2]: return True if abs(si[1] - si[2]) == 1 and sc[1] == sc[2]: return True return False def is_two_adj1(): if abs(si[0] - si[1]) == 2 and sc[0] == sc[1]: return True elif abs(si[0] - si[2]) == 2 and sc[0] == sc[2]: return True if abs(si[1] - si[2]) == 2 and sc[1] == sc[2]: return True return False pass s = input().split() si = [0,0,0] sc = ['','',''] for i in range(3): si[i] = int(s[i][0]) for i in range(3): sc[i] = s[i][1] #print(si) #print(sc) if is_koutsu() or is_shuntsu(): print(0) elif is_two_same() or is_two_adj() or is_two_adj1(): print(1) else: print(2)
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
a, b, c = input().split() n = [a[0], b[0], c[0]] s = [a[1], b[1], c[1]] if len(set(s)) == 1 and (len(set(n)) == 1 or "".join(sorted(n)) in "123456789"): print(0) else: a = 0 for i in range(3): # print((abs(int(n[i]) - int(n[(i+1)%2])))) if s[i] == s[(i+1)%3] and (abs(int(n[i]) - int(n[(i+1)%3])) in [0, 1, 2]): print(1) a = 1 break if a == 0: print(2)
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
a,b,c=input().split() a,b,c=sorted([a,b,c]) A=[a,b,c] A=set(A) if len(A)==1: print(0) exit() if len(A)==2: print(1) exit() if a[1]==b[1]and b[1]==c[1]: if a[0]==b[0] and b[0]==c[0]: print(0) elif int(b[0])==int(a[0])+1 and int(c[0])==int(b[0])+1: print(0) elif int(b[0])==int(a[0])+1 or int(c[0])==int(b[0])+1: print(1) else: if int(b[0])-int(a[0])==2 or int(c[0])-int(b[0])==2: print(1) else: print(2) elif a[1]==b[1]: if int(b[0])-int(a[0])<=2: print(1) else: print(2) elif b[1]==c[1]: if int(c[0])-int(b[0])<=2: print(1) else: print(2) elif a[1]==c[1]: if int(c[0])-int(a[0])<=2: print(1) else: print(2) else: print(2)
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
A=input().split(' ') s=[0]*10 p=[0]*10 m=[0]*10 for item in A: inte=int(item[0]) if(item[1]=='s'): s[inte]+=1 elif(item[1]=='p'): p[inte]+=1 elif(item[1]=='m'): m[inte]+=1 req=3 ans=3 for i in range (1,10): req=3-s[i] if(req<ans): ans=req req=3-p[i] if(req<ans): ans=req req=3-m[i] if(req<ans): ans=req for j in range (1,8): sm=0 for k in range (j,j+3): if not(s[k]==0): sm+=1 req=3-sm if(req<ans): ans=req sm=0 for k in range (j,j+3): if not(m[k]==0): sm+=1 req=3-sm if(req<ans): ans=req sm=0 for k in range (j,j+3): if not(p[k]==0): sm+=1 req=3-sm if(req<ans): ans=req print(ans)
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
import sys import math from collections import defaultdict,deque input = sys.stdin.readline def inar(): return [int(el) for el in input().split()] def main(): a,b,c=input().split() if a[1]==b[1]==c[1]: lol=[int(a[0]),int(b[0]),int(c[0])] lol.sort() if (lol[0]+1==lol[1] and lol[1]+1==lol[2]) or (a[0]==b[0]==c[0]): print(0) elif (lol[0]+1==lol[1] or lol[1]+1==lol[2]) or (lol[0]==lol[1] or lol[1]==lol[2]) or lol[0]+2==lol[1] or lol[1]+2==lol[2]: print(1) else: print(2) else: lol=[a[1],b[1],c[1]] lol.sort() char="" if lol[0]==lol[1] or lol[1]==lol[2]: if lol[0]==lol[1]: char=lol[0] else: char=lol[1] ls=[] if a[1]==char: ls.append(int(a[0])) if b[1]==char: ls.append(int(b[0])) if c[1]==char: ls.append(int(c[0])) ls.sort() if ls[0]==ls[1] or ls[0]+1==ls[1] or ls[0]+2==ls[1]: print(1) else: print(2) else: print(2) if __name__ == '__main__': main()
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
a,b,c=input().split(" ") anum=int(a[0]) achar=a[1] bnum=int(b[0]) bchar=b[1] cnum=int(c[0]) cchar=c[1] arr=[] arr.append(a) arr.append(b) arr.append(c) acount=arr.count(a) bcount=arr.count(b) ccount=arr.count(c) arval=[] arval.append(anum) arval.append(bnum) arval.append(cnum) archar=[] archar.append(achar) archar.append(bchar) archar.append(cchar) arval, archar = (list(t) for t in zip(*sorted(zip(arval, archar)))) #print(arval) #print(archar) if acount==3 or bcount==3 or ccount==3: print(0) else: if arval[0]+2==arval[1]+1==arval[2] and archar[0]==archar[1]==archar[2]: print(0) elif acount==2 or bcount==2 or ccount==2: print(1) elif (arval[0]+1==arval[1] and archar[0]==archar[1]) or (arval[0]+1==arval[2] and archar[0]==archar[2]) or (arval[0]+2==arval[2] and archar[0]==archar[2]) or (arval[0]+2==arval[1] and archar[0]==archar[1])or (arval[1]+2==arval[2] and archar[1]==archar[2]) or (arval[1]+1==arval[2] and archar[1]==archar[2]): print(1) else: print(2)
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
strings = list(map(str, input().split())) s1, s2, s3 = strings[0], strings[1], strings[2] check = {'m': [], 'p': [], 's': []} check[s1[1]].append(int(s1[0])) check[s2[1]].append(int(s2[0])) check[s3[1]].append(int(s3[0])) check['m'].sort() check['p'].sort() check['s'].sort() cm, cp, cs = len(check['m']), len(check['p']), len(check['s']) if cm == cp == cs == 1: print(2) else: ans = 0 diff = list() if cm > cp and cm > cs: for i in range(cm-1): diff.append(abs(check['m'][i] - check['m'][i + 1])) elif cp > cm and cp > cs: for i in range(cp-1): diff.append(abs(check['p'][i] - check['p'][i + 1])) else: for i in range(cs-1): diff.append(abs(check['s'][i] - check['s'][i + 1])) if len(diff) == 1: if diff[0] == 0 or diff[0] == 1 or diff[0] == 2: ans = 1 else: ans = 2 elif len(diff) == 2: if diff[0] == diff[1]: if diff[0] == 2: ans = 1 elif diff[0] > 2: ans = 2 elif diff[0] != diff[1]: for i in diff: if i == 0 or i == 1 or i == 2: ans = 1 break else: ans = 2 print(ans)
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
def ism(a, b, c): return a==b and b==c def isk(a, b, c): x = [a, b, c] x.sort() if x[0][1] == x[1][1] and x[1][1] == x[2][1]: if int(x[0][0])+1 == int(x[1][0]) and int(x[1][0])+1 == int(x[2][0]): return 1 return 0 a, b, c = input().split() x = [a,b,c] typem = [] types = [] typep = [] m, s, p = 0, 0, 0 for i in x: if i[1]=='m': m+=1 typem.append(i) elif i[1]=='s': s+=1 types.append(i) elif i[1]=='p': p+=1 typep.append(i) ans = 0 done = 0 if isk(a,b,c) or ism(a,b,c): ans = 0 done = 1 if done==0 and a==b and b==c: ans = 0 done = 1 elif done==0 and a==b: ans = 1 done = 1 elif done==0 and b==c: ans = 1 done = 1 elif done==0 and a==c: ans = 1 done = 1 # Shuntsu if done==0 and m>=2: typem.sort() for i in range(len(typem)-1): if abs(int(typem[i][0]) - int(typem[i+1][0])) <= 2 and \ abs(int(typem[i][0]) - int(typem[i+1][0])) > 0: ans = 1 done = 1 if done==0 and s>=2: types.sort() for i in range(len(types)-1): if abs(int(types[i][0]) - int(types[i+1][0])) <= 2 and \ abs(int(types[i][0]) - int(types[i+1][0])) > 0: ans = 1 done = 1 if done==0 and p>=2: typep.sort() for i in range(len(typep)-1): if abs(int(typep[i][0]) - int(typep[i+1][0])) <= 2 and \ abs(int(typep[i][0]) - int(typep[i+1][0])) > 0: ans = 1 done = 1 if done == 0: ans = 2 done = 1 print(ans)
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
import java.io.OutputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.Map; /** * Built using CHelper plug-in Actual solution is at the top */ public class Practice { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskA solver = new TaskA(); solver.solve(1, in, out); out.close(); } static class TaskA { public void solve(int testNumber, InputReader in, PrintWriter out) { String[] cards=new String[3]; HashMap<String,Integer> map=new HashMap<>(); int maxCount=1; ArrayList<Integer> s=new ArrayList<>(); ArrayList<Integer> p=new ArrayList<>(); ArrayList<Integer> m=new ArrayList<>(); for(int i=0;i<3;i++){ cards[i]=in.next(); if(map.containsKey(cards[i])){ map.put(cards[i],map.get(cards[i])+1); maxCount=Math.max(maxCount, map.get(cards[i])); } else{ map.put(cards[i], 1); } if(cards[i].contains("s")){ s.add(Integer.valueOf(cards[i].charAt(0))); } if(cards[i].contains("m")){ m.add(Integer.valueOf(cards[i].charAt(0))); } if(cards[i].contains("p")){ p.add(Integer.valueOf(cards[i].charAt(0))); } } if(maxCount==3){ out.println(0); } else{ Collections.sort(s); Collections.sort(m); Collections.sort(p); int cntS=1; int temp=0; for(int i=1;i<s.size();i++){ if(s.get(i)-s.get(i-1)==1){ cntS++; } else if(s.get(i)-s.get(i-1)==2){ temp=1; } } int cntM=1; for(int i=1;i<m.size();i++){ if(m.get(i)-m.get(i-1)==1){ cntM++; } else if(m.get(i)-m.get(i-1)==2){ temp=1; } } int cntP=1; for(int i=1;i<p.size();i++){ if(p.get(i)-p.get(i-1)==1){ cntP++; } else if(p.get(i)-p.get(i-1)==2){ temp=1; } } int cnt=Math.max(cntS,Math.max(cntM, cntP)); if(cnt==3){ out.println(0); } else{ int ans=3-maxCount; if(cnt>maxCount){ out.println(3-cnt); } else if(temp==1){ out.println(3-(cnt+1)); } else{ out.println(3-maxCount); } } } } } public static boolean checkPrime(int n, int p) { for (int i = 2; i <= Math.sqrt(n) && i <= p; i++) { if (n % i == 0) { return false; } } return true; } public long GCD(long a, long b) { if (b == 0) { return a; } return GCD(b, a % b); } public static long nCr(int n, int r) { return n * (n - 1) / 2; } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } } }
JAVA
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
# your code goes here tiles = input().split(' ') tiles.sort() ans = 2 sq = 0 if (tiles[0] == tiles[1] and tiles[1] == tiles[2]): ans = 0 elif (tiles[0] != tiles[1] and tiles[1] != tiles[2]): if(tiles[0][1] == tiles[1][1]): if(int(tiles[0][0]) >= int(tiles[1][0]) - 2): ans = 1 if(int(tiles[0][0]) == int(tiles[1][0]) - 1): sq = 1 if(tiles[1][1] == tiles[2][1]): if(int(tiles[1][0]) == int(tiles[2][0]) - 1): ans = 1 if(sq): ans = 0 if(int(tiles[1][0]) == int(tiles[2][0]) - 2): ans = 1 if(tiles[0][1] == tiles[2][1]): if(int(tiles[0][0]) >= int(tiles[2][0]) - 2 and sq != 1): ans = 1 else: ans = 1 print(ans)
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
/* * @author derrick20 */ import java.io.*; import java.util.*; public class mahjong { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); StringTokenizer st = new StringTokenizer(sc.nextLine()); Integer[] m = new Integer[10]; Integer[] s = new Integer[10]; Integer[] p = new Integer[10]; for (int i = 0; i < 10; i++) { m[i] = 0; s[i] = 0; p[i] = 0; } while (st.hasMoreTokens()) { String x = st.nextToken(); int rank = Integer.parseInt(x.substring(0, 1)); if (x.charAt(1) == 's') { s[rank]++; } if (x.charAt(1) == 'p') { p[rank]++; } if (x.charAt(1) == 'm') { m[rank]++; } } int needed = 3; int most = Collections.max(Arrays.asList(s)); most = Math.max(most, Collections.max(Arrays.asList(p))); most = Math.max(most, Collections.max(Arrays.asList(m))); needed = Math.max(0, needed - most); int longest = 0; int run = 0; for (int i = 1; i < 8; i++) { boolean a = m[i] > 0; boolean b = m[i + 1] > 0; boolean c = m[i + 2] > 0; if (a && b && c) { longest = Math.max(longest, 3); } else if (a && b || b && c || a && c) { longest = Math.max(longest, 2); } else if (a || b || c) { longest = Math.max(longest, 1); } } for (int i = 1; i < 8; i++) { boolean a = s[i] > 0; boolean b = s[i + 1] > 0; boolean c = s[i + 2] > 0; if (a && b && c) { longest = Math.max(longest, 3); } else if (a && b || b && c || a && c) { longest = Math.max(longest, 2); } else if (a || b || c) { longest = Math.max(longest, 1); } } for (int i = 1; i < 8; i++) { boolean a = p[i] > 0; boolean b = p[i + 1] > 0; boolean c = p[i + 2] > 0; if (a && b && c) { longest = Math.max(longest, 3); } else if (a && b || b && c || a && c) { longest = Math.max(longest, 2); } else if (a || b || c) { longest = Math.max(longest, 1); } } int secondNeed = Math.max(0, 3 - longest); int ans = Math.min(needed, secondNeed); out.println(ans); out.close(); } static class Scanner { BufferedReader br; StringTokenizer st; Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } Scanner(FileReader s) { br = new BufferedReader(s); } String nextLine() throws IOException { return br.readLine(); } String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } int nextInt() throws IOException { return Integer.parseInt(next()); } long nextLong() throws IOException { return Long.parseLong(next()); } } }
JAVA
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
a = input().split() r = 2 for i in range(48,58): for c in "mps": r = min(r,max(0,3-a.count(chr(i)+c))) r = min(r,3-(chr(i-1)+c in a)-(chr(i)+c in a)-(chr(i+1)+c in a)) print(r)
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
#include <bits/stdc++.h> using namespace std; const long long mx = 1e6 + 9; const long long inf = 1e18 + 9; long long A[mx], B[mx], freq[mx], fr[mx]; vector<pair<long long, long long> > vp1, vp2; vector<long long> v1; vector<char> v2; bool sign[mx]; map<char, bool> mp; int32_t main() { long long n = 0, m = 0, k = 0, a = 0, b = 0, c = 0, p = 0, q = 0, x = 0, y = 0, sum = 0, ans = 0, maxi = -inf, mini = inf; bool f1 = false, f2 = false; char ch1, ch2, ch3; cin >> n >> ch1 >> m >> ch2 >> k >> ch3; v1.push_back(n); v1.push_back(m); v1.push_back(k); sort(v1.begin(), v1.end()); if (n == m && k == m && ch1 == ch2 && ch2 == ch3) cout << 0 << endl; else if (ch1 == ch2 && ch2 == ch3 && v1[0] + 1 == v1[1] && v1[1] + 1 == v1[2]) cout << 0 << endl; else { if ((ch1 == ch2 && n == m) || (ch2 == ch3 && m == k) || (ch3 == ch1 && n == k)) cout << 1 << endl; else if ((ch1 == ch2 && ((n == m + 1) || (m == n + 1))) || (ch2 == ch3 && ((k == m + 1) || (m == k + 1))) || ((ch1 == ch3 && ((n == k + 1) || (k == n + 1))))) cout << 1 << endl; else if ((ch1 == ch2 && ((n == m + 2) || (m == n + 2))) || (ch2 == ch3 && ((k == m + 2) || (m == k + 2))) || ((ch1 == ch3 && ((n == k + 2) || (k == n + 2))))) cout << 1 << endl; else cout << 2 << endl; } return 0; }
CPP
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
import sys,math def read_int(): return int(sys.stdin.readline().strip()) def read_int_list(): return list(map(int,sys.stdin.readline().strip().split())) def read_string(): return sys.stdin.readline().strip() def read_string_list(delim=" "): return sys.stdin.readline().strip().split(delim) def print_list(l, delim=" "): print(delim.join(map(str, l))) ###### Author : Samir Vyas ####### ###### Write Code Below ####### tiles = read_string_list() #all equal if tiles[0] == tiles[1] == tiles[2]: print(0) sys.exit() #any two equal if tiles[0] == tiles[1] or tiles[1] == tiles[2] or tiles[2] == tiles[0]: print(1) sys.exit() mps = {"m":[], "p":[], "s":[]} for t in tiles: mps[t[1]] += [int(t[0])] for k in mps: mps[k].sort() #3 of same for k in mps: if len(mps[k]) == 3: l = mps[k] if l[0]+1 == l[1] and l[1]+1 == l[2]: print(0) sys.exit() if l[1]-l[0] <= 2 or l[2]-l[1] <= 2: print(1) sys.exit() #2 of same for k in mps: if len(mps[k]) == 2: l = mps[k] if l[1]-l[0] <=2 : print(1) sys.exit() #no luck print(2)
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
s=list(map(str,input().split())) arr=[] for i in range(3): arr.append([]) d={} for i in s: if i in d: d[i]+=1 else: d[i]=1 if i[1]=='m': arr[0].append(int(i[0])) elif i[1]=='p': arr[1].append(int(i[0])) else: arr[2].append(int(i[0])) ans=len(d)-1 # print(ans) # print(arr) for i in range(3): b=set() for j in arr[i]: b.add(j) b=list(b) b.sort() for j in range(1,len(b)): if b[j]-b[j-1]==1: # print("lol") ans=min(ans,1) for j in range(1,len(b)): if b[j]-b[j-1]==2: # print("loolll") ans=min(ans,1) for j in range(2,len(b)): if b[j]-b[j-1]==1 and b[j-1]-b[j-2]==1: ans=0 print(ans)
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
#include <bits/stdc++.h> using namespace std; map<string, int> m; int main() { string s; string b[4]; int ind = 0; for (int i = 1; i <= 3; i++) { string a; cin >> a; b[i] = a; if (i > 1) { if (a != s) ind = 1; } m[a]++; s = a; } if (ind == 0) { cout << 0; return 0; } int ans = 3; for (int i = 1; i <= 3; i++) { int ans1 = 3 - m[b[i]]; int ans2 = 4; int x = b[i][0] - 48; int j = max(0, x - 2); for (; j <= x; j++) { char n = (j + 1) + 48; char l = (j + 48); char p = (j + 2) + 48; string s1 = "", s2 = "", s3 = ""; s1 += l, s2 += n, s3 += p; s1 += b[i][1], s2 += b[i][1], s3 += b[i][1]; int o = m[s1], y = m[s2], x = m[s3]; x = min(1, x), o = min(o, 1), y = min(1, y); ans2 = min(ans2, 3 - (x + o + y)); } ans = min(ans, min(ans1, ans2)); } cout << ans; return 0; }
CPP
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
#include <bits/stdc++.h> using namespace std; int inf = 100000000; long long INF = 4000000000000000000; long long MOD = 1000000007; int main() { vector<string> s(3); vector<int> a(3); for (int(i) = 0; (i) < (3); (i)++) cin >> s.at(i); sort(s.begin(), s.end()); for (int(i) = 0; (i) < (3); (i)++) a.at(i) = s.at(i).at(0) - '0'; if (s.at(0) == s.at(1) && s.at(1) == s.at(2)) { cout << 0 << endl; return 0; } if (s.at(0).at(1) == s.at(1).at(1) && s.at(1).at(1) == s.at(2).at(1) && a.at(0) == a.at(1) - 1 && a.at(1) == a.at(2) - 1) { cout << 0 << endl; return 0; } for (int(i) = 0; (i) < (2); (i)++) { for (int j = i + 1; j < 3; j++) { if (s.at(i).at(1) == s.at(j).at(1) && (a.at(i) == a.at(j) || a.at(i) == a.at(j) - 1 || a.at(i) == a.at(j) + 1 || a.at(i) == a.at(j) + 2 || a.at(i) == a.at(j) - 2)) { cout << 1 << endl; return 0; } } } cout << 2 << endl; }
CPP
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
# ========= /\ /| |====/| # | / \ | | / | # | /____\ | | / | # | / \ | | / | # ========= / \ ===== |/====| # code if __name__ == "__main__": s = [[],[],[]] st = list(input().split()) for i in st: if i[1] == 'm': s[0].append(int(i[0])) if i[1] == 'p': s[1].append(int(i[0])) if i[1] == 's': s[2].append(int(i[0])) ans = 2 for i in s: if len(i) == 1: ans = min(ans , 2) elif len(i) == 2: i.sort() if i[1] == i[0] + 1 or i[1] == i[0] + 2: ans = min(ans , 1) elif i[1] == i[0]: ans = min(ans , 1) else: ans = min(ans , 2) elif len(i) == 3: i.sort() if i[2] == i[1] and i[1] == i[0]: ans = 0 if i[2] == i[1] + 1 and i[1] == i[0] + 1: ans = 0 elif i[2] == i[1] and i[1] == i[0]: ans = 0 elif i[1] == i[0] + 1 or i[1] == i[0] + 2: ans = min(ans , 1) elif i[2] == i[1] + 1 or i[2] == i[1] + 2: ans = min(ans , 1) elif i[2] == i[0] + 1 and i[2] == i[0] + 2: ans = min(ans , 1) elif i[0] == i[1] or i[1] == i[2]: ans = min(ans , 1) else: ans = min(ans, 2) print(ans)
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
//package codeforces; import java.util.Scanner; public class ex5 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String S [] = new String[3]; int m=0,s=0,p=0; int temp=0; for (int i = 0; i < S.length; i++) { S[i]=scan.next(); if(S[i].indexOf('m')!=-1) m++; if(S[i].indexOf('s')!=-1) s++; if(S[i].indexOf('p')!=-1) p++; } int n1 = Integer.parseInt(S[0].substring(0,1)); int n2 = Integer.parseInt(S[1].substring(0,1)); int n3 = Integer.parseInt(S[2].substring(0,1)); int d3 = Math.abs(n1-n2); int d4 = Math.abs(n1-n3); int d5 = Math.abs(n2-n3); if(m==3||s==3||p==3) { if(d3==1&d5==1&d4==2||d3==1&d4==1&d5==2||d5==1&d4==1&d3==2) System.out.println(0); else if(d3==0&d4==0) System.out.println(0); else if(d3<d5&d3<d4) { if(d3==1||d3==2||d3==0) System.out.println(1); else System.out.println(2); } else if (d5<d4&d5<d3){ if(d5==1||d5==2||d5==0) System.out.println(1); else System.out.println(2); } else if(d4<d5&d4<d3) { if(d4==1||d4==2||d4==0) System.out.println(1); else System.out.println(2); } else if(d3==2&d5==2||d4==2&d5==2||d3==2&d4==2||d3==1&d5==1||d4==1&d5==1||d3==2&d4==1) System.out.println(1); else System.out.println(2); } if(m==2||s==2||p==2) { char c1 = S[0].charAt(1); char c2 = S[1].charAt(1); char c3 = S[2].charAt(1); if(c1==c2) { if(n1==n2) System.out.println(1); else if(d3==1||d3==2) System.out.println(1); else System.out.println(2); } if(c1==c3) { if(n1==n3) System.out.println(1); else if(d4==1||d4==2) System.out.println(1); else System.out.println(2); } if(c2==c3) { if(n2==n3) System.out.println(1); else if(d5==1||d5==2) System.out.println(1); else System.out.println(2); } } if(m==1&s==1&p==1) System.out.println(2); } }
JAVA
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
a, b, c = map(str, input().split()) d = [] for i in range(3): d.append([0] * 9) def f(k): if k[1] == 'm': d[0][int(k[0]) - 1] += 1 elif k[1] == 'p': d[1][int(k[0]) - 1] += 1 else: d[2][int(k[0]) - 1] += 1 f(a) f(b) f(c) min_m = 2 z = 0 for i in d: z = max(z, max(i)) if z == 3: min_m = min(0, min_m) elif z == 2: min_m = min(1, min_m) else: for j in range(3): for i in range(1, 8): if d[j][i] == 1: if d[j][i - 1] + d[j][i + 1] == 1: min_m = min(1, min_m) elif d[j][i - 1] == d[j][i + 1] == 1: min_m = min(0, min_m) else: if d[j][i - 1] == d[j][i + 1] == 1: min_m = min(1, min_m) min_m = min(2, min_m) print(min_m)
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
s=list(input().split()) s=sorted(s) if(len(set(s))==1): print("0") elif(s[0][1]==s[1][1] and s[1][1]==s[2][1] and int(s[1][0])-int(s[0][0])==1 and int(s[2][0])-int(s[1][0])==1): print("0") elif(len(set(s))==2): print("1") elif(s[0][1]==s[1][1] and (int(s[1][0])-int(s[0][0])==1 or int(s[1][0])-int(s[0][0])==2) or (s[1][1]==s[2][1] and (int(s[2][0])-int(s[1][0])==1 or int(s[2][0])-int(s[1][0])==2)) or (s[0][1]==s[2][1] and (int(s[2][0])-int(s[0][0])==2 or int(s[2][0])-int(s[0][0])==1))): print("1") else: print("2")
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
import java.io.*; import java.util.*; import java.lang.*; public class c1 { public static MyScanner scan; public static PrintWriter out; public static void main(String[] args) { scan=new MyScanner(); out=new PrintWriter(new BufferedOutputStream(System.out)); int t=1; // int t=scan.nextInt(); while(t-->0) { String[] s=scan.nextLine().split(" "); char[] one=s[0].toCharArray(); char[] two=s[1].toCharArray(); char[] thr=s[2].toCharArray(); if(koutsu(one,two,thr)||shuntsu(one,two,thr)) out.println(0); else { boolean found=false; char[] suit={'m','s','p'}; for(int i=0;i<3;i++) { for(int j='1';j<='9';j++) { char[] temp=new char[2]; temp[0]=(char)(j); temp[1]=suit[i]; if(koutsu(temp,two,thr)||shuntsu(temp,two,thr)) { out.println(1); found=true; } else if(koutsu(one,temp,thr)||shuntsu(one,temp,thr)) { out.println(1); found=true; } else if(koutsu(one,two,temp)||shuntsu(one,two,temp)) { out.println(1); found=true; } if(found) break; } if(found) break; } if(!found) out.println(2); } } out.close(); } //-----------------------------------------------------COMP-SPACE----------------------------------------------------- public static boolean koutsu(char[] one,char[] two,char[] thr) { if(one[0]==two[0]&&one[0]==thr[0]&&one[1]==two[1]&&one[1]==thr[1]) return true; return false; } public static boolean shuntsu(char[] one,char[] two,char[] thr) { if(one[1]==two[1]&&two[1]==thr[1]) { int[] a=new int[3]; a[0]=one[0]; a[1]=two[0]; a[2]=thr[0]; Arrays.sort(a); for(int c=1;c<3;c++) if(a[c]-a[c-1]!=1) return false; return true; } return false; } //-------------------------------------------------------------------------------------------------------------------- //node static class Node implements Comparable<Node> { ArrayList<Node> adj=new ArrayList<>(); public int x,y; public Node(int x,int y) { this.x=x; this.y=y; } public ArrayList<Node> getAdj() { return adj; } public int compareTo(Node other) { if(this.x==other.x) return 0; else if(this.x>other.x) return 1; else return -1; } public boolean equals(Node other) { return this.x==other.x; } // public int compareTo(Node other) { // if(this.y==other.y) return 0; // else if(this.y>other.y) return 1; // else return -1; // } // // public boolean equals(Node other) { // return this.y==other.y; // } } //edge static class Edge implements Comparable<Edge> { public Node a,b; public int weight; public Edge(Node a,Node b,int weight) { this.a=a; this.b=b; this.weight=weight; } public int compareTo(Edge other) { if(this.weight==other.weight) return 0; else if(this.weight>other.weight) return 1; else return -1; } } //util public static int gcd(int a, int b) { if (b == 0) return a; if (a == 0) return b; return (a > b) ? gcd(a % b, b) : gcd(a, b % a); } public static int lcm(int a, int b) { return a * b / gcd(a, b); } public static void sort(int[] a) { ArrayList<Integer> list=new ArrayList<>(); for (int i:a) list.add(i); Collections.sort(list); for (int i=0; i<a.length; i++) a[i]=list.get(i); } public static int min(int a,int b) { if(a<=b) return a; else return b; } public static int max(int a,int b) { if(a>=b) return a; else return b; } public static int abs(int a) { if(a<0) return a*-1; else return a; } public static ArrayList<Integer> getPrimes(int n) { boolean prime[]=new boolean[n+1]; Arrays.fill(prime,true); for (int p=2;p*p<=n;p++) { if (prime[p]) { for (int i=p*2;i<=n;i+=p) { prime[i]=false; } } } ArrayList<Integer> primeNumbers=new ArrayList<Integer>(); for (int i = 2; i <= n; i++) { if (prime[i]) { primeNumbers.add(i); } } return primeNumbers; } public static boolean isPrime(int a) { if (a == 0 || a == 1) { return false; } if (a == 2) { return true; } for (int i = 2; i < Math.sqrt(a) + 1; i++) { if (a % i == 0) { return false; } } return true; } public static ArrayList<Integer> getDivisors(int n) { ArrayList<Integer> div = new ArrayList<Integer>(); for (int i=1;i*i<=n;i++) { if (n%i==0) { div.add(i); if (n/i!=i) div.add(n/i); } } return div; } //scanner public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static int[] nextIntArray(int n) { int[] a=new int[n]; for(int c=0;c<n;c++) a[c]=scan.nextInt(); return a; } public static Integer[] nextIntegerArray(int n) { Integer[] a=new Integer[n]; for(int c=0;c<n;c++) a[c]=scan.nextInt(); return a; } public static int[][] nextIntMatrix(int n,int m) { int[][] a=new int[n][m]; for(int i=0;i<n;i++) for(int j=0;j<m;j++) a[i][j]=scan.nextInt(); return a; } public static Integer[][] nextIntegerMatrix(int n,int m) { Integer[][] a=new Integer[n][m]; for(int i=0;i<n;i++) for(int j=0;j<m;j++) a[i][j]=scan.nextInt(); return a; } //print public static void printIntArray(int[] a) { for(int c:a) out.print(c+" "); out.println(); } public static void printIntegerArray(Integer[] a) { for(int c:a) out.print(c+" "); out.println(); } public static void printIntMatrix(int[][] a) { for(int[] i:a) { for(int j:i) out.print(j+" "); out.println(); } } public static void printIntegerMatrix(Integer[][] a) { for(Integer[] i:a) { for(Integer j:i) out.print(j+" "); out.println(); } } public static void help(int t,int n) { out.println("Test Case: "+(t+1)+" | Variable Output: "+n); } public static void help(int t,String n) { out.println("Test Case: "+(t+1)+" | Variable Output: "+n); } public static void help(int t,char[] n) { out.print("Test Case: "+(t+1)+" | Variable Output: "); for(char c:n) out.print(c+" "); out.println(); } }
JAVA
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
#include <bits/stdc++.h> using namespace std; long long MOD = 1e9 + 7; long long powmod(long long a, long long l, long long md) { long long res = 1; while (l) { if (l & 1) res = res * a % md; l /= 2; a = a * a % md; } return res; } long long binpow(long long a, long long l) { long long res = 1; while (l) { if (l & 1) res = res * a; l /= 2; a = a * a; } return res; } long long __set(long long b, long long i) { return b | (1 << i); } long long __unset(long long b, long long i) { return b & (~(1UL << i)); } long long __check(long long b, long long i) { return b & (1 << i); } long long mulmod(long long a, long long b, long long md) { return ((a % md) * (b % md)) % md; } long long addmod(long long a, long long b, long long md) { return (a + b) % md; } long long submod(long long a, long long b, long long md) { return (((a - b) % md) + md) % md; } long long divmod(long long a, long long b, long long md) { return mulmod(a, powmod(b, md - 2, md), md); } const long long inf = 0xFFFFFFFFFFFFFFFL; priority_queue<long long, vector<long long>, greater<long long> > pq; clock_t time_p = clock(); void time() { time_p = clock() - time_p; cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n"; } long long d[3][10]; signed main(void) { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; for (long long i = 0; i < 3; i++) { string s; cin >> s; if (s[1] == 'm') { d[0][s[0] - '0']++; } else if (s[1] == 'p') { d[1][s[0] - '0']++; } else { d[2][s[0] - '0']++; } } long long mx = 3; for (long long i = 0; i < 3; i++) { for (long long j = 1; j <= 9; j++) mx = min(mx, 3 - min(3ll, d[i][j])); for (long long j = 1; j <= 7; j++) { long long tp = 0; if (!d[i][j]) tp++; if (!d[i][j + 1]) tp++; if (!d[i][j + 2]) tp++; mx = min(mx, tp); } } cout << mx << "\n"; return 0; }
CPP
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
import java.io.*; import java.util.*; public class Main { static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); st = new StringTokenizer(br.readLine()); } catch (Exception e){e.printStackTrace();} } public String next() { if (st.hasMoreTokens()) return st.nextToken(); try {st = new StringTokenizer(br.readLine());} catch (Exception e) {e.printStackTrace();} return st.nextToken(); } public int nextInt() {return Integer.parseInt(next());} public long nextLong() {return Long.parseLong(next());} public double nextDouble() {return Double.parseDouble(next());} public String nextLine() { String line = ""; if(st.hasMoreTokens()) line = st.nextToken(); else try {return br.readLine();}catch(IOException e){e.printStackTrace();} while(st.hasMoreTokens()) line += " "+st.nextToken(); return line; } } public static void main(String[] args) { FastScanner sc = new FastScanner(); PrintWriter pw = new PrintWriter(System.out); int[][] cnt = new int[3][10]; String tiles = "mps"; for(int i=0;i<3;i++) { String t = sc.next(); cnt[tiles.indexOf(t.charAt(1))][t.charAt(0)-'0']++; } int ans = 2; for(int i=0;i<3;i++) { for(int j=1;j<=9;j++) { ans = Math.min(ans, 3 - cnt[i][j]); } for(int j=1;j<=7;j++) { if(cnt[i][j] > 0 && cnt[i][j+1] > 0 && cnt[i][j+2] > 0) { ans = 0; } } for(int j=1;j<=8;j++) { if(cnt[i][j] > 0 && cnt[i][j+1] > 0) { ans = Math.min(ans, 1); } } for(int j=1;j<=7;j++) { if(cnt[i][j] > 0 && cnt[i][j+2] > 0) { ans = Math.min(ans, 1); } } } pw.println(ans); pw.close(); } }
JAVA
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
# coding: UTF-8 import sys #sys.setrecursionlimit(n) import heapq import re import bisect import random import math import itertools from collections import defaultdict, deque from copy import deepcopy from decimal import * readl= lambda: list(map(str, sys.stdin.readline().split())) readt= lambda: tuple(map(int, sys.stdin.readline().split())) read = lambda: sys.stdin.readline().rstrip() readi = lambda: int(read()) readmi = lambda: map(int, sys.stdin.readline().split()) readms = lambda: map(str, sys.stdin.readline().split()) t = readl() n = [] m = [] t.sort() for i in t: n.append(int(i[0])) m.append(i[1]) count = 2 if m[0] == m[1] == m[2]: if n[0] == n[1] == n[2] or (n[0] + 1 == n[1] and n[1] + 1 == n[2]): print(0) elif n[0] == n[1] or n[0] == n[2] or n[1] == n[2]: print(1) elif n[0] + 1 == n[1] or n[0] + 2 == n[1] or n[1] + 1 == n[2] or n[1] + 2 == n[2] or n[0] + 1 == n[2] or n[0] + 2 == n[2]: print(1) else: print(2) elif m[0] == m[1]: if n[0] == n[1] or n[0] + 1 == n[1] or n[0] + 2 == n[1]: print(1) else: print(2) elif m[0] == m[2]: if n[0] == n[2] or n[0] + 1 == n[2] or n[0] + 2 == n[2]: print(1) else: print(2) elif m[1] == m[2]: if n[1] == n[2] or n[1] + 1 == n[2] or n[1] + 2 == n[2]: print(1) else: print(2) else: print(2)
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
la = sorted(input().split()) res = 2 if int(la[0][0]) == int(la[1][0]) - 1 == int(la[2][0]) - 2: if la[0][1] == la[1][1] == la[2][1]: res = 0 elif la[0][1] == la[1][1] or la[1][1] == la[2][1] or la[0][1] == la[2][1]: res = 1 elif la[0][0] == la[1][0] == la[2][0]: if la[0][1] == la[1][1] == la[2][1]: res = 0 elif la[0][1] == la[1][1] or la[1][1] == la[2][1] or la[0][1] == la[2][1]: res = 1 else: if int(la[0][0]) == int(la[1][0]) - 2: if la[0][1] == la[1][1]: res = 1 if int(la[1][0]) == int(la[2][0]) - 2: if la[1][1] == la[2][1]: res = 1 if int(la[0][0]) == int(la[2][0]) - 2: if la[0][1] == la[2][1]: res = 1 if int(la[0][0]) == int(la[2][0]) - 1: if la[0][1] == la[2][1]: res = 1 if int(la[1][0]) == int(la[2][0]) - 1: if la[1][1] == la[2][1]: res = 1 if int(la[0][0]) == int(la[1][0]) - 1: if la[0][1] == la[1][1]: res = 1 if int(la[0][0]) == int(la[1][0]): if la[0][1] == la[1][1]: res = 1 if int(la[1][0]) == int(la[2][0]): if la[1][1] == la[2][1]: res = 1 if int(la[0][0]) == int(la[2][0]): if la[0][1] == la[2][1]: res = 1 print(res)
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
s = list(map(str,input().split())) ans = 10**18 for i in map(str,range(1,10)): for p in ('m', 'p', 's'): k = s.count(i+p) if 3-k < ans: ans = 3-k for i in range(1,8): for p in ('m', 'p', 's'): k = 0 if str(i)+p in s: k += 1 if str(i+1)+p in s: k += 1 if str(i+2)+p in s: k += 1 if 3-k < ans: ans = 3-k print(ans)
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
a = (input().split()) a.sort() #print(a) if(a[0] == a[1] == a[2]): print(0) exit() elif(a[0] == a[1] or a[1] == a[2]): print(1) exit() a1 = [] for i in range(3): a1.append([int(a[i][0]), a[i][1]]) a1.sort() #print(a1) if(a1[1][1] == a1[2][1] == a1[0][1]): if(a1[0][0] == a1[1][0] - 1 and a1[0][0] == a1[2][0] - 2): print(0) exit() found = False for i in range(3): for j in range(3): if(abs(a1[i][0] - a1[j][0]) == 1 or abs(a1[i][0] - a1[j][0]) == 2 ): print(1) exit() print(2) exit() for i in range(3): for j in range(i + 1, 3): if(a1[i][1] == a1[j][1]): if(a1[i][0] == a1[j][0] - 1 or a1[i][0] == a1[j][0] - 2): print(1) else: print(2) exit() print(2)
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
from collections import Counter, defaultdict l=raw_input().split() d=defaultdict(Counter) mx=0 for i in l: #print i[1],i[0] d[i[1]][int(i[0])]+=1 mx=max(mx,d[i[1]][int(i[0])]) if d[i[1]][int(i[0])]==3: print 0 exit() ans=1000 for i in 'abcdefghijklmnopqrstuvwxyz': for j in range(1,8): x=3 if d[i][j]: x-=1 if d[i][j+1]: x-=1 if d[i][j+2]: x-=1 ans=min(ans,x) print min(ans,3-mx)
PYTHON
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
data = input().split() z, a = [], [] for i in range(3): a.append(int(data[i][0])) z.append(data[i][1]) if all(data[0] == data[i] for i in range(3)): print(0) elif data[0] == data[1] or data[1] == data[2] or data[0] == data[2]: print(1) else: k = sorted(a) if z[0] == z[1] == z[2] and k[0] == k[1] - 1 == k[2] - 2: print(0) elif (z[0] == z[1] and abs(a[0] - a[1]) in [1, 2]) or (z[1] == z[2] and abs(a[1] - a[2]) in [1, 2]) or (z[0] == z[2] and abs(a[0] - a[2]) in [1, 2]): print(1) else: print(2)
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
b=list(input().split()) s,p,m,g=[],[],[],[] for i in range(len(b)): if b[i][1]=="s": s.append(b[i][0]) if b[i][1]=="p": p.append(b[i][0]) if b[i][1]=="m": m.append(b[i][0]) s=list(map(int,s)) m=list(map(int,m)) p=list(map(int,p)) if len(s)==1: g.append(2) else: l=1 s.sort() for i in range(len(s)-1): if s[i+1]-s[i]==1: l=l+1 elif s[i+1]-s[i]==2: g.append(3-l) g.append(1) l=1 g.append(3-l) h=set(s) h=list(h) for i in range(len(h)): k=0 for j in range(len(s)): if h[i]==s[j]: k=k+1 g.append(3-k) if len(m)==1: g.append(2) else: l=1 m.sort() for i in range(len(m)-1): if m[i+1]-m[i]==1: l=l+1 elif m[i+1]-m[i]==2: g.append(3-l) g.append(1) l=1 g.append(3-l) q=set(m) q=list(q) for i in range(len(q)): k=0 for j in range(len(m)): if q[i]==m[j]: k=k+1 g.append(3-k) if len(p)==1: g.append(2) else: l=1 p.sort() for i in range(len(p)-1): if p[i+1]-p[i]==1: l=l+1 elif p[i+1]-p[i]==2: g.append(3-l) g.append(1) l=1 g.append(3-l) r=set(p) r=list(r) for i in range(len(r)): k=0 for j in range(len(p)): if r[i]==p[j]: k=k+1 g.append(3-k) if min(g)<0: print("0") else: print(min(g))
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
#include <bits/stdc++.h> using namespace std; string s[2000]; int main() { cin >> s[0] >> s[1] >> s[2]; sort(s, s + 3); if (s[0] == s[1] && s[1] == s[2]) { cout << 0 << endl; return 0; } if (s[0][1] == s[1][1] && s[1][1] == s[2][1]) { if (s[1][0] - s[0][0] == 1 && s[2][0] - s[1][0] == 1) { cout << 0 << endl; return 0; } } if (s[0] == s[1] || s[1] == s[2] || s[0] == s[2]) { cout << 1 << endl; return 0; } if (s[0][1] == s[1][1] && s[1][0] - s[0][0] <= 2 || s[0][1] == s[2][1] && s[2][0] - s[0][0] <= 2 || s[1][1] == s[2][1] && s[2][0] - s[1][0] <= 2) { cout << 1 << endl; return 0; } cout << 2 << endl; return 0; }
CPP
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
s = list(map(str,input().split())) for i in range(0,len(s)): s[i] = s[i][::-1] s = sorted(s) for i in range(0,len(s)): s[i] = s[i][::-1] for i in range(0,len(s)-2): if s[i]==s[i+1]==s[i+2]: print(0) exit(0) elif (ord(s[i][0])+2 == ord(s[i+1][0])+1 == ord(s[i+2][0])) and s[i][1]==s[i+1][1]==s[i+2][1]: print(0) exit(0) for i in range(0,len(s)-1): if s[i]==s[i+1]: print(1) exit(0) elif (ord(s[i][0])+1 == ord(s[i+1][0]) or ord(s[i][0])+2 == ord(s[i+1][0])) and s[i][1]==s[i+1][1]: print(1) exit(0) print(2)
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
#include <bits/stdc++.h> using namespace std; int main() { long long i, l, j, m, n, k; string a, b, c; cin >> a >> b >> c; if (a == b && b == c) { cout << 0; return 0; } if (a[1] == b[1] && b[1] == c[1]) { long long s[3]; s[0] = a[0] - '0'; s[1] = b[0] - '0'; s[2] = c[0] - '0'; sort(s, s + 3); if (s[0] == s[1] - 1 && s[1] == s[2] - 1) { cout << 0; return 0; } else { if (a == b || b == c || a == c) { cout << 1; return 0; } if (s[0] == s[1] - 1) { cout << 1; return 0; } if (s[0] == s[2] - 2) { cout << 1; return 0; } if (s[1] == s[2] - 1) { cout << 1; return 0; } } } if (a == b || b == c || a == c) { cout << 1; return 0; } if (a[1] == b[1]) { if (max(a[0], b[0]) == min(a[0], b[0]) + 1 || max(a[0], b[0]) == min(a[0], b[0]) + 2) { cout << 1; return 0; } } if (a[1] == c[1]) { if (max(a[0], c[0]) == min(a[0], c[0]) + 1 || max(a[0], c[0]) == min(a[0], c[0]) + 2) { cout << 1; return 0; } } if (b[1] == c[1]) { if (max(b[0], c[0]) == min(b[0], c[0]) + 1 || max(b[0], c[0]) == min(b[0], c[0]) + 2) { cout << 1; return 0; } } cout << 2; }
CPP
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
import java.util.*; import java.lang.*; import java.io.*; public class GFG { public static void main(String[] args) { Scanner sc= new Scanner(System.in); //int n = sc.nextInt(); String[] a =new String[3]; a[0] = sc.next(); a[1] = sc.next(); a[2] = sc.next(); int[] m = new int[10]; int[] p = new int[10]; int[] s = new int[10]; //System.out.println(Integer.valueOf(a[1].charAt(0))); for(int i=0;i<3;i++) { if(a[i].contains("m")) { m[Integer.valueOf(a[i].charAt(0)) - '0']++; } if(a[i].contains("p")) { p[Integer.valueOf(a[i].charAt(0)) - '0']++; } if(a[i].contains("s")) { s[Integer.valueOf(a[i].charAt(0)) - '0']++; } } //System.out.println(m[9]); int min = Integer.MAX_VALUE; for(int i=1;i<=7;i++) { if(m[i]==3 || p[i]==3 || s[i]==3 || m[9]==3 || p[9]==3 || s[9]==3 || m[8]==3 || p[8]==3 || s[8]==3 ) { System.out.println("0"); return; } else if((m[i]>0 && m[i+1]>0 && m[i+2]>0) || (p[i]>0 && p[i+1]>0 && p[i+2]>0) || (s[i]>0 && s[i+1]>0 && s[i+2]>0)) { System.out.println("0"); return; } else if((m[i]>0 && m[i+1]>0) || (p[i]>0 && p[i+1]>0) || (s[i]>0 && s[i+1]>0) || (m[8]>0 && m[9]>0) || (p[8]>0 && p[9]>0) || (s[8]>0 && s[9]>0)) { min = Math.min(min,1); } else if((m[i]>0 && m[i+2]>0) || (p[i]>0 && p[i+2]>0) || (s[i]>0 && s[i+2]>0)) { min = Math.min(min,1); } else if(m[i]==2 || p[i]==2 || s[i]==2 || m[9]==2 || p[9]==2 || s[9]==2 || m[8]==2 || p[8]==2 || s[8]==2) { System.out.println("1"); return; } else { min=Math.min(min,2); } } System.out.println(min); } }
JAVA
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
x,y,z = input().split() v = list((x,y,z)) v.sort() #print(v) a = int(v[0][0]) b = int(v[1][0]) c = int(v[2][0]) l = v[0][1] m = v[1][1] n = v[2][1] #print(a,b,c,l,m,n) if x==y and y==z: print(0) elif x==y and y!=z or x==z and y!=z or y==z and x!=z: print(1) else: if l==m and m==n: if b==a+1 and c==b+1: print(0) elif b==a+1 and c!=b+1 or c==b+1 and b!=a+1: print(1) elif b==a+2 or c==b+2: print(1) else: print(2) elif l==m and m!=n: if b==a+1 or b==a+2 or b==a: print(1) else: print(2) elif m==n and l!=n: if c==b+1 or c==b or c==b+2: print(1) else: print(2) elif l==n and n!=m: if c==a+1 or c==a or c==a+2: print(1) else: print(2) else: print(2)
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] strs = br.readLine().split("\\s+"); int[] tiles = new int[3]; for(int i=0; i<3; i++) { tiles[i] = Integer.parseInt(strs[i].substring(0, 1)); if(strs[i].charAt(1) == 'm') tiles[i] += 10; else if(strs[i].charAt(1) == 'p') tiles[i] += 30; else if(strs[i].charAt(1) == 's') tiles[i] += 50; } Arrays.sort(tiles); int match = 1; int series = 1; if(tiles[1] == tiles[0]) ++match; if(tiles[2] == tiles[1]) ++match; if(tiles[1] - tiles[0] == 1 && tiles[2] - tiles[1] == 1) { System.out.println(0); return; } else if(tiles[1] - tiles[0] == 1 || tiles[1] - tiles[0] == 2) { series = 2; } else if(tiles[2] - tiles[1] == 1 || tiles[2] - tiles[1] == 2) { series = 2; } System.out.println(3 - Math.max(match, series)); } }
JAVA
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int inf = 1e9 + 1; const int prime_100000000 = 5761460; const double eps = 1e-15; const double EPS = 1e-9; const double PI = acos(-1.0); long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } long long lcm(long long a, long long b) { return a * b / gcd(a, b); } int main() { ios_base ::sync_with_stdio(false); cin.tie(NULL); string a, b, c; cin >> a >> b >> c; vector<string> l; swap(a[0], a[1]); swap(b[0], b[1]); swap(c[0], c[1]); l.push_back(a); l.push_back(b); l.push_back(c); sort(l.begin(), l.end()); swap(a[0], a[1]); swap(b[0], b[1]); swap(c[0], c[1]); if ((a[0] == b[0] && b[0] == c[0] && a[1] == b[1] && b[1] == c[1]) || (l[0][0] == l[1][0] && l[1][0] == l[2][0] && (int)l[0][1] == (int)l[1][1] - 1 && (int)l[1][1] == (int)l[2][1] - 1)) { cout << 0; return 0; } if (a[0] == b[0] && a[1] == b[1] || b[0] == c[0] && b[1] == c[1] || a[0] == c[0] && a[1] == c[1]) { cout << 1; return 0; } if (l[0][0] == l[1][0]) { if (abs((int)l[0][1] - (int)l[1][1]) <= 2) { cout << 1; return 0; } } if (l[1][0] == l[2][0]) { if (abs((int)l[2][1] - (int)l[1][1]) <= 2) { cout << 1; return 0; } } cout << 2; return 0; }
CPP
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
from collections import defaultdict def is123(List): List.sort() if(List[1]-List[0]==1 and List[2]-List[1]==1): return True else: return False def is139(List): List.sort() if(List[1]-List[0]<=2 or List[2]-List[1]<=2): return True return False def is1123(List): List.sort() if(List[1]-List[0]<=2): return True return False a,b,c = map(str,input().split()) Number = [int(a[0]),int(b[0]),int(c[0])] Char = [a[1],b[1],c[1]] Dict = defaultdict(list) Dict[Char[0]].append(Number[0]) Dict[Char[1]].append(Number[1]) Dict[Char[2]].append(Number[2]) if((len(set(Number))==1 or is123(Number)) and len(set(Char))==1 ): #First Case print(0) elif(len(set(Char))==1 and is139(Number)): #Third Case print(1) elif(len(set(Char))==1 and not is139(Number)): print(2) elif(len(set(Char))==3): print(2) elif(len(set(Char))==2): for i in Dict.keys(): if(len(Dict[i])==2): P = Dict[i] break if(is1123(P)): print(1) else: print(2)
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
import java.io.*; import java.util.*; public class R573B { public static void main(String[] args) { JS scan = new JS(); int[][] type = new int[4][10]; //s = 1 //m = 2 //p = 3; for(int i = 0;i<3;i++){ Arrays.fill(type[i],0); } for(int i = 0;i<3;i++){ String s = scan.next(); int num = s.charAt(0)-'0'; if(s.charAt(1)=='s'){ type[1][num]++; }else if(s.charAt(1)=='m'){ type[2][num]++; }else{ type[3][num]++; } } int ans1 = 99; for(int i = 1;i<4;i++){ //we'll find the best increasing streak in this suit int streak = 1; for(int j = 1;j<9;j++){ if(type[i][j]>=1 && type[i][j+1]>=1){ streak++; }else{ ans1 = Math.min(3-streak, ans1); streak = 1; } } ans1 = Math.min(3-streak, ans1); } int ans2 = 99; for(int i = 1;i<4;i++){ for(int j = 1;j<8;j++){ if(type[i][j]>=1 && type[i][j+2]>=1){ ans2 = 1; } } } int ans = 99; for(int i = 1;i<4;i++){ //we gotta find how many match numbers in this suit for(int j = 1;j<10;j++){ ans = Math.min(ans, 3-type[i][j]); } } System.out.println(Math.min(ans2, Math.min(ans, ans1))); } static class JS{ public int BS = 1<<16; public char NC = (char)0; byte[] buf = new byte[BS]; int bId = 0, size = 0; char c = NC; double num = 1; BufferedInputStream in; public JS() { in = new BufferedInputStream(System.in, BS); } public JS(String s) throws FileNotFoundException { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } public char nextChar(){ while(bId==size) { try { size = in.read(buf); }catch(Exception e) { return NC; } if(size==-1)return NC; bId=0; } return (char)buf[bId++]; } public int nextInt() { return (int)nextLong(); } public long nextLong() { num=1; boolean neg = false; if(c==NC)c=nextChar(); for(;(c<'0' || c>'9'); c = nextChar()) { if(c=='-')neg=true; } long res = 0; for(; c>='0' && c <='9'; c=nextChar()) { res = (res<<3)+(res<<1)+c-'0'; num*=10; } return neg?-res:res; } public double nextDouble() { double cur = nextLong(); return c!='.' ? cur:cur+nextLong()/num; } public String next() { StringBuilder res = new StringBuilder(); while(c<=32)c=nextChar(); while(c>32) { res.append(c); c=nextChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while(c<=32)c=nextChar(); while(c!='\n') { res.append(c); c=nextChar(); } return res.toString(); } public boolean hasNext() { if(c>32)return true; while(true) { c=nextChar(); if(c==NC)return false; else if(c>32)return true; } } } }
JAVA
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
a = input().split() r = 2 for x in a: r = min(r,max(0,3-a.count(x))) r = min(r,(not x.replace(x[0],chr(ord(x[0])+1),1) in a)+(not x.replace(x[0],chr(ord(x[0])+2),1) in a)) r = min(r,(not x.replace(x[0],chr(ord(x[0])-1),1) in a)+(not x.replace(x[0],chr(ord(x[0])+1),1) in a)) print(r)
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
a = input().split() b=[] x = {'s':0,'m':0,'p':0} for i in range (0,3): b.append(int(a[i][0])) x[a[i][1]] += 1 if int(a[0][0])> int(a[1][0]): a[0],a[1]=a[1],a[0] if int(a[1][0]) > int(a[2][0]) : a[1],a[2]=a[2],a[1] if int(a[0][0])> int(a[1][0]): a[0],a[1]=a[1],a[0] elif int(a[1][0]) > int(a[2][0]) : a[1],a[2]=a[2],a[1] if int(a[0][0])> int(a[1][0]): a[0],a[1]=a[1],a[0] if a[0] == a[1] and a[1] == a[2]: print(0) elif a[0][1]== a[1][1] and a[1][1] == a[2][1]: if int(a[1][0])- int(a[0][0]) == 1: if int(a[2][0])- int(a[1][0]) == 1: print (0) else: print(1) elif int(a[2][0])- int(a[1][0]) == 1: print (1) elif int(a[2][0])- int(a[1][0]) == 0 or int(a[1][0])- int(a[0][0]) == 0: print (1) elif int(a[1][0])- int(a[0][0]) == 2 or int(a[2][0])- int(a[1][0]) == 2: print (1) else: print(2) elif a[0][1]== a[1][1] : if int(a[1][0])- int(a[0][0]) == 1: print(1) elif int(a[1][0])- int(a[0][0]) == 2: print (1) elif int(a[1][0])- int(a[0][0]) == 0: print (1) else: print(2) elif a[1][1] == a[2][1]: if int(a[2][0])- int(a[1][0]) == 1: print (1) elif int(a[2][0])- int(a[1][0]) == 2 : print (1) elif int(a[2][0])- int(a[1][0]) == 0 : print (1) else: print(2) elif a[0][1] == a[2][1]: if int(a[2][0]) - int( a[0][0]) == 1: print (1) elif int(a[2][0]) - int( a[0][0]) == 2: print (1) elif int(a[2][0])- int(a[0][0]) == 0 : print (1) else: print(2) else: print(2)
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
st = input().split() m = [] p = [] s = [] for i in range(len(st)): if st[i][1] == 's': s.append(int(st[i][0])) elif st[i][1] == 'm': m.append(int(st[i][0])) else: p.append(int(st[i][0])) lst = [m, p, s] a = m for i in range(1, len(lst)): if len(lst[i]) > len(a): a = lst[i] a.sort() like = 2 shoes = 2 if len(a) == 1: print(2) elif len(a) == 2: if abs(a[1] - a[0]) == 1 or abs(a[1] - a[0]) == 2 or a[1] - a[0] == 0: print(1) else: print(2) else: if abs(a[1] - a[2]) == 1 or abs(a[0] - a[1]) == 1 or abs(a[2] - a[0]) == 1: like -= 1 elif abs(a[1] - a[2]) == 2 or abs(a[0] - a[1]) == 2 or abs(a[2] - a[0]) == 2: like -= 1 if abs(a[1] - a[2]) == 1 and abs(a[2] - a[0]) == 2: like -= 1 if a[1] == a[0] or a[1] == a[2] or a[0] == a[2]: shoes -= 1 if a[1] == a[0] == a[2]: shoes -= 1 print(min(like, shoes))
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
import java.io.*; import java.util.*; public class Alpha_Round { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out)); String[] in = reader.readLine().split(" "); Arrays.sort(in, new Comparator<String>() { @Override public int compare(String o1, String o2) { return o1.charAt(0) - o2.charAt(0); } }); int[][] ans = new int[10][3]; int min = Integer.MAX_VALUE; for (int i = 0; i < 3; ++i) { int j = Integer.parseInt(String.valueOf(in[i].charAt(0))); int k; if (in[i].charAt(1) == 'm') { k = 0; } else if (in[i].charAt(1) == 'p') { k = 1; } else { k = 2; } ++ans[j][k]; min = Math.min(min, (ans[j][k] >= 3) ? 0 : 3 - ans[j][k]); if (j - 2 >= 0) { int add = 2; add -= ans[j - 2][k] > 0 ? 1 : 0; add -= ans[j - 1][k] > 0 ? 1 : 0; min = Math.min(min, add); } if (j + 2 < 10) { int add = 2; add -= ans[j + 2][k] > 0 ? 1 : 0; add -= ans[j + 1][k] > 0 ? 1 : 0; min = Math.min(min, add); } if (j - 1 >= 0 && j + 1 < 10) { int add = 2; add -= ans[j + 1][k] > 0 ? 1 : 0; add -= ans[j - 1][k] > 0 ? 1 : 0; min = Math.min(min, add); } } writer.write(min + ""); writer.close(); } }
JAVA
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); vector<string> v(3); map<string, int> m; for (int i = 0; i < 3; i++) cin >> v[i]; m[v[0]] = 1; m[v[1]] = 1; m[v[2]] = 1; vector<int> ans; for (int i = 0; i < 3; i++) { int temp = 2; for (int j = 0; j < 3; j++) { if (i != j and v[i] == v[j]) temp--; } ans.push_back(temp); } string bb = "spm"; for (int i = 0; i < 3; i++) { vector<string> gg; for (int j = 1; j <= 9; j++) { string kb = ""; kb += char(j + '0'); kb += bb[i]; gg.push_back(kb); } for (int j = 0; j <= 6; j++) { int temp = 3; for (int k = j; k < j + 3; k++) temp -= m[gg[k]]; ans.push_back(temp); } } sort(ans.begin(), ans.end()); cout << ans[0]; return 0; }
CPP
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
import sys a,b,c=map(str,raw_input().split()) d={} h={} l=[a,b,c] for i in xrange(len(l)): key=l[i][1] if key not in d: d[key]=[int(l[i][0])] else: d[key].append(int(l[i][0])) q=d.values() ans=2 for i in xrange(len(q)): u=q[i] if len(u)==1: ans=min(ans,2) elif len(u)==2: if len(set(u))==1: ans=min(1,ans) elif abs(u[0]-u[1])==1: ans=min(ans,1) elif abs(u[0]-u[1])==2: ans=min(ans,1) else: ans=min(ans,2) elif len(u)==3: u.sort() if len(set(u))==1: print 0 sys.exit() elif u[1]-u[0]==1 and u[2]-u[1]==1: print 0 sys.exit() elif u[1]-u[0]<=1 or u[1]-u[0]<=2: ans=min(1,ans) elif u[2]-u[1]<=1 or u[2]-u[1]<=2: ans=min(1,ans) elif u[2]-u[0]<=2: ans=min(1,ans) else: ans=min(2,ans) print ans
PYTHON
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
def issort(a,b,c): l = [a,b,c] l = sorted(l) if l[1]-l[0] == 1 and l[2]-l[1]==1: return 0 elif l[1]-l[0] == 1 or l[2]-l[1] == 1 or l[1]-l[0] == 2 or l[2]-l[1] == 2: return 1 return 2 a,b,c = input().split() rk = 2 if a==b==c: rk =0 elif a == b or b==c or c==a: rk=1 #print(rk) a = str(a) b = str(b) c = str(c) sk = 0 if a[1]==b[1]==c[1]: sk = issort(int(a[0]),int(b[0]),int(c[0])) elif a[1]==b[1]: if abs(int(a[0])-int(b[0])) == 1 or abs(int(a[0])-int(b[0])) == 2: sk=1 else: sk = 2 elif c[1]==b[1]: if abs(int(c[0])-int(b[0])) == 1 or abs(int(c[0])-int(b[0])) == 2: sk=1 else: sk = 2 elif a[1]==c[1]: if abs(int(a[0])-int(c[0])) == 1 or abs(int(a[0])-int(c[0])) == 2: sk=1 else: sk = 2 else: sk=2 print(min(rk,sk)) #print(sk)
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
cards = input().split(" ") cards.sort() cards = [(int(card[0]), card[1]) for card in cards] if cards[0] == cards[1] and cards[0] == cards[2]: koutsuCount = 0 elif cards[0] == cards[1] or cards[1] == cards[2]: koutsuCount = 1 else: koutsuCount = 2 if cards[0][1] == cards[1][1] and cards[0][1] == cards[2][1]: if cards[0][0] + 1 == cards[1][0] and cards[0][0] + 2 == cards[2][0]: shuntsuCount = 0 elif cards[0][0] + 1 == cards[1][0] or cards[0][0] + 2 == cards[1][0] or cards[1][0] + 1 == cards[2][0] or cards[1][0] + 2 == cards[2][0]: shuntsuCount = 1 else: shuntsuCount = 2 elif cards[0][1] == cards[1][1]: if cards[0][0] + 1 == cards[1][0] or cards[0][0] + 2 == cards[1][0]: shuntsuCount = 1 else: shuntsuCount = 2 elif cards[0][1] == cards[2][1]: if cards[0][0] + 1 == cards[2][0] or cards[0][0] + 2 == cards[2][0]: shuntsuCount = 1 else: shuntsuCount = 2 elif cards[1][1] == cards[2][1]: if cards[1][0] + 1 == cards[2][0] or cards[1][0] + 2 == cards[2][0]: shuntsuCount = 1 else: shuntsuCount = 2 else: shuntsuCount = 2 print(min(koutsuCount, shuntsuCount))
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
d = {} for x, y in input().split(): d.setdefault(y,[]).append(int(x)) r = 2 for k in d: a = sorted(d[k]) s = {y - x for x, y in zip(a, a[1:])} if len(a) > 2 and s in ({0},{1}): r = 0 if {0,1,2} & s: r = min(r, 1) print(r)
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
i = raw_input() l = i.split(' ') l.sort() if(len(set(l))==1) : print(0) else : num = [int(x[0],10) for x in l] st = [x[1] for x in l] if(len(set(st))==1) : if(num[1]-num[0]==1 or num[2]-num[1]==1) : if(num[1]-num[0]==1 and num[2]-num[1]==1) : print(0) else : print(1) else : if(num[1]-num[0]==2 or num[2]-num[1]==2 or num[1]-num[0]==0 or num[2]-num[1]==0) : print(1) else : print(2) elif(len(set(st))==2) : merge = [[st[i],num[i]] for i in range(len(st))] merge.sort() if(merge[0][0]==merge[1][0]) : if(merge[0][1]-merge[1][1]==-1 or merge[0][1]-merge[1][1]==1 or merge[0][1]-merge[1][1]==-2 or merge[0][1]-merge[1][1]==2 or merge[0][1]-merge[1][1]==0 ) : print(1) else : print(2) elif(merge[1][0]==merge[2][0]) : if(merge[1][1]-merge[2][1]==-1 or merge[1][1]-merge[2][1]==1 or merge[1][1]-merge[2][1]==-2 or merge[1][1]-merge[2][1]==2 or merge[1][1]-merge[2][1]==0 ) : print(1) else : print(2) else : print(2)
PYTHON
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
f= lambda c: 'mps'.index(c) l= [[], [], []] for c in input().split(): a, b= c l[f(b)].append(int(a)) for i in range(3): l[i].sort() res= int(3) for x in l: if(len(x)==0): continue elif(len(x)==1): res= min(res, 2) elif(len(x)==3): if(len(set(x))==1): res= min(res, 0) break if(x[0]==x[1]-1 and x[1]==x[2]-1): res= min(res, 0) break res= min(res, 2) for i in range(len(x)): for j in range(i+1, len(x)): if (abs(x[i]-x[j])<=2): res= min(res, 1) print(int(res))
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
'''input 3p, 6p, 7p ''' def main(): a, b, c = input().split() nums = sorted(list(map(int , [a[0], b[0], c[0]]))) chars = [a[1], b[1], c[1]] tup = sorted(list(map(lambda x : (int(x[0]), x[1]), [a, b, c])), key = lambda x : x[0]) if(a == b and b == c): return 0 if(nums[0] + 1 == nums[1] and nums[1] + 1 == nums[2] and len(set(chars)) == 1): return 0 if(a == b or b == c or c == a): return 1 if(len(set(chars)) <= 2): if(tup[0][1] == tup[1][1]): if(tup[0][0] + 1 == tup[1][0] or tup[0][0] + 2 == tup[1][0]): return 1 if(tup[0][1] == tup[2][1]): if(tup[0][0] + 1 == tup[2][0] or tup[0][0] + 2 == tup[2][0]): return 1 if(tup[1][1] == tup[2][1]): if(tup[1][0] + 1 == tup[2][0] or tup[1][0] + 2 == tup[2][0]): return 1 return 2 if __name__ == '__main__': print(main())
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
from collections import defaultdict def main(): # ****************************** Input ************************************* A=list(input().split()) # print(A) # ****************************** Algorithm ********************************* B=sorted(A,key = lambda x : int(x[0])) m=defaultdict(list) for i in B: m[i[1]].append(int(i[0])) # print(m) # Now check for mentsu # Check for Koutsu # Formed when in any of m,s,p there are 3 numbers the same maxCount=0 for i in m: count1=0 for j in range(len(m[i])-1): # print(m[i][j],m[i][j+1]) if m[i][j] == m[i][j+1]: count1+=1 # print("Run",count1) else: count1=0 if count1>maxCount: maxCount=count1 if count1==2: print(0) return # Check for Shuntsu for i in m: count2=0 for j in range(len(m[i])-1): if m[i][j] + 1 ==m[i][j+1]: count2+=1 else: count2=0 if count2 > maxCount: maxCount = count2 if count2 == 2: print(0) return # print(maxCount) # THird Case # print(m) if maxCount==0: for i in m: # count3=0 for j in range(len(m[i])-1): # print(m[i][j],m[i][j+1]) if abs(m[i][j] - m[i][j+1]) == 2: print(1) return # ****************************** output ************************************ #Output here # print(m) if len(A)==0: print(3) else: print(2-maxCount) main() # 5p 5s 9m 4p 1s 7p 7m 6p # 2m 3p 2s 4m 1s 2s 4s # 3m 9m 2m
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
#include <bits/stdc++.h> using namespace std; int main() { string s[3]; cin >> s[0] >> s[1] >> s[2]; if (s[0][0] > s[1][0]) swap(s[0], s[1]); if (s[0][0] > s[2][0]) swap(s[0], s[2]); if (s[1][0] > s[2][0]) swap(s[2], s[1]); if (s[0] == s[1] and s[1] == s[2]) { cout << 0; return 0; } else if (s[0] == s[1] or s[1] == s[2]) { cout << 1; return 0; } else if (s[0][1] == s[1][1] and s[1][1] == s[2][1]) { if (s[2][0] - s[1][0] == 1 and s[1][0] - s[0][0] == 1) { cout << 0; return 0; } else if (s[2][0] - s[1][0] == 1 or s[1][0] - s[0][0] == 1) { cout << 1; return 0; } else if (s[2][0] - s[1][0] == 2 or s[1][0] - s[0][0] == 2) { cout << 1; return 0; } else { cout << 2; return 0; } } else if (s[0][1] == s[1][1]) { int temp = abs(s[0][0] - s[1][0]); if (temp == 1 or temp == 2) { cout << 1; return 0; } else { cout << 2; return 0; } } else if (s[1][1] == s[2][1]) { int temp = abs(s[1][0] - s[2][0]); if (temp == 1 or temp == 2) { cout << 1; return 0; } else { cout << 2; return 0; } } else if (s[0][1] == s[2][1]) { int temp = abs(s[0][0] - s[2][0]); if (temp == 1 or temp == 2) { cout << 1; return 0; } else { cout << 2; return 0; } } else { cout << 2; return 0; } }
CPP
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
a = input().split() p = [] m = [] s = [] for i in a: n = int(i[0]) if i[1]=='p': p.append(n) elif i[1]=='m': m.append(n) else: s.append(n) for qq in (p,m,s): if len(qq)>2: sp = list(sorted(list(set(qq)))) if len(sp)==1: print(0) elif len(sp)==2: print(1) else: if max(sp)-min(sp)==2: print(0) else: if sp[1]-sp[0]<3: print(1) elif sp[2]-sp[1]<3: print(1) else: print(2) exit() else: if len(p)==2: if abs(p[0]-p[1])<3: print(1) else: print(2) elif len(m)==2: if abs(m[0]-m[1])<3: print(1) else: print(2) elif len(s)==2: if abs(s[0]-s[1])<3: print(1) else: print(2) else: print(2)
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
input_ = input() input_ =input_.split(" ") arg1 = input_[0] arg2 = input_[1] arg3 = input_[2] def calc(arg1, arg2, arg3): if(arg1 == arg2): if(arg1 == arg3): return 0 # == all # only 2 == 1 return 1 if(arg1==arg3): return 1 if(arg2==arg3): return 1 # all!= if(arg1[1] == arg2[1]): if(arg1[1] == arg3[1]): # 1 masti numb = list() numb.append(int(arg1[0])) numb.append(int(arg2[0])) numb.append(int(arg3[0])) numb.sort() if(numb[1] - numb[0] == 1): if(numb[2] - numb[1] == 1): return 0 return 1 if(numb[2] - numb[1] == 1): return 1 if(numb[1] - numb[0] == 2 or numb[2] - numb[1] == 1): return 1 return 2 if((int(arg1[0]) - int(arg2[0]) < 3) and (int(arg1[0]) - int(arg2[0]) > -3) ): return 1 if(arg1[1] == arg3[1]): if((int(arg1[0]) - int(arg3[0]) <3)and (int(arg1[0]) - int( arg3[0])>-3) ): return 1 if(arg2[1] == arg3[1]): if((int(arg3[0]) - int(arg2[0]) <3) and (int(arg3[0]) - int(arg2[0])>-3) ): return 1 return 2 res = calc(arg1, arg2, arg3) if(res is None): print(2) else: print(res)
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.StringTokenizer; public class CF1191B { public static void main(String[] args) { FastReader input = new FastReader(); String s = input.nextLine(); String[] t = s.split(" "); Arrays.sort(t); if(t[0].charAt(1) == t[2].charAt(1) && t[0].charAt(1) != t[1].charAt(1)){ String temp = t[1]; t[1] = t[2]; t[2] = temp; } // for(String p : t){ // System.out.print(p + " "); // } // System.out.println(); int count = 0; int maxCount = 0; for(int i = 0;i < t.length-1;i++){ if(t[i].compareTo(t[i+1]) == 0){ count++; if(count > maxCount){ maxCount = count + 1; } } else count = 0; if(count == 2){ System.out.println(0); return; } } if(maxCount == 0) maxCount = 1; int count2 = 0; int maxCount2 = 0; for(int i = 0;i < t.length-1;i++){ if(t[i].charAt(1) == t[i+1].charAt(1)){ if(t[i+1].charAt(0) - t[i].charAt(0) == 1){ count2++; if(count2 > maxCount2) maxCount2 = count2+1; } } else count2 = 0; if(count2 == 2){ System.out.println(0); return; } } for(int i = 0;i < t.length-1;i++){ if(t[i].charAt(1) == t[i+1].charAt(1)){ if(t[i+1].charAt(0) - t[i].charAt(0) == 2){ maxCount2 = 2; } } } if(maxCount2 == 0) maxCount2 = 1; int ans = Math.max(maxCount,maxCount2); System.out.println(3 - ans); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
JAVA
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
a,b,c=sorted(input().split()) v=2 if a==b==c: v=0 elif a==b or a==c or b==c: v=1 else: x,y,z=int(a[0]),int(b[0]),int(c[0]) if a[1]==b[1]==c[1] and x+1==y and y+1==z: v=0 elif (a[1]==b[1] and 0<y-x<3) or (a[1]==c[1] and 0<z-x<3) or (b[1]==c[1] and 0<z-y<3): v=1 print(v)
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
from sys import stdin,stdout from itertools import combinations from collections import defaultdict,Counter import math import heapq def listIn(): return list((map(int,stdin.readline().strip().split()))) def stringListIn(): return([x for x in stdin.readline().split()]) def intIn(): return (int(stdin.readline())) def stringIn(): return (stdin.readline().strip()) if __name__=="__main__": tiles=stringListIn() ch1,ch2,ch3=tiles[0][1],tiles[1][1],tiles[2][1] if ch1==ch2 and ch2==ch3: tiles=sorted(tiles) else: tiles=sorted(tiles,key=lambda x:x[1]) #print(tiles) c=Counter(tiles) m=max(c.values()) if m>=2: print(3-m) else: num=int(tiles[0][0]) ch=tiles[0][1] count=1 flag=1 for tile in tiles[1:]: if ch==tile[1]: if (abs(int(tile[0])-num)<=2): count+=1 else: ch=tile[1] num=int(tile[0]) else: ch=tile[1] num=int(tile[0]) print(3-count)
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
s = input().split() hand = {'m': [], 'p': [], 's':[]} for item in s: hand[item[1]].append(int(item[0])) min_steps_needed = 10 for symb in ['m', 'p', 's']: hand[symb] = sorted(hand[symb]) for start in range(1, 10): a_needed = 10 b_needed = 10 a_needed = 3 - hand[symb].count(start) b1, b2, b3 = 0, 0, 0 if hand[symb].count(start) > 0: b1 = 1 if hand[symb].count(start+1) > 0: b2 = 1 if hand[symb].count(start+2) > 0: b3 = 1 b_needed = 3 - b1 - b2 - b3 if a_needed < min_steps_needed: min_steps_needed = a_needed if b_needed < min_steps_needed: min_steps_needed = b_needed # print(s) # print(hand) print(min_steps_needed)
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
#!/usr/bin/env python3 def main(): ans = 0 s = input().split() s.sort() # It contains koutsu if s[0] == s[1] and s[1] == s[2]: print(ans) return # It contains shuntsu if s[0][1] == s[1][1] and s[1][1] == s[2][1]: if int(s[2][0]) - int(s[1][0]) == 1 and int(s[1][0]) - int(s[0][0]) == 1: print(ans) return else: pass # one more kouts piece if s[0] == s[1] or s[1] == s[2] or s[0] == s[2]: print(1) return # one more shuntsu piece if ( (s[0][1] == s[1][1] and int(s[1][0]) - int(s[0][0]) < 3) or (s[1][1] == s[2][1] and int(s[2][0]) - int(s[1][0]) < 3) or (s[2][1] == s[0][1] and int(s[2][0]) - int(s[0][0]) < 3) ): print(1) return print(2) main()
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
GI = lambda: int(input()); GIS = lambda: map(int, input().split()); LGIS = lambda: list(GIS()) def main(): cards = input().strip().split() d = {c: [0] * 9 for c in 'smp'} for card in cards: num, suite = card[0], card[1] num = int(num) d[suite][num-1] += 1 mn = float('inf') for l in d.values(): for i, x in enumerate(l): mn = min(mn, 3 - max(x, sum(map(bool, l[i:i+3])))) print(max(mn, 0)) main()
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
a,b,c=sorted(10*ord(y)+int(x)for x,y in input().split()) s={b-a,c-b} print(2-bool(s&{0,1,2})-(s<{0,1}))
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
A=list(map(list,(list(input().split())))) m=[] p=[] s=[] for x,a in A: if a=="m": m.append(int(x)) elif a=="p": p.append(int(x)) else: s.append(int(x)) m.sort() p.sort() s.sort() def check(x): if len(x)==3: if x[0]==x[1]==x[2]: return 3 if x[0]+1==x[1] and x[1]+1==x[2]: return 3 if x[0]==x[1] or x[1]==x[2]: return 2 if x[0]+1==x[1] or x[1]+1==x[2] or x[0]+2==x[1] or x[1]+2==x[2]: return 2 return 1 if len(x)==2: if x[0]==x[1]: return 2 if x[0]+1==x[1] or x[0]+2==x[1]: return 2 return 1 return 1 print(3-max(check(m),check(p),check(s)))
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.Map; import java.util.PriorityQueue; import java.util.Scanner; import java.util.Set; import java.util.Stack; import java.util.StringTokenizer; import java.util.TreeMap; import java.util.TreeSet; import java.util.Vector; public class mai { public static int lowerBound(long[] array, int length, long value) { int low = 0; int high = length; while (low < high) { final int mid = (low + high) / 2; if (value <= array[mid]) { high = mid; } else { low = mid + 1; } } return low; } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } static long lcm(long a, long b) { return (a * b) / gcd(a, b); } public static void sortbyColumn(int arr[][], int col) { // Using built-in sort function Arrays.sort Arrays.sort(arr, new Comparator<int[]>() { @Override // Compare values according to columns public int compare(final int[] entry1, final int[] entry2) { // To sort in descending order revert // the '>' Operator // if (entry1[col] > entry2[col]) // return 1; // else //(entry1[col] >= entry2[col]) // return -1; return new Integer(entry1[col]).compareTo(entry2[col]); // return entry1[col]. } }); // End of function call sort(). } class pair<X, Y> { // utilizing Java "Generics" X _first; Y _second; public pair(X f, Y s) { _first = f; _second = s; } X first() { return _first; } Y second() { return _second; } void setFirst(X f) { _first = f; } void setSecond(Y s) { _second = s; } } static long nCr(long n, long r) { long x = 1; long yu = n - r; while (n > r) { x = x * n; n--; } while (yu > 0) { x /= yu; yu--; } return x; } public static void main(String[] args) throws NumberFormatException, IOException { FastReader sc = new FastReader(); // BufferedReader br = new BufferedReader(new // InputStreamReader(System.in)); // Scanner scn = new Scanner(System.in); // PrintWriter pr = new PrintWriter(new BufferedWriter(new // OutputStreamWriter(System.out))); String s=sc.nextLine(); String ss[]=s.split(" "); Arrays.sort(ss); HashMap<String, Integer>h=new HashMap<>(); int max=0; //System.out.println("f"); for(int i=0;i<ss.length;i++) { if(h.containsKey(ss[i])) { h.put(ss[i], h.get(ss[i])+1); if(h.get(ss[i])==3) { System.out.println("0"); return; } if(h.get(ss[i])>max) { max=h.get(ss[i]); } } else h.put(ss[i], 1); } // System.out.println("f"); int b=0; for(int i=1;i<10;i++) {int c=0; while(i<10 && h.containsKey(i+"m")) {c++; i++; } if(c>max) max=c; } for(int i=1;i<10;i++) {int c=0; while(i<10 && h.containsKey(i+"s")) { c++; i++;} if(c>max) max=c; } for(int i=1;i<10;i++) {int c=0; while(i<10 && h.containsKey(i+"p")) {c++;i++;} if(c>max) max=c; } if(max>=3) { System.out.println("0"); } else { for(int i=0;i<ss.length;i++) { for(int j=i+1;j<ss.length;j++) { if(Math.abs(ss[i].charAt(0)-ss[j].charAt(0))==2 && ss[i].charAt(1)==ss[j].charAt(1)) { System.out.println("1"); return; } } } System.out.println(3-max); //System.out.println()); } } }
JAVA
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
#include <bits/stdc++.h> using namespace std; const int maxn = 10000; int a[3]; int main() { string s; for (int i = 0; i < 3; ++i) { cin >> s; a[i] = (s[0] - '0') + (s[1] - 'a') * 100; } sort(a, a + 3); int t1 = a[1] - a[0], t2 = a[2] - a[1]; if (t1 == t2 && (t1 == 1 || t1 == 0)) puts("0"); else if (t1 == 0 || t1 == 1 || t1 == 2 || t2 == 0 || t2 == 1 || t2 == 2) puts("1"); else puts("2"); return 0; }
CPP
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
#include <bits/stdc++.h> using namespace std; char s1[20], s2[20], s3[20]; int ques(char a, char b, char c) { if ((a - b == 1 && b - c == 1) || (a - c == 1 && c - b == 1) || (b - c == 1 && c - a == 1) || (b - a == 1 && a - c == 1) || (c - a == 1 && a - b == 1) || (c - b == 1 && b - a == 1)) return 1; else return 0; } int xiangtong3(char s[], char ss[], char sss[]) { if (strcmp(s, ss) == 0 && strcmp(ss, sss) == 0) return 1; else return 0; } int xiangtong2(char s[], char ss[], char sss[]) { if (strcmp(s, ss) == 0 || strcmp(ss, sss) == 0 || strcmp(s, sss) == 0) return 1; else return 0; } int lianxu3(char s[], char ss[], char sss[]) { if (s[1] == ss[1] && ss[1] == sss[1] && ques(ss[0], s[0], sss[0])) { return 1; } else return 0; } int lianxu2(char s[], char ss[], char sss[]) { if (s[1] == ss[1] && ((abs(s[0] - ss[0]) == 1) || (abs(s[0] - ss[0]) == 2))) return 1; if (s[1] == sss[1] && ((abs(s[0] - sss[0]) == 1) || (abs(s[0] - sss[0]) == 2))) return 1; if (((abs(ss[0] - sss[0]) == 1) || (abs(ss[0] - sss[0]) == 2)) && (ss[1] == sss[1])) return 1; return 0; } int main() { while (cin >> s1 >> s2 >> s3) { if (lianxu3(s1, s2, s3) || xiangtong3(s1, s2, s3)) printf("0\n"); else if (lianxu2(s1, s2, s3) || xiangtong2(s1, s2, s3)) printf("1\n"); else printf("2\n"); } }
CPP
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
#include <bits/stdc++.h> using namespace std; int main() { string a, b, c; cin >> a >> b >> c; char x = '1'; char y[3] = {'m', 'p', 's'}; map<string, int> ump; for (int i = 0; i < 3; i++) { string make = ""; make += y[i]; for (int j = 1; j <= 9; j++) { make = (char)(j + '0') + make; ump[make] = 0; make = y[i]; } x = '1'; } ump[a]++; ump[b]++; ump[c]++; for (auto uj : ump) { if (uj.second == 3) { cout << "0" << endl; exit(0); } } for (int i = 1; i <= 9; i++) { if (i > 7) break; string make = ""; make += (char)(i + '0'); string make1 = ""; make1 += (char)(i + 1 + '0'); string make2 = ""; make2 += (char)(i + 2 + '0'); for (int j = 0; j < 3; j++) { make += y[j]; make1 += y[j]; make2 += y[j]; if (ump[make] && ump[make1] && ump[make2]) { cout << "0" << endl; exit(0); } make = (char)(i + '0'); make1 = (char)(i + 1 + '0'); make2 = (char)(i + 2 + '0'); } } int ans = min(3 - ump[a], 3 - ump[b]); ans = min(ans, 3 - ump[c]); int ans2 = INT_MAX; for (int i = 1; i <= 9; i++) { if (i > 7) break; string make = ""; make += (char)(i + '0'); string make1 = ""; make1 += (char)(i + 1 + '0'); string make2 = ""; make2 += (char)(i + 2 + '0'); for (int j = 0; j < 3; j++) { make += y[j]; make1 += y[j]; make2 += y[j]; int zz = 0; if (ump[make]) zz++; if (ump[make1]) zz++; if (ump[make2]) zz++; ans2 = min(3 - zz, ans2); make = (char)(i + '0'); make1 = (char)(i + 1 + '0'); make2 = (char)(i + 2 + '0'); } } cout << min(ans, ans2) << endl; }
CPP
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
def for_k(l): if not l: return 3 d = [] for e in l: d.append(l.count(e)) return max(3 - max(d), 0) def for_s(l): t = [0 for _ in range(9)] if not l: return 3 numbas = [] for e in l: if e not in numbas: numbas.append(int(e[0])) if any([numbas[i] + 1 == numbas[i + 1] and numbas[i + 2] == numbas[i + 1] + 1 for i in range(len(numbas) - 2)]): return 0 elif any([numbas[i] + 1 == numbas[i + 1] for i in range(len(numbas) - 1)]): return 1 else: for n in numbas: t[n - 1] = 1 gaps = [] buff = 0 for i in range(t.index(1), len(t)): if t[i] == 0: buff += 1 else: if buff: gaps.append(buff) buff = 0 if not gaps: return 2 if min(gaps) >= 2: return 2 elif min(gaps) == 1: return 1 a = input().split() a.sort(key=lambda x: (x[1], x[0])) x = [] y = [] z = [] for e in a: if e[1] == 'm': x.append(e) elif e[1] == 'p': y.append(e) else: z.append(e) hello = [] for thing in (x, y, z): hello.append(for_s(thing)) hello.append(for_k(thing)) print(min(hello))
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
#Ashish Sagar l=list(map(str,input().split())) m=0 s=0 p=0 for i in range(3): if l[i][1]=='s': s+=1 elif l[i][1]=='m': m+=1 else : p+=1 if m==1 and p==1 and s==1: print(2) elif m==2: a=[] for i in range(3): if l[i][1]=='m': a.append(l[i][0]) a.sort() if int(a[1])==int(a[0])+1 or int(a[0])==int(a[1]) or int(a[1])==int(a[0])+2: print(1) else: print(2) elif s==2: a=[] for i in range(3): if l[i][1]=='s': a.append(l[i][0]) a.sort() if int(a[1])==int(a[0])+1 or int(a[0])==int(a[1]) or int(a[1])==int(a[0])+2: print(1) else: print(2) elif p==2: a=[] for i in range(3): if l[i][1]=='p': a.append(l[i][0]) a.sort() if int(a[1])==int(a[0])+1 or int(a[0])==int(a[1]) or int(a[1])==int(a[0])+2: print(1) else: print(2) elif m==3: a=[] for i in range(3): a.append(l[i][0]) a.sort() c=0 d=0 e=0 for i in range(2): if int(a[i])==int(a[i+1])-1 : c+=1 if int(a[i])==int(a[i+1])-2 : e=1 if int(a[i])==int(a[i+1]): d+=1 print(min(min(2-c,2-d),2-e)) elif s==3: a=[] for i in range(3): a.append(l[i][0]) a.sort() c=0 d=0 e=0 for i in range(2): if int(a[i])==int(a[i+1])-1 : c+=1 if int(a[i])==int(a[i+1])-2 : e=1 if int(a[i])==int(a[i+1]): d+=1 print(min(min(2-c,2-d),2-e)) elif p==3: a=[] for i in range(3): a.append(l[i][0]) a.sort() c=0 d=0 e=0 for i in range(2): if int(a[i])==int(a[i+1])-1 : c+=1 if int(a[i])==int(a[i+1])-2 : e=1 if int(a[i])==int(a[i+1]): d+=1 print(min(min(2-c,2-d),2-e))
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
n=input().split() init=len(n) m=set(n) fg=0 final=len(m) def checkConsecutive(l): return sorted(l) == list(range(min(l), max(l)+1)) lst=[] lst.append(int(n[0][0])) lst.append(int(n[1][0])) lst.append(int(n[2][0])) if(n[0][1]==n[1][1] and n[1][1]==n[2][1] and checkConsecutive(lst)): fg=0 elif(n[0][1]==n[1][1] and (abs(int(n[0][0])-int(n[1][0]))==1 or abs(int(n[0][0])-int(n[1][0]))==2)): fg=1 elif(n[1][1]==n[2][1] and (abs(int(n[1][0])-int(n[2][0]))==1 or abs(int(n[1][0])-int(n[2][0]))==2)): fg=1 elif(n[0][1]==n[2][1] and (abs(int(n[0][0])-int(n[2][0]))==1 or abs(int(n[0][0])-int(n[2][0]))==2)): fg=1 elif(init-final==1): fg=1 elif(init-final==2): fg=0 else: fg=2 if(fg==0): print(0) elif(fg==1): print(1) else: print(2)
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
import sys raw = sys.stdin.readline() # raw = open('input.txt', 'r').read().split('\n')[0] tokens = raw.strip().split(' ') by_type = { 'm': [t for t in tokens if t[1] == 'm'], 'p': [t for t in tokens if t[1] == 'p'], 's': [t for t in tokens if t[1] == 's'], } def answer_for_two(i1, i2): if i1 > i2: i1, i2 = i2, i1 if i1 == i2 or i1 + 1 == i2 or i1 + 2 == i2: return 1 return 2 def answer_for_type(t): tokens = sorted(by_type[t]) if len(tokens) == 0: return 3 elif len(tokens) == 1: return 2 elif len(tokens) == 2: i1 = int(tokens[0][0]) i2 = int(tokens[1][0]) return answer_for_two(i1, i2) else: i1 = int(tokens[0][0]) i2 = int(tokens[1][0]) i3 = int(tokens[2][0]) if i1 == i2 == i3 or (i1 + 1 == i2 and i2 + 1 == i3): return 0 return min([ answer_for_two(i1, i2), answer_for_two(i2, i3), answer_for_two(i1, i3), ]) anm = answer_for_type('m') ans = answer_for_type('p') anp = answer_for_type('s') print min([anm, ans, anp])
PYTHON
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
arr = list(map(lambda el: [int(el[0]), el[1]], input().split())) sortt = sorted(arr, key=lambda el: el[0]) result = 2 for i in range(3): cnt1 = 2 cnt2 = 2 base = sortt[i][0] for y in range(i+1, 3): if sortt[i][1] == sortt[y][1]: if sortt[i][0] == sortt[y][0]: cnt1 -= 1 elif sortt[y][0] == base + 1: cnt2 -= 1 elif sortt[y][0] == base + 2: result = 1 base = sortt[y][0] result = min(result, cnt1, cnt2) print(result)
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Scanner; public class Main { static char getSuit(String s) { return s.charAt(1); } static int getNum(String s) { return s.charAt(0) - '0'; } static int equalSuits(String[] suit) { int[] suits = new int[3]; int max = 0; for (int i = 0; i < 3; i++) { int cell = getSuit(suit[i]) == 'm' ? 0 : getSuit(suit[i]) == 'p' ? 1 : 2 ; suits[cell]++; max = Math.max(max, suits[cell]); } return max; } static int equalNum(String[] suit) { int[] nums = new int[10]; int max = 0; for (int i = 0; i < 3; i++) { int num = getNum(suit[i]); nums[num]++; max = Math.max(max, nums[num]); } return max; } static boolean isCont(String[] suit) { int[] nums = new int[3]; for (int i = 0; i < 3; i++) nums[i] = getNum(suit[i]); Arrays.sort(nums); for (int i = 1; i < 3; i++) if (nums[i - 1] + 1 != nums[i]) return false; return true; } static boolean canBeCont(String[] suit){ int[] nums = new int[3]; for (int i = 0; i < 3; i++) nums[i] = getNum(suit[i]); Arrays.sort(nums); for (int i = 0; i < 3; i++) { for (int j = i + 1; j < 3; j++) { if (Math.abs(nums[i] - nums[j]) == 1 || Math.abs(nums[i] - nums[j]) == 2) return true; } } return false; } static char getSuitEqual(String[] suit){ char f = getSuit(suit[0]); char s = getSuit(suit[1]); char t = getSuit(suit[2]); if (f == s || f == t) return f; else return s; } static boolean isOk(String[] suit){ char suitttttt = getSuitEqual(suit); ArrayList<Integer> nums = new ArrayList<>(); for (int i = 0; i < 3; i++) { if (getSuit(suit[i]) == suitttttt){ nums.add(getNum(suit[i])); } } Collections.sort(nums); if (nums.get(1) - nums.get(0) < 3) return true; return false; } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String[] tiles = new String[3]; for (int i = 0; i < 3; i++) tiles[i] = scanner.next(); if (equalSuits(tiles) == 3 && (equalNum(tiles) == 3 || isCont(tiles))){ System.out.println(0); } else if (equalSuits(tiles) == 3 && (equalNum(tiles) > 1 || canBeCont(tiles))) { System.out.println(1); } else if (equalSuits(tiles) == 2 && isOk(tiles)){ System.out.println(1); } else { System.out.println(2); } } } // suits
JAVA
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
#include <bits/stdc++.h> using namespace std; int main() { int x, d, e, f; string a, b, c; cin >> a >> b >> c; d = a[0] - '0'; e = b[0] - '0'; f = c[0] - '0'; if (a == b && b == c && c == a) { x = 0; } else if ((a == b) || a == c || b == c) { x = 1; } else if ((a[1] == b[1] && abs(d - e) <= 2) && (a[1] == c[1] && abs(d - f) <= 2) && (b[1] == c[1] && abs(e - f) <= 2)) { x = 0; } else if ((a[1] == b[1] && abs(d - e) <= 2) || (a[1] == c[1] && abs(d - f) <= 2) || (b[1] == c[1] && abs(e - f) <= 2)) { x = 1; } else { x = 2; } cout << x << endl; return 0; }
CPP
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
s = [x for x in input().split()] n = len(s) d = {} for i in range(n): if s[i][1] in d: d[s[i][1]].append(s[i][0]) else: d[s[i][1]] = [s[i][0]] f = 1 for k in d.keys(): d[k].sort() c = 0 if len(set(d[k])) == len(d[k])-2: f = 0 print(0) elif len(set(d[k])) == len(d[k])-1: f = 0 print(1) else: #print(d[k]) two = 0 for i in range(len(d[k])-1): if int(d[k][i+1])-int(d[k][i])==1: c+=1 if int(d[k][i+1])-int(d[k][i])==2: two+=1 if c==2: f = 0 print(0) break if c==1 or two>=1: f = 0 print(1) break if f==1: print(2)
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
m=[x for x in input().split()] tiles=[[0 for i in range(9)] for j in range(3)] for i in range(len(m)): g=int(m[i][0])-1 h=(m[i][1]) if h=="m": tiles[0][g]+=1 elif h=="p": tiles[1][g]+=1 else: tiles[2][g]+=1 if m[0]==m[1] and m[1]==m[2]: print(0) elif m[0]==m[1]: print(1) elif m[0]==m[2]: print(1) elif m[1]==m[2]: print(1) else: n=False for i in range(3): for j in range(9): if tiles[i][j]!=0: if j!=8 and tiles[i][j+1]!=0: if j!=7 and tiles[i][j+2]!=0: print(0) n=True break else: print(1) n=True break elif j!=7 and j!=8 and tiles[i][j+2]!=0: print(1) n=True break if n==False: print(2)
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
x = [] x = input().split(" ") x1, x2, x3 = [x[i] for i in range(len(x))] newx = (sorted(x)) if x1 == x2 and x2 == x3: print("0") elif x1 == x2 or x1 == x3 or x2 == x3: print("1") else: x1, x2, x3 = [newx[i] for i in range(len(newx))] if x1[1] == x2[1] and x2[1] == x3[1] and abs(int(x1[0])-int(x2[0]))==1 and abs(int(x2[0])-int(x3[0]))==1: print("0") elif x1[1] == x2[1] and (abs(int(x1[0])-int(x2[0]))==1 or abs(int(x1[0])-int(x2[0]))==2): print("1") elif x2[1] == x3[1] and (abs(int(x2[0])-int(x3[0]))==1 or abs(int(x2[0])-int(x3[0]))==2): print("1") elif x3[1] == x1[1] and (abs(int(x3[0])-int(x1[0]))==1 or abs(int(x3[0])-int(x1[0]))==2): print("1") else: print("2")
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
t = input().split(" ") b = [] for i in range(3): b.append(t[i][1]) l2 = len(set(b)) b = list(set(b)) d = {} for i in range(l2): for j in range(3): if b[i]==t[j][1]: if b[i] not in d: d[b[i]] = [int(t[j][0]),] else: d[b[i]].append(int(t[j][0])) d[b[i]].sort() k = 2 m = 2 c = 0 for key, val in d.items(): i = val if len(i)==3: if len(set(i))==1: k = 0 elif len(set(i))==2: k = 1 if i[1]-i[0]==1 and i[2]-i[1]==1: m = 0 elif i[1]-i[0]==1 or i[2]-i[1]==1 or i[1]-i[0]==2 or i[2]-i[1]==2 or i[2]-i[0]==1 or i[2]-i[0]==1: m = min(m, 1) elif len(i)==2: if len(set(i))==1: k = 1 else: if i[1]-i[0]==1 or i[1]-i[0]==2: m = min(m, 1) print(min(k, m))
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
tiles = input().split() l = 0 s = 0 for i in tiles: tmp = 0 for j in tiles: if i == j: tmp += 1 l = max(l, tmp) for i in tiles: for j in tiles: for k in tiles: ans = 1 if (i != j and j != k and i != k): if (int(i[0]) == int(j[0]) + 2 and i[1] == j[1]): ans += 1 if (int(i[0]) == int(k[0]) + 1 and i[1] == k[1]): ans += 1 elif (int(i[0]) == int(j[0]) - 2 and i[1] == j[1]): ans += 1 if (int(i[0]) == int(k[0]) - 1 and i[1] == k[1]): ans += 1 else: if (int(i[0]) == int(j[0]) - 1 and i[1] == j[1]) or (int(i[0]) == int(j[0]) + 1 and i[1] == j[1]): ans += 1 elif (int(i[0]) == int(k[0]) - 1 and i[1] == k[1]) or (int(i[0]) == int(k[0]) + 1 and i[1] == k[1]): ans += 1 s = max(s, ans) print(min(3 - l, 3 - s))
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
import java.io.*; import java.util.*; public class B { static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); static MyScanner sc = new MyScanner(); public static void main(String[] args) { doTask(); out.flush(); } static class Card { Card(Integer a, Character b) { this.a = a; this.b = b; } Integer a; Character b; } static Card parse(String l) { return new Card(Integer.valueOf("" + l.charAt(0)), l.charAt(1)); } public static void doTask(){ String[] cards = sc.nextLine().split(" "); Map<Character, int[]> r = new HashMap<>(); r.put('s', new int[10]); r.put('p', new int[10]); r.put('m', new int[10]); for (int i = 0; i<3; i++) { Card c = parse(cards[i]); r.get(c.b)[c.a]++; } int result = 100; for (char key : r.keySet()) { result = Math.min(result, toKoutsu(r.get(key))); result = Math.min(result, toShuntsu(r.get(key))); } out.println(result); } static int toKoutsu(int[] a) { int result = 100; for (int i=1; i<10; i++) { result = Math.min(3-a[i], result); } return result; } static int toShuntsu(int[] a) { int result = 100; for (int i = 1; i<8; i++) { result = Math.min(3 -Integer.signum(a[i]) - Integer.signum(a[i+1]) - Integer.signum(a[i+2]), result); } return result; } public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine(){ String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
JAVA
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, โ€ฆ, 9m, 1p, 2p, โ€ฆ, 9p, 1s, 2s, โ€ฆ, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] โ€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] โ€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] โ€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings โ€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer โ€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile โ€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
import java.io.*; import java.util.*; public class TokitsukazeandMahjong { public static boolean ascendingOrder(int one, int two, int three) { if(one-two == 1 && two-three==1) { return true; } else if (one - three==1 && three-two==1) { return true; } else if(two-one==1 && one-three==1) { return true; } else if(two-three==1 && three-one==1) { return true; } else if(three-one==1 && one-two==1) { return true; } else if(three-two==1 && two-one==1) { return true; } else return false; } public static boolean twoSame(String tile1, String tile2, String tile3) { if ((tile1.equals(tile2) && !(tile2.equals(tile3))) || (tile1.equals(tile3) && !(tile2.equals(tile3))) || (tile3.equals(tile2) && !(tile1.equals(tile3)))) { return true; } return false; } public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); String tile1 = sc.next(); String tile2 = sc.next(); String tile3 = sc.next(); int one = Integer.parseInt(tile1.substring(0,1)); int two = Integer.parseInt(tile2.substring(0,1)); int three = Integer.parseInt(tile3.substring(0,1)); if ((tile1.equals(tile2) && tile2.equals(tile3)) || (ascendingOrder(one, two, three) == true && tile1.substring(1,2).equals(tile2.substring(1,2)) && tile2.substring(1,2).equals(tile3.substring(1,2)))) { pw.print("0"); } else if (twoSame(tile1, tile2, tile3) || (Math.abs(one-two) == 1 && tile1.substring(1,2).equals(tile2.substring(1,2))) || (Math.abs(one-three) == 1 && tile1.substring(1,2).equals(tile3.substring(1,2))) || (Math.abs(three-two) == 1 && tile2.substring(1,2).equals(tile3.substring(1,2))) || (Math.abs(one-two) == 2 && tile1.substring(1,2).equals(tile2.substring(1,2))) || (Math.abs(one-three) == 2 && tile1.substring(1,2).equals(tile3.substring(1,2))) || (Math.abs(three-two) == 2 && tile2.substring(1,2).equals(tile3.substring(1,2)))) { pw.print("1"); } else { pw.print("2"); } sc.close(); pw.close(); } }
JAVA