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
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader sc = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Task solver = new Task(); solver.solve(1, sc, out); out.close(); } static class Task { public boolean check0(int[] p,int[] s,int[] m) { for(int i=1;i<=7;i++) { if(p[i]==1&&p[i+1]==1&&p[i+2]==1) return true; if(s[i]==1&&s[i+1]==1&&s[i+2]==1) return true; if(m[i]==1&&m[i+1]==1&&m[i+2]==1) return true; } for(int i=1;i<=9;i++) { if(p[i]==3||s[i]==3||m[i]==3) return true; } return false; } public boolean check1(int[] p,int[] s,int[] m) { for(int i=1;i<=9;i++) { if(p[i]==2||s[i]==2||m[i]==2) return true; } for(int i=1;i<=8;i++) { if(p[i]==1&&p[i+1]==1) return true; if(s[i]==1&&s[i+1]==1) return true; if(m[i]==1&&m[i+1]==1) return true; } for(int i=1;i<=7;i++) { if(p[i]==1&&p[i+2]==1) return true; if(s[i]==1&&s[i+2]==1) return true; if(m[i]==1&&m[i+2]==1) return true; } return false; } public void solve(int testNumber, InputReader sc, PrintWriter out) { int[] p=new int[10]; int[] s=new int[10]; int[] m=new int[10]; for(int i=0;i<3;i++) { char[] res=sc.next().toCharArray(); if(res[1]=='p') p[res[0]-'0']++; if(res[1]=='s') s[res[0]-'0']++; if(res[1]=='m') m[res[0]-'0']++; } if(check0(p,s,m)) { out.println("0"); return ; } if(check1(p,s,m)) { out.println("1"); return ; } out.println("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()); } } }
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.util.Arrays; import java.util.Scanner; public class TokitsuzakeAndMahjong { public static void main(String[] args) { Scanner scan=new Scanner(System.in); int onee[]=new int[3]; String two[]=new String[3]; for(int i=0;i<3;i++) { two[i]=scan.next(); // onee[i]=Integer.parseInt(one.substring(0,one.length()-1)); } Arrays.sort(two);int count=0; for(int i=0;i<3;i++) { for(int j=i+1;j<3;j++) { if(two[i].equals(two[j]))count++; }} if(count==3)System.out.println(0); else {if(count==1)System.out.println(1); else {count=0;boolean q=false; String nee= Integer.parseInt(two[0].substring(0,two[0].length()-1))+2+two[0].substring(two[0].length()-1); for(int i=1;i<3;i++) { int j=i-1; String d=Integer.parseInt(two[j].substring(0,two[j].length()-1))+1+two[j].substring(two[j].length()-1); if(two[i].equals(d))count++; String diff=Integer.parseInt(two[j].substring(0,two[j].length()-1))+2+two[j].substring(two[j].length()-1); if(two[i].equals(diff)||two[2].equals(nee)) { q=true; } } if(count==0) { String l=Integer.parseInt(two[2].substring(0,two[2].length()-1))-1+two[2].substring(two[2].length()-1); if(two[0].equals(l))count++; } if(count==2)System.out.println(0); if(count==1)System.out.println(1); if(count==0&&q==true) { System.out.println(1); } if(count==0&&q==false)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
t1,t2,t3 = map(str, input().split(" ")) arr = sorted([int(t1[0]),int(t2[0]),int(t3[0])]) if (t1 == t2 and t2 == t3) or (t1[1] == t2[1] and t2[1] == t3[1] and (arr[2] - arr[1]) == 1 and (arr[1] - arr[0]) == 1): print(0) elif (t1 == t2 or t2 == t3 or t3 == t1): print(1) elif (t1[1] == t2[1] and (abs(int(t1[0]) - int(t2[0])) == 1 or abs(int(t1[0]) - int(t2[0])) == 2)): print(1) elif (t2[1] == t3[1] and (abs(int(t3[0]) - int(t2[0])) == 1 or abs(int(t3[0]) - int(t2[0])) == 2)): print(1) elif (t1[1] == t3[1] and (abs(int(t1[0]) - int(t3[0])) == 1 or abs(int(t1[0]) - int(t3[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
s = sorted(input().split()) a1 = set(s) if len(a1) == 1: print(0) else: max_len = {} ans = 2 i0 = s[0][1] i1 = int(s[0][0]) for i in s: max_len[i[1]] = [] for i in s: max_len[i[1]].append(int(i[0])) for i in max_len.keys(): temp = max_len[i] if len(temp) == 3: one = temp[1] - temp[0] two = temp[2] - temp[1] if one == two == 1: ans = 0 else: if one == 1 or two == 1 or one == 2 or two == 2: ans = 1 else: ans = 2 elif len(temp) == 2: if (temp[1] - temp[0]) == 1 or (temp[1] - temp[0]) == 2: ans = 1 else: ans = 2 print(min(len(a1) - 1, 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 = list(input().split()) k = dict() mk = 0 s = 0 for e in a: if e not in k: k[e] = 0 k[e] += 1 if k[e] > mk: mk = k[e] for e in a: temp = 1 num = int(e[0]) t = e[1] if (str(num + 1) + t) in k: temp += 1 if (str(num - 1) + t) in k: temp += 1 elif (str(num - 1) + t) in k: temp += 1 if (str(num + 1) + t) in k: temp += 1 elif (str(num - 2) + t) in k: temp += 1 elif (str(num + 2) + t) in k: temp += 1 if temp > s: s = temp if s > mk: print(3 - s) else: print(3 - mk)
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; public class Mahjong { public static void main(String args[])throws IOException{ BufferedReader in =new BufferedReader(new InputStreamReader(System.in)); String[] line=in.readLine().split(" "); Arrays.sort(line); ArrayList<String> game=new ArrayList<String>(); for(String x:line) game.add(x); Collections.sort(game); if(game.get(0).equals(game.get(1)) && game.get(0).equals(game.get(2))){ System.out.println(0); } else if((game.get(0).substring(1, 2).equals(game.get(1).substring(1,2)) && (Integer.parseInt(game.get(0).substring(0,1))==Integer.parseInt(game.get(1).substring(0,1))-1))&&(game.get(1).substring(1, 2).equals(game.get(2).substring(1,2)) && (Integer.parseInt(game.get(1).substring(0,1))==Integer.parseInt(game.get(2).substring(0,1))-1))){ System.out.println(0); } else if(game.get(0).equals(game.get(1)) || game.get(0).equals(game.get(2)) || game.get(1).equals(game.get(2))){ System.out.println(1); } else if((game.get(0).substring(1, 2).equals(game.get(1).substring(1,2)) && (Integer.parseInt(game.get(0).substring(0,1))==Integer.parseInt(game.get(1).substring(0,1))-1 || Integer.parseInt(game.get(0).substring(0,1))==Integer.parseInt(game.get(1).substring(0,1))-2)) || (game.get(1).substring(1, 2).equals(game.get(2).substring(1,2)) && (Integer.parseInt(game.get(1).substring(0,1))==Integer.parseInt(game.get(2).substring(0,1))-1 || Integer.parseInt(game.get(1).substring(0,1))==Integer.parseInt(game.get(2).substring(0,1))-2)) || (game.get(0).substring(1, 2).equals(game.get(2).substring(1,2)) && (Integer.parseInt(game.get(0).substring(0,1))==Integer.parseInt(game.get(2).substring(0,1))-1 || Integer.parseInt(game.get(0).substring(0,1))==Integer.parseInt(game.get(2).substring(0,1))-2))){ System.out.println(1); } else{ 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
h = [hi for hi in raw_input().split(" ")] suits = ['m','p','s'] k23 = [] kf = [] s23 = [] sf = [] a = 1 b = 9 for i in range(a,b+1): # print i,i,i for suit in suits: k23 += [[str(i)+suit,str(i)+suit]] kf += [[str(i)+suit,str(i)+suit,str(i)+suit]] for i in range(a,b): for suit in suits: s23 += [[str(i)+suit,str(i+1)+suit]] for i in range(a,b-1): for suit in suits: s23 += [[str(i)+suit,str(i+2)+suit]] for i in range(a,b-1): for suit in suits: sf += [[str(i)+suit,str(i+1)+suit,str(i+2)+suit]] h012 = [h[0]]+[h[1]]+[h[2]] h021 = [h[0]]+[h[2]]+[h[1]] h102 = [h[1]]+[h[0]]+[h[2]] h120 = [h[1]]+[h[2]]+[h[0]] h201 = [h[2]]+[h[0]]+[h[1]] h210 = [h[2]]+[h[1]]+[h[0]] h01 = [h[0]]+[h[1]] h02 = [h[0]]+[h[2]] h10 = [h[1]]+[h[0]] h12 = [h[1]]+[h[2]] h20 = [h[2]]+[h[0]] h21 = [h[2]]+[h[1]] if h012 in kf or h012 in sf: print 0 elif h021 in kf or h021 in sf: print 0 elif h102 in kf or h102 in sf: print 0 elif h120 in kf or h120 in sf: print 0 elif h201 in kf or h201 in sf: print 0 elif h210 in kf or h210 in sf: print 0 elif h01 in k23 or h01 in s23: print 1 elif h02 in k23 or h02 in s23: print 1 elif h10 in k23 or h10 in s23: print 1 elif h12 in k23 or h12 in s23: print 1 elif h20 in k23 or h20 in s23: print 1 elif h21 in k23 or h21 in s23: print 1 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
a=input().split() a.sort() b=[int(a[0][0]),int(a[1][0]),int(a[2][0])] e=[a[0][1],a[1][1],a[2][1]] if(len(set(a))==1): print(0) elif a[0]==a[1] or a[1]==a[2]: print(1) elif(len(set(e))==3): print(2) elif(len(set(e))==1): b.sort() k=2 o=0 if b[1]-b[0]==1: k-=1 o=1 if b[2]-b[1]==1: k-=1 o=1 if o==0 and ((b[1]-b[0]!=1 and b[1]-b[0]==2) or (b[1]-b[0]==2 and b[1]-b[0]!=1) or (b[1]-b[0]==2 and b[1]-b[0]==2)): k-=1 print(k) else: if e[0]==e[1]: if abs(b[0]-b[1])==1 or abs(b[0]-b[1])==2: print(1) else: print(2) elif e[1]==e[2]: if abs(b[1]-b[2])==1 or abs(b[1]-b[2])==2: print(1) else: print(2) elif e[0]==e[2]: if abs(b[0]-b[2])==1 or abs(b[0]-b[2])==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
import java.util.Arrays; import java.util.Scanner; public class Hp { public static void main(String[] args) { Scanner in = new Scanner(System.in); int[] idx = new int[257]; int[][] count = new int[3][9]; idx['m']=1; idx['p']=2; idx['s']=3; for(int i=0;i<3;i++) { char[] x = in.next().toCharArray(); ++count[idx[x[1]]-1][x[0]-'1']; } int ans =2; for(int i=0;i<3;i++) { for(int j=0;j<9;j++) { ans = Math.min(ans,3-count[i][j]); if(j+2<9) { if(count[i][j]!=2&&count[i][j+1]!=2&&count[i][j+2]!=2) ans = Math.min(ans,3-count[i][j]-count[i][j+1]-count[i][j+2]); } } } System.out.println(ans); } }
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 num[4]; template <class T> int check_mod(T a, T b) { return (a % b) ? 1 : 0; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); vector<string> cards(3); for (int i = 0; i < 3; i++) cin >> cards[i]; sort(cards.begin(), cards.end()); if ((cards[0] == cards[1] && cards[1] == cards[2]) || ((cards[0][1] == cards[1][1] && cards[1][1] == cards[2][1]) && (cards[1][0] == cards[0][0] + 1 && cards[2][0] == cards[1][0] + 1))) { cout << 0 << endl; return 0; } if (cards[0] == cards[1] || cards[1] == cards[2] || cards[0] == cards[2]) { cout << 1 << endl; return 0; } if (cards[0][1] == cards[1][1] && (abs(cards[0][0] - cards[1][0]) == 1 || abs(cards[0][0] - cards[1][0]) == 2)) { cout << 1 << endl; return 0; } if (cards[0][1] == cards[2][1] && (abs(cards[0][0] - cards[2][0]) == 1 || abs(cards[0][0] - cards[2][0]) == 2)) { cout << 1 << endl; return 0; } if (cards[2][1] == cards[1][1] && (abs(cards[2][0] - cards[1][0]) == 1 || abs(cards[2][0] - cards[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
import java.io.*; import java.util.*; import java.math.*; import java.lang.*; import static java.lang.Math.*; public class Cf182 implements Runnable { static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; private BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars==-1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if(numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public int nextInt() { int c = read(); while(isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if(c<'0'||c>'9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public double nextDouble() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } public static void main(String args[]) throws Exception { new Thread(null, new Cf182(),"Main",1<<27).start(); } public static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } // array sorting by colm public static void sortbyColumn(int arr[][], int col) { Arrays.sort(arr, new Comparator<int[]>() { @Override public int compare(final int[] entry1, final int[] entry2) { if (entry1[col] > entry2[col]) return 1; else return -1; } }); } // gcd public static long findGCD(long arr[], int n) { long result = arr[0]; for (int i = 1; i < n; i++) result = gcd(arr[i], result); return result; } // fibonaci static int fib(int n) { int a = 0, b = 1, c; if (n == 0) return a; for (int i = 2; i <= n; i++) { c = a + b; a = b; b = c; } return b; } // sort a string public static String sortString(String inputString) { char tempArray[] = inputString.toCharArray(); Arrays.sort(tempArray); return new String(tempArray); } // pair function // list.add(new Pair<>(sc.nextInt(), i + 1)); // Collections.sort(list, (a, b) -> Integer.compare(b.first, a.first)); private static class Pair<F, S> { private F first; private S second; public Pair() {} public Pair(F first, S second) { this.first = first; this.second = second; } } static long negProdSubArr(int arr[], int n) { long positive = 1, negative = 0; for (int i = 0; i < n; i++) { if (i > 0) arr[i] *= arr[i - 1]; if (arr[i] == 1) positive++; else negative++; } return (positive * negative); } public void run() { InputReader sc = new InputReader(System.in); PrintWriter w = new PrintWriter(System.out); String s1 = sc.next(); String s2 = sc.next(); String s3 = sc.next(); int c1 = s1.charAt(0)-48; int c2 = s2.charAt(0)-48; int c3 = s3.charAt(0)-48; if(s1.equals(s2) && s2.equals(s3)) w.println("0"); else if(s1.charAt(1)==s2.charAt(1) && s2.charAt(1)==s3.charAt(1)) { if(c1+1==c2 && c2+1==c3) w.println("0"); else if(c1+1==c3 && c3+1==c2) w.println("0"); else if(c2+1==c1 && c1+1==c3) w.println("0"); else if(c2+1==c3 && c3+1==c1) w.println("0"); else if(c3+1==c2 && c2+1==c1) w.println("0"); else if(c3+1==c1 && c1+1==c2) w.println("0"); else if(c1+1==c2 || c1+1==c3 || c2+1==c3 || c2+1==c1 || c3+1==c2 || c3+1==c1) w.println("1"); else if(c1+2==c2 || c1+2==c3 || c2+2==c3 || c2+2==c1 || c3+2==c2 || c3+2==c1) w.println("1"); else if(s1.equals(s2) || s1.equals(s3) || s2.equals(s3)) w.println("1"); else w.println("2"); } else { int ans = 5; if((c1+1==c2 || c2+1==c1) && s1.charAt(1)==s2.charAt(1)) ans = Math.min(ans,1); else if((c1+1==c3 || c3+1==c1) && s1.charAt(1)==s3.charAt(1)) ans = Math.min(ans,1); else if((c2+1==c3 || c3+1==c2 ) && s2.charAt(1)==s3.charAt(1)) ans = Math.min(ans,1); else if((c1+2==c2 || c2+2==c1) && s1.charAt(1)==s2.charAt(1)) ans = Math.min(ans,1); else if((c1+2==c3 || c3+2==c1) && s1.charAt(1)==s3.charAt(1)) ans = Math.min(ans,1); else if((c2+2==c3 || c3+2==c2 ) && s2.charAt(1)==s3.charAt(1)) ans = Math.min(ans,1); else if(s1.equals(s2)) ans = Math.min(ans,1); else if(s1.equals(s3)) ans = Math.min(ans,1); else if(s2.equals(s3)) ans = Math.min(ans,1); else ans = Math.min(ans,2); w.println(ans); } w.flush(); w.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
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.StringTokenizer; public class Main { public static void main(String[] args) { MyScanner sc = new MyScanner(); String[] str = sc.nextLine().split(" "); Map<Character, List<Integer>> map = new HashMap<>(); for (int i = 0; i < 3; i++) { String s = str[i]; map.compute(s.charAt(1), (k, v) -> { if (v == null) { v = new ArrayList<>(); } v.add(Integer.valueOf(s.substring(0, 1))); return v; }); } int res = 2; for (List<Integer> list : map.values()) { Collections.sort(list); int inARow = 0; int theSame = 0; int prev = list.get(0); for (int i = 1; i < list.size(); i++) { int next = list.get(i); if (next == prev) { theSame++; } if (next - 1 == prev) { inARow++; } if (next - 2 == prev) { inARow = 1; break; } prev = next; } res = Math.min(res, Math.min(2 - theSame, 2 - inARow)); } System.out.println(res); } 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.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.io.BufferedReader; import java.io.InputStream; public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Task solver = new Task(); solver.solve(1, in, out); out.close(); } static class Task { public int same(int a[]){ int max=0; for(int i=0;i<10;i++) max=Math.max(a[i],max); return 3-max; } public int sequence(int a[],PrintWriter out){ int max,cur; max=0; cur=0; for(int i=0;i<10;i++){ //out.print(a[i]); if(a[i] > 0){ cur++; } else if(a[i]==0){ if(cur == 1 && i+1 <10 && a[i+1]>0 ){ cur++; max=Math.max(max,cur); } cur=0; } max=Math.max(max,cur); } return 3-max; } public int solve(int testNumber, InputReader in, PrintWriter out) { String s; int ind,min; int[][] a; min=10; a=new int[3][10]; for(int i=0;i<3;i++){ s=in.next(); if(s.charAt(1) == 's') ind=0; else if(s.charAt(1) == 'm') ind=1; else ind=2; a[ind][Character.getNumericValue(s.charAt(0))]++; } for(int j=0;j<3;j++){ min=Math.min(min,same(a[j])); min=Math.min(min,sequence(a[j],out)); //out.println(); } out.println(min); return 0; } } 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()); } } }
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 buc[101][101], ans = 0x3f3f3f3f; char ch1, ch2; int hash_(char c) { if (c == 'm') return 1; if (c == 'p') return 2; if (c == 's') return 3; } int main() { while (~scanf("%c%c%*c", &ch1, &ch2)) { ++buc[hash_(ch2)][ch1 - '0']; } for (int i = 1; i <= 9; ++i) { for (int j = 1; j <= 3; ++j) { ans = min(ans, 3 - buc[j][i]); } } for (int j = 1; j <= 3; ++j) { for (int i = 1; i <= 7; ++i) { ans = min( ans, 3 - (bool)buc[j][i] - (bool)buc[j][i + 1] - (bool)buc[j][i + 2]); } } printf("%d\n", 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
d = {} for i in ['s', 'm', 'p']: for j in range(1, 10): d[str(j)+i] = 0 keys = list(d.keys()) for i in input().split(): d[i] += 1 def is_valid0(): for i in range(3): for j in range(9): if d[keys[i*9:i*9+9][j]] > 2: return True for j in range(7): if d[keys[i*9:i*9+9][j]] > 0 and d[keys[i*9:i*9+9][j+1]] > 0 and d[keys[i*9:i*9+9][j+2]] > 0: return True return False def is_valid1(): for i in range(3): for j in range(9): if d[keys[i*9:i*9+9][j]] > 1: return True for j in range(7): if d[keys[i*9:i*9+9][j]] > 0 and d[keys[i*9:i*9+9][j+1]] > 0: return True if d[keys[i*9:i*9+9][j+1]] > 0 and d[keys[i*9:i*9+9][j+2]] > 0: return True if d[keys[i*9:i*9+9][j]] > 0 and d[keys[i*9:i*9+9][j+2]] > 0: return True return False if is_valid0(): print(0) elif is_valid1(): 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
data = input().split() data.sort() dic = {"s":[], "m":[], "p":[]} for d in data: dic[d[1]].append(d) #mx = max([len(l) for l in dic.values()]) vals = list(dic.values()) vals.sort(key=lambda a: len(a)) lis = vals[-1] lis.sort() if len(lis) == 3: # sm = 0 # for a in range(2): # if lis[a] == lis[a+1]: # sm += 1 # if sm == 2: # print(0) # elif sm == 1: if lis[0] == lis[1]: if lis[1] == lis[2]: print(0) else: print(1) else: if lis[1] == lis[2]: print(1) else: ns = [int(a[0]) for a in lis] ns.sort() if ns[0] + 1 == ns[1]: if ns[1] + 1 == ns[2]: print(0) else: print(1) elif ns[0] + 2 == ns[1]: print(1) else: if ns[1] + 1 == ns[2] or ns[1] + 2 == ns[2]: print(1) else: print(2) elif len(lis) == 2: ns = [int(a[0]) for a in lis] ns.sort() if ns[0] == ns[1] or ns[0] + 1 == ns[1] or ns[0] + 2 == ns[1]: print(1) else: print(2) else: print(2) # if data[0] == data[1]: # pass # else: # if data[1] == data[2]: # print(1) # else
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 itertools import combinations from collections import defaultdict from copy import deepcopy import sys input = sys.stdin.readline ''' for CASES in range(int(input())): n, m = map(int, input().split()) n = int(input()) A = list(map(int, input().split())) S = input().strip() sys.stdout.write(" ".join(map(str,ans))+"\n") ''' inf = 100000000000000000 # 1e17 mod = 998244353 B = ["1s", "2s", "3s", "4s", "5s", "6s", "7s", "8s", "9s", "1m", "2m", "3m", "4m", "5m", "6m", "7m", "8m", "9m", "1p", "2p", "3p", "4p", "5p", "6p", "7p", "8p", "9p"] A = list(map(str, input().split())) A.sort() def check(a, b, c): if (C[a][1] == C[b][1] == C[c][1] and ord(C[a][0]) + ord(C[c][0]) == ord(C[b][0]) * 2 and ord(C[b][0]) - ord(C[a][0]) == 1): return 1 else: return 0 if A[-1] == A[-2] == A[-3]: print(0) elif A[-1] == A[-2] or A[-2] == A[-3]: print(1) else: if A[0][1] == A[1][1] == A[2][1] and ord(A[0][0]) + ord(A[2][0]) == ord(A[1][0]) * 2 and ord(A[1][0]) - ord(A[0][0]) == 1: print(0) sys.exit() for b in B: C = deepcopy(A) C.append(b) C.sort() for a,b,c in combinations([0,1,2,3],3): if check(a,b,c): print(1) sys.exit() print(2) # the end
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
k = {"m":[0] * 9, "s":[0] * 9, "p":[0] * 9} p = 1 a = list(map(str, input().split())) for i in a: k[i[1]][int(i[0])-1] += 1 for j in k: for i in range(7): if(k[j][i] == 2 or k[j][i+1] == 2 or k[j][i+2] == 2): p = max(2, p) continue x = k[j][i] + k[j][i+1] + k[j][i+2] p = max(p, x) print(3 - p)
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() if len(set(a)) == 1: print(0) elif len(set(a)) == 2: print(1) else: d = {} for i in a: n = int(i[0]) c = i[1] if c in d: d[c].append(n) else: d[c] = [n] v = list(d.values()) cond0 = False cond1 = False # print (d,v) for i in v: if len(i) == 2: i = sorted(i) x = i[0] y = i[1] if x + 1 == y or y - x == 2: cond1 = True if len(i) == 3: i = sorted(i) x = i[0] y = i[1] z = i[2] if x + 1 == y and y + 1 == z: cond0 = True if (x+1 == y) or (x+2 == y) or (y+2 ==z) or (y+1 ==z): cond1 = True if cond0: print(0) elif cond1: 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
#include <bits/stdc++.h> using namespace std; int s[15], p[15], m[15], ans, l, i, j, minim = 9; string s1[5]; int main() { for (int i = 0; i < 3; ++i) { cin >> s1[i]; if (s1[i][1] == 's') s[s1[i][0] - '0']++; if (s1[i][1] == 'p') p[s1[i][0] - '0']++; if (s1[i][1] == 'm') m[s1[i][0] - '0']++; } for (i = 1; i <= 9; i++) { if (s[i] == 3 || p[i] == 3 || m[i] == 3) ans = 0; else if ((s[i] == 1 && s[i + 1] == 1 && s[i + 2] == 1) || (m[i] == 1 && m[i + 1] == 1 && m[i + 2] == 1) || (p[i] == 1 && p[i + 1] == 1 && p[i + 2] == 1)) ans = 0; else if (((s[i] == 1 && s[i + 1] == 1) || (s[i] == 1 && s[i + 2] == 1)) || ((m[i] == 1 && m[i + 1] == 1) || (m[i] == 1 && m[i + 2] == 1)) || ((p[i] == 1 && p[i + 1] == 1) || (p[i] == 1 && p[i + 2] == 1)) || s[i] == 2 || m[i] == 2 || p[i] == 2) ans = 1; else ans = 2; if (ans < minim) minim = ans; } cout << minim; 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
#Tokitsukaze and Mahjong DEBUG = False def debug(to_print_args): if not DEBUG: return for arg in to_print_args: print(arg,end='') print() # def shuntsu(num1,num2,num3,a1,a2,a3): # if num1+1=num2 and num1+2=num3: # if a1=a2 and a2=a3: # return True; # else a=input().split() strings=[a[0][1],a[1][1],a[2][1]]; numbers=[a[0][0],a[1][0],a[2][0]]; numbers=list(map(int,numbers)); if strings[0]==strings[1] and strings[1]==strings[2]: numbers.sort() if numbers[0]==numbers[1] and numbers[1]==numbers[2]: print(0); elif abs(numbers[0]-numbers[1])==1 and abs(numbers[2]-numbers[1])==1 and abs(numbers[2]-numbers[0])==2: print(0); elif abs(numbers[0]-numbers[1])==1 and abs(numbers[2]-numbers[1])==1 and abs(numbers[2]-numbers[0])==1: print(1); elif abs(numbers[0]-numbers[1])==1 or abs(numbers[1]-numbers[2])==1 or abs(numbers[0]-numbers[2])==1: print(1); elif numbers[0]==numbers[1] or numbers[1]==numbers[2] or numbers[0]==numbers[2]: print(1); elif abs(numbers[0]-numbers[1])==2 or abs(numbers[1]-numbers[2])==2 or abs(numbers[0]-numbers[2])==2: print(1); else: print(2); elif strings[0]==strings[1]: if numbers[0]==numbers[1]: print(1); elif abs(numbers[0]-numbers[1])==1: print(1); elif abs(numbers[0]-numbers[1])==2: print(1); else: print(2); elif strings[2]==strings[1]: if numbers[2]==numbers[1]: print(1); elif abs(numbers[2]-numbers[1])==1: print(1); elif abs(numbers[2]-numbers[1])==2: print(1); else: print(2); elif strings[0]==strings[2]: if numbers[0]==numbers[2]: print(1); elif abs(numbers[0]-numbers[2])==1: print(1); elif abs(numbers[0]-numbers[2])==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
''' Auther: ghoshashis545 Ashis Ghosh College: jalpaiguri Govt Enggineering College ''' from os import path import sys from heapq import heappush,heappop from functools import cmp_to_key as ctk from collections import deque,defaultdict as dd from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right from itertools import permutations from datetime import datetime from math import ceil,sqrt,log,gcd def ii():return int(input()) def si():return input().rstrip() def mi():return map(int,input().split()) def li():return list(mi()) abc='abcdefghijklmnopqrstuvwxyz' mod=1000000007 # mod=998244353 inf = float("inf") vow=['a','e','i','o','u'] dx,dy=[-1,1,0,0],[0,0,1,-1] def bo(i): return ord(i)-ord('a') file=1 def solve(): # for _ in range(ii()): s = list(map(str,input().split())) m = {} m['s'] = [] m['p'] = [] m['m'] = [] for i in s: m[i[1]].append(int(i[0])) if len(set(s))==1: print(0) elif(len(set(s))==2): print(1) elif(len(m['s'])==3): p = [m['s'][0],m['s'][1],m['s'][2]] p.sort() if p[1]-p[0]==1 and p[2]-p[1]==1: print(0) elif(p[1]-p[0]==2 or p[2]-p[1]==2 or p[1]-p[0]==1 or p[2]-p[1]==1): print(1) else: print(2) elif(len(m['p'])==3): p = [m['p'][0],m['p'][1],m['p'][2]] p.sort() if p[1]-p[0]==1 and p[2]-p[1]==1: print(0) elif(p[1]-p[0]==2 or p[2]-p[1]==2 or p[1]-p[0]==1 or p[2]-p[1]==1): print(1) else: print(2) elif(len(m['m'])==3): p = [m['m'][0],m['m'][1],m['m'][2]] p.sort() if p[1]-p[0]==1 and p[2]-p[1]==1: print(0) elif(p[1]-p[0]==2 or p[2]-p[1]==2 or p[1]-p[0]==1 or p[2]-p[1]==1): print(1) else: print(2) elif(len(m['s'])==2 and (abs(m['s'][0]-m['s'][1]) == 1 or abs(m['s'][0]-m['s'][1])==2)): print(1) elif(len(m['p'])==2 and (abs(m['p'][0]-m['p'][1]) == 1 or abs(m['p'][0]-m['p'][1])==2)): print(1) elif(len(m['m'])== 2 and (abs(m['m'][0]-m['m'][1]) == 1 or abs(m['m'][0]-m['m'][1])==2)): print(1) else: print(2) if __name__ =="__main__": if(file): if path.exists('input.txt'): sys.stdin=open('input.txt', 'r') sys.stdout=open('output.txt','w') else: input=sys.stdin.readline 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
import java.io.*; import java.math.BigInteger; import java.net.SocketTimeoutException; import java.util.Arrays; import java.util.InputMismatchException; import java.util.StringTokenizer; public class B { static class FastWriter { private final BufferedWriter bw; public FastWriter() { this.bw = new BufferedWriter(new OutputStreamWriter(System.out)); } public void print(Object object) throws IOException { bw.append("" + object); } public void println(Object object) throws IOException { print(object); bw.append("\n"); } public void close() throws IOException { bw.close(); } } 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; } BigInteger nextBigInteger() { try { return new BigInteger(nextLine()); } catch (NumberFormatException e) { throw new InputMismatchException(); } } } public static void main(String[] args) { FastReader fr = new FastReader(); FastWriter fw = new FastWriter(); String s = fr.nextLine(); String[] arr = s.split(" "); Arrays.sort(arr); if (arr[0].equals(arr[1]) && arr[1].equals(arr[2])) System.out.println(0); else if (arr[2].charAt(0) - 1 == arr[1].charAt(0) && arr[1].charAt(0) - 1 == arr[0].charAt(0) && arr[0].charAt(1) == arr[1].charAt(1) && arr[1].charAt(1) == arr[2].charAt(1)) System.out.println(0); else if (arr[0].equals(arr[1]) || arr[1].equals(arr[2])) System.out.println(1); else if ((arr[2].charAt(0) - 1 == arr[1].charAt(0) && arr[1].charAt(1) == arr[2].charAt(1))) System.out.println(1); else if (arr[1].charAt(0) - 1 == arr[0].charAt(0) && arr[0].charAt(1) == arr[1].charAt(1)) System.out.println(1); else if (arr[2].charAt(0) - 1 == arr[0].charAt(0) && arr[0].charAt(1) == arr[2].charAt(1)) System.out.println(1); else if ((arr[2].charAt(0) - 2 == arr[1].charAt(0) && arr[1].charAt(1) == arr[2].charAt(1))) System.out.println(1); else if (arr[1].charAt(0) - 2 == arr[0].charAt(0) && arr[0].charAt(1) == arr[1].charAt(1)) System.out.println(1); else if (arr[2].charAt(0) - 2 == arr[0].charAt(0) && arr[0].charAt(1) == arr[2].charAt(1)) System.out.println(1); else 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
#import resource import sys #resource.setrlimit(resource.RLIMIT_STACK, [0x100000000, resource.RLIM_INFINITY]) #import threading #threading.Thread(target=main).start() #threading.stack_size(2**26) #sys.setrecursionlimit(10**6) mod=(10**9)+7 #fact=[1] #for i in range(1,100001): # fact.append((fact[-1]*i)%mod) #ifact=[0]*100001 #ifact[100000]=pow(fact[100000],mod-2,mod) #for i in range(100000,0,-1): # ifact[i-1]=(i*ifact[i])%mod from sys import stdin, stdout import bisect from bisect import bisect_left as bl from bisect import bisect_right as br import itertools import collections import math import heapq #from random import randint as rn #from Queue import Queue as Q def modinv(n,p): return pow(n,p-2,p) def ncr(n,r,p): t=((fact[n])*((ifact[r]*ifact[n-r])%p))%p return t def ain(): return map(str,sin().split()) def sin(): return stdin.readline().strip() def GCD(x,y): while(y): x, y = y, x % y return x def isprime(x): if(x==1): return False elif(x<4): return True for i in range(2,int(math.sqrt(x))+1): if(x%i==0): return False return True """**************************************************************************""" s=ain() t=10**18 x=[] for i in range(3): if(i==0): w="s" elif(i==1): w="p" else: w="m" for j in range(1,10): x.append([str(j)+w,str(j)+w,str(j)+w]) for i in range(3): if(i==0): w="s" elif(i==1): w="p" else: w="m" for j in range(1,8): x.append([str(j)+w,str(j+1)+w,str(j+2)+w]) for i in range(len(x)): for j in range(3): if(s[j] in x[i]): x[i].remove(s[j]) t=min(t,len(x[i])) print t
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
s=input().split() l=[] s.sort() for i in s: l.append(int(i[0])) l.append(i[1]) if l[0]==l[2] and l[1]==l[3]: if l[0]==l[4] and l[1]==l[5]: print(0) else: print(1) elif l[4]==l[2] and l[5]==l[3]: print(1) elif l[0]+1==l[2] and l[1]==l[3]: if l[2]+1==l[4] and l[3]==l[5]: print(0) else: print(1) elif l[0]+2==l[2] and l[1]==l[3]: print(1) elif l[2]+1==l[4] and l[5]==l[3]: print(1) elif l[2]+2==l[4] and l[5]==l[3]: print(1) elif l[0]+1==l[4] and l[1]==l[5]: print(1) elif l[0]+2==l[4] and l[1]==l[5]: 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
#d=[[] for i in range(26)] a=[0]*26 d={'p':[],'s':[],'m':[]} for i in input().split(): d[i[1]]+=int(i[0]), a[ord(i[1])-97]+=1 if max(a)==1:print(2) else: x=chr(a.index(max(a))+97);v=[] if len(d[x])==2: g=abs(d[x][0]-d[x][1]) if g==1 or g==0 or g==2:print(1) else:print(2) else: v+=abs(d[x][0]-d[x][1]), v+=abs(d[x][0]-d[x][2]), v+=abs(d[x][1]-d[x][2]), if v.count(0)>1:print(0) elif v.count(0)==1:print(1) elif v.count(1)==2:print(0) elif v.count(1)==1 or v.count(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
l = [x for x in input().split()] l.sort() if l[0] == l[2]: print(0) elif int(l[0][0]) + 2 == int(l[1][0]) + 1 == int(l[2][0]) and l[0][1] == l[1][1] == l[2][1]: print(0) elif l[0][1] == l[1][1] and int(l[1][0]) - int(l[0][0]) <= 2: print(1) elif l[1][1] == l[2][1] and int(l[2][0]) - int(l[1][0]) <= 2: print(1) elif l[2][1] == l[0][1] and int(l[2][0]) - int(l[0][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
d = [[0] * 10 for i in range(3)] for i in input().split(): if i[1] == 'm': d[0][int(i[0])] += 1 elif i[1] == 'p': d[1][int(i[0])] += 1 else: d[2][int(i[0])] += 1 for i in range(3): for j in range(10): if d[i][j] == 3: print(0) exit() for i in range(3): for j in range(10): if d[i][j] == 2: print(1) exit() for i in d: for j in range(1, 8): if sum(i[j:j + 3]) == 3: print(0) exit() for i in d: for j in range(1, 8): if sum(i[j:j + 3]) == 2: print(1) 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
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; string a, b, c; cin >> a >> b >> c; vector<int> m(10, 0); vector<int> p(10, 0); vector<int> s(10, 0); if (a[1] == 'm') { m[a[0] - 48]++; } else if (a[1] == 'p') { p[a[0] - 48]++; } else if (a[1] == 's') { s[a[0] - 48]++; } if (b[1] == 'm') { m[b[0] - 48]++; } else if (b[1] == 'p') { p[b[0] - 48]++; } else if (b[1] == 's') { s[b[0] - 48]++; } if (c[1] == 'm') { m[c[0] - 48]++; } else if (c[1] == 'p') { p[c[0] - 48]++; } else if (c[1] == 's') { s[c[0] - 48]++; } bool flag0 = false; bool flag1 = false; for (int i = 1; i < 8; i++) { if ((m[i] > 0 && m[i + 1] > 0 && m[i + 2]) || (p[i] > 0 && p[i + 1] > 0 && p[i + 2]) || (s[i] > 0 && s[i + 1] > 0 && s[i + 2])) { flag0 = true; } if ((m[i] > 0 && m[i + 2] > 0) || (p[i] > 0 && p[i + 2] > 0) || (s[i] > 0 && s[i + 2] > 0)) { flag1 = true; } } for (int i = 1; i < 9; i++) { if ((m[i] > 0 && m[i + 1] > 0) || (p[i] > 0 && p[i + 1] > 0) || (s[i] > 0 && s[i + 1] > 0)) { flag1 = true; } } for (int i = 1; i < 10; i++) { if (m[i] == 3 || p[i] == 3 || s[i] == 3) flag0 = true; if (m[i] == 2 || p[i] == 2 || s[i] == 2) flag1 = true; } if (flag0) { cout << 0; return 0; } else if (flag1) { cout << 1; return 0; } else { cout << 2; return 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 # sys.stdin = open('input.txt', 'r') # sys.stdout = open('output.txt', 'w') s = input() arr = list(s.split()) a = [0]*10 b = [0]*10 c = [0]*10 for ch in arr: num = int(ch[0]) ch = ch[1] if (ch == 'm'): a[num] += 1 elif (ch == 'p'): b[num] += 1 else: c[num] += 1 # print(*a) # print(*b) # print(*c) # print("_----------------------") ans = 3 for i in range(1,10): ans = min(ans,3-a[i]) if (i+1 < 10): ans = min(ans,3-min(1,a[i])-min(1,a[i+1])) if (i+2<10): ans = min(ans,3-min(1,a[i])-min(1,a[i+1])-min(1,a[i+2])) for i in range(1,10): ans = min(ans,3-b[i]) if (i+1 < 10): ans = min(ans,3-min(1,b[i])-min(1,b[i+1])) if (i+2<10): ans = min(ans,3-min(1,b[i])-min(1,b[i+1])-min(1,b[i+2])) for i in range(1,10): ans = min(ans,3-c[i]) if (i+1 < 10): ans = min(ans,3-min(1,c[i])-min(1,c[i+1])) if (i+2<10): ans = min(ans,3-min(1,c[i])-min(1,c[i+1])-min(1,c[i+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 p(s,n): return str(int(s[0])+n)+s[1] a,b,c=sorted(input().split(),key=lambda x:int(x[0])) if a==b==c or (a==p(b,-1) and c==p(b,1)): print(0) elif a==b or b==c or a==c:print(1) else: if p(a,1) in [b,c] or p(a,2) in [b,c] or p(a,-1) in [b,c] or p(a,-2) in [b,c]: print(1) elif p(b,1) in [a,c] or p(b,2) in [a,c] or p(b,-1) in [a,c] or p(b,-2) in [a,c]: print(1) elif p(c, 1) in [b, a] or p(c, 2) in [b, a] or p(c, -1) in [b, a] or p(c, -2) in [b, a]: 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
s=input().rstrip().split(' ') l=[] q=[] w=[] S=[] D=[] for i in range(0,len(s)): t=list(s[i]) if t[1]=='s': l.append(int(t[0])) elif t[1]=='p': q.append(int(t[0])) else: w.append(int(t[0])) l.sort() q.sort() w.sort() F=[] if len(l)==0: F.append(3) elif len(l)==1: F.append(2) elif len(l)==2: F.append(len(list(set(l)))) if l[0]==l[1] or l[0]==l[1]-1 or l[0]==l[1]-2: F.append(1) else: F.append(2) elif len(l)==3: if len(list(set(l))) == 1: F.append(0) if len(list(set(l))) == 2: F.append(1) if len(list(set(l))) == 3: F.append(2) if l[0]==l[1]-2 or l[1]==l[2]-2 or l[0]==l[2]-2: F.append(1) if len(list(set(l)))==1: F.append(0) if l[0]==l[1]-1 and l[1]==l[2]-1: F.append(0) if l[0]==l[1]-1 and l[1]!=l[2]-1: F.append(1) if l[0]!=l[1]-1 and l[1]==l[2]-1: F.append(1) if l[0]!=l[1]-1 and l[1]!=l[2]-1: F.append(2) l=q; if len(l)==0: F.append(3) elif len(l)==1: F.append(2) elif len(l)==2: F.append(len(list(set(l)))) if l[0]==l[1] or l[0]==l[1]-1 or l[0]==l[1]-2: F.append(1) else: F.append(2) elif len(l)==3: if len(list(set(l))) == 1: F.append(0) if len(list(set(l))) == 2: F.append(1) if len(list(set(l))) == 3: F.append(2) if l[0]==l[1]-2 or l[1]==l[2]-2 or l[0]==l[2]-2: F.append(1) if len(list(set(l)))==1: F.append(0) if l[0]==l[1]-1 and l[1]==l[2]-1: F.append(0) if l[0]==l[1]-1 and l[1]!=l[2]-1: F.append(1) if l[0]!=l[1]-1 and l[1]==l[2]-1: F.append(1) if l[0]!=l[1]-1 and l[1]!=l[2]-1: F.append(2) l=w; if len(l)==0: F.append(3) elif len(l)==1: F.append(2) elif len(l)==2: F.append(len(list(set(l)))) if l[0]==l[1] or l[0]==l[1]-1 or l[0]==l[1]-2: F.append(1) else: F.append(2) elif len(l)==3: if len(list(set(l))) == 1: F.append(0) if len(list(set(l))) == 2: F.append(1) if len(list(set(l))) == 3: F.append(2) if l[0]==l[1]-2 or l[1]==l[2]-2 or l[0]==l[2]-2: F.append(1) if len(list(set(l)))==1: F.append(0) if l[0]==l[1]-1 and l[1]==l[2]-1: F.append(0) if l[0]==l[1]-1 and l[1]!=l[2]-1: F.append(1) if l[0]!=l[1]-1 and l[1]==l[2]-1: F.append(1) if l[0]!=l[1]-1 and l[1]!=l[2]-1: F.append(2) #F.append(len(list(set()))) print(min(F))
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 check(int req, string s1, string s2, string s3) { int new_req = 3; vector<int> list; if (s1[1] == s2[1] && s1[1] == s3[1]) { list.push_back(s1[0] - 48); list.push_back(s2[0] - 48); list.push_back(s3[0] - 48); sort(list.begin(), list.end()); if (abs(list[0] - list[1]) == 1 && abs(list[1] - list[2]) == 1) new_req = 0; else if (abs(list[0] - list[1]) == 1 || abs(list[1] - list[2]) == 1 || abs(list[0] - list[1]) == 2 || abs(list[1] - list[2]) == 2) new_req = 1; else new_req = 2; } else if ((s1[1] == s2[1] && (abs(s1[0] - s2[0]) == 1 || abs(s1[0] - s2[0]) == 2))) new_req = 1; else if ((s3[1] == s2[1] && (abs(s3[0] - s2[0]) == 1 || abs(s3[0] - s2[0]) == 2))) new_req = 1; else if ((s3[1] == s1[1] && (abs(s3[0] - s1[0]) == 1 || abs(s3[0] - s1[0]) == 2))) new_req = 1; else new_req = 2; if (new_req < req) return new_req; else return req; } int main() { int req = 0; string s1, s2, s3; cin >> s1 >> s2 >> s3; if (s1 == s2 && s2 == s3) req = 0; else if (s1 == s2 || s2 == s3 || s1 == s3) req = 1; else { req = 2; } req = check(req, s1, s2, s3); cout << req; 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; void solve(); int main() { ios_base::sync_with_stdio(false); solve(); return 0; } void solve() { string a, b, c; cin >> a >> b >> c; vector<int> arr; arr.push_back(a[0]); arr.push_back(b[0]); arr.push_back(c[0]); if (a[1] == b[1] && a[1] == c[1]) { if (arr[0] == arr[1] && arr[0] == arr[2]) cout << 0 << endl; else if (arr[0] == arr[1] || arr[1] == arr[2] || arr[0] == arr[2]) { cout << 1 << endl; } else { int min = 4; sort(arr.begin(), arr.end()); for (int i = 0; i < 2; ++i) { if ((arr[i + 1] - arr[i]) < min) min = arr[i + 1] - arr[i]; } if (min == 3 || min == 4) cout << 2 << endl; else if (min == 2) cout << 1 << endl; else { if (arr[1] == (arr[0] + 1) && arr[2] == (arr[1] + 1)) cout << 0 << endl; else cout << 1 << endl; } } } else if (a[1] == b[1] || a[1] == c[1] || c[1] == b[1]) { if (a[1] == b[1]) { int temp = abs(a[0] - b[0]); if (temp == 0 || temp == 1 || temp == 2) cout << 1 << endl; else cout << 2 << endl; } else if (a[1] == c[1]) { int temp = abs(a[0] - c[0]); if (temp == 0 || temp == 1 || temp == 2) cout << 1 << endl; else cout << 2 << endl; } else { int temp = abs(b[0] - c[0]); if (temp == 0 || temp == 1 || temp == 2) cout << 1 << endl; else cout << 2 << endl; } } else { 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
a = input().split() d = {} ds = {} for i in a: if d.get(i[1]): d[i[1]].append(int(i[0])) d[i[1]].sort() ds[i[1]] += 1 else: d[i[1]] = [int(i[0])] ds[i[1]] = 1 ds = dict(sorted(ds.items(), key = lambda x:x[1], reverse=True)) for i in ds: if ds[i] == 3: if len(set(d[i])) == 1: print(0) break elif len(set(d[i])) == 2: print(1) break elif d[i][2] == (d[i][1] + 1) and d[i][1] == (d[i][0] + 1): print(0) break elif d[i][1] == (d[i][0] + 1) or d[i][1] == (d[i][0] + 2): print(1) break elif d[i][2] == (d[i][1] + 1) or d[i][2] == (d[i][1] + 2): print(1) break else: print(2) break elif ds[i] == 2: if len(set(d[i])) == 1: print(1) break elif d[i][1] == (d[i][0] + 1) or d[i][1] == (d[i][0] + 2): print(1) break else: print(2) 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
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; public class que2 { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] s = br.readLine().split(" "); Arrays.sort(s); if (s[0].equals(s[1]) && s[1].equals(s[2])) { System.out.println(0); } else if (s[0].charAt(1) == s[1].charAt(1) && s[1].charAt(1) == s[2].charAt(1)) { int val = s[0].charAt(0) - '0'; int val2 = s[1].charAt(0) - '0'; int val3 = s[2].charAt(0) - '0'; if (val + 1 == val2 && val2 + 1 == val3) { System.out.println(0); } else if (val + 1 == val2 || val2 + 1 == val3 || val + 2 == val2 || val2 + 2 == val3||val2 == val||val2==val3||val3==val) { System.out.println(1); } else { System.out.println(2); } } else if (s[0].charAt(1) == s[1].charAt(1)) { int val = s[0].charAt(0) - '0'; int val2 = s[1].charAt(0) - '0'; if (val2 + 1 == val || val + 1 == val2 || val2 + 2 == val || val + 2 == val2||val2 == val) { System.out.println(1); } else { System.out.println(2); } } else if (s[1].charAt(1) == s[2].charAt(1)) { int val = s[1].charAt(0) - '0'; int val2 = s[2].charAt(0) - '0'; if (val2 + 1 == val || val + 1 == val2 || val2 + 2 == val || val + 2 == val2||val2 == val) { System.out.println(1); } else { System.out.println(2); } } else if (s[0].charAt(1) == s[2].charAt(1)) { int val = s[0].charAt(0) - '0'; int val2 = s[2].charAt(0) - '0'; if (val2 + 1 == val || val + 1 == val2 || val2 + 2 == val || val + 2 == val2||val2 == val ) { System.out.println(1); }else{ System.out.println(2); } } else { 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
import java.util.*; import java.io.*; public class coconuts { public static void main (String[] args) throws java.lang.Exception { BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); String s[]=in.readLine().split(" "); Map<String,Integer> hmap=new HashMap<>(); for(int i=0;i<3;i++){ if(hmap.containsKey(s[i])) hmap.put(s[i],hmap.get(s[i])+1); else hmap.put(s[i],1); } int ans=Integer.MAX_VALUE; int temp=1; for(Map.Entry<String,Integer> hash: hmap.entrySet()){ int freq=hash.getValue(); char a=hash.getKey().charAt(0); char b=hash.getKey().charAt(1); int aa=a-'0'; String aa1=Integer.toString(aa+1) + b; String aa2=Integer.toString(aa+2) + b; if(hmap.containsKey(aa1)) temp++; if(hmap.containsKey(aa2)) temp++; ans=Math.min(ans,Math.min(3-freq,3-temp)); temp=1; } System.out.println(ans); } }
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 exit t = input().split()[:3:] s = set(t) res = 3 if len(s)==1: res = min(res,0) elif len(s)==2: res = min(res,1) elif len(s)==3: res = min(res,2) if res==0: print(res) exit(0) t.sort() m = [int(a[0]) for a in t if a[1]=='m'] p = [int(a[0]) for a in t if a[1]=='p'] s = [int(a[0]) for a in t if a[1]=='s'] def f(a): res = 2 for i in a: if (i-1 in a and i+1 in a)or(i-2 in a and i-1 in a)or(i+1 in a and i+2 in a): return 0 elif i-1 in a or i+1 in a or i-2 in a or i+2 in a: res = min(res,1) return res res = min([res,f(m),f(p),f(s)]) 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
l = input().split() s = [] m = [] p = [] for i in range(3): if l[i][1] == 's': s.append(l[i][0]) if l[i][1] == 'm': m.append(l[i][0]) if l[i][1] == 'p': p.append(l[i][0]) r = 2 for s in [s, m, p]: s = list(map(int, s)) s.sort() if len(s) > 1: for i in range(10): if i in s and i + 1 in s and i + 2 in s: r = min(r, 0) if i in s and s.count(i) == 3: r = min(r, 0) for j in range(1, 10): s_ = s.copy() s_.append(j) for i in range(10): if i in s_ and i + 1 in s_ and i + 2 in s_: r = min(r, 1) if i in s_ and s_.count(i) == 3: 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
a=list(input().split()) s=[] m=[] p=[] for i in a: if i[1]=='s': s.append(int(i[0])) elif i[1]=='m': m.append(int(i[0])) else : p.append(int(i[0])) if len(s)==1 and len(m)==1 and len(p)==1: print(2) elif len(s)==2 or len(m)==2 or len(p)==2: if len(s)==2: if abs(s[1]-s[0])<3: print(1) else: print(2) elif len(m)==2: if abs(m[1]-m[0])<3: print(1) else: print(2) else: if abs(p[1]-p[0])<3: print(1) else: print(2) else: if len(s)==3: s.sort() if s[2]-s[0]==0: print(0) elif s[2]-s[1]==1 and s[1]-s[0]==1: print(0) elif s[2]-s[1]<3 or s[1]-s[0]<3: print(1) else: print(2) elif len(m)==3: m.sort() if m[2]-m[0]==0: print(0) elif m[2]-m[1]==1 and m[1]-m[0]==1: print(0) elif m[2]-m[1]<3 or m[1]-m[0]<3: print(1) else: print(2) else: p.sort() if p[2]-p[0]==0: print(0) elif p[2]-p[1]==1 and p[1]-p[0]==1: print(0) elif p[2]-p[1]<3 or p[1]-p[0]<3: 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() if (a==b and b==c): print (0) exit() x = sorted([int(a[0]),int(b[0]),int(c[0])]) if (a[1]==b[1] and b[1]==c[1]) and (x[0]+1==x[1] and x[1]+1==x[2]): print (0) exit() if a==b or b==c or a==c: print (1) exit() d = {"p":[],"m":[],"s":[]} d[a[1]].append(a) d[b[1]].append(b) d[c[1]].append(c) ans = 2 flag = 0 for i in d: if len(d[i])==2: x = sorted([int(d[i][0][0]),int(d[i][1][0])]) if x[1]-x[0]<=2: ans = min(ans,1) elif len(d[i])==3: x = sorted([int(d[i][0][0]),int(d[i][1][0]),int(d[i][2][0])]) if x[1]-x[0]<=2 or x[2]-x[1]<=2: ans = min(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
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.math.BigInteger; import java.util.*; import java.util.concurrent.ThreadLocalRandom; import java.util.stream.Collectors; import java.util.stream.IntStream; public class Main2 { static int mod = 1000000007; static FastScanner scanner; public static void main(String[] args) { scanner = new FastScanner(); String line = scanner.nextLine(); Map<String, Integer> tiles = new HashMap<>(); for (String tile : line.split("\\s+")) { tiles.put(tile, tiles.getOrDefault(tile, 0) + 1); } int toAdd = 3; for (String tile : tiles.keySet()) { toAdd = Math.min(toAdd, Math.max(3 - tiles.get(tile), 0)); int num = tile.charAt(0) - '0'; String s = tile.substring(1); int have = 1 + (tiles.containsKey((num + 1) + s) ? 1 : 0) + (tiles.containsKey((num + 2) + s) ? 1 : 0); toAdd = Math.min(toAdd, 3 - have); have = 1 + (tiles.containsKey((num - 1) + s) ? 1 : 0) + (tiles.containsKey((num + 1) + s) ? 1 : 0); toAdd = Math.min(toAdd, 3 - have); have = 1 + (tiles.containsKey((num - 2) + s) ? 1 : 0) + (tiles.containsKey((num - 1) + s) ? 1 : 0); toAdd = Math.min(toAdd, 3 - have); } System.out.println(toAdd); } //1 1 1 2 3 4 5 5 5 7 static class WithIdx { int val, idx; public WithIdx(int val, int idx) { this.val = val; this.idx = idx; } } public static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String nextToken() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return st.nextToken(); } String nextLine() { try { return br.readLine(); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(); } } int nextInt() { return Integer.parseInt(nextToken()); } long nextLong() { return Long.parseLong(nextToken()); } double nextDouble() { return Double.parseDouble(nextToken()); } int[] nextIntArray(int n) { int[] res = new int[n]; for (int i = 0; i < n; i++) res[i] = nextInt(); return res; } long[] nextLongArray(int n) { long[] res = new long[n]; for (int i = 0; i < n; i++) res[i] = nextLong(); return res; } String[] nextStringArray(int n) { String[] res = new String[n]; for (int i = 0; i < n; i++) res[i] = nextToken(); return res; } } static class PrefixSums { long[] sums; public PrefixSums(long[] sums) { this.sums = sums; } public long sum(int fromInclusive, int toExclusive) { if (fromInclusive > toExclusive) throw new IllegalArgumentException("Wrong value"); return sums[toExclusive] - sums[fromInclusive]; } public static PrefixSums of(int[] ar) { long[] sums = new long[ar.length + 1]; for (int i = 1; i <= ar.length; i++) { sums[i] = sums[i - 1] + ar[i - 1]; } return new PrefixSums(sums); } public static PrefixSums of(long[] ar) { long[] sums = new long[ar.length + 1]; for (int i = 1; i <= ar.length; i++) { sums[i] = sums[i - 1] + ar[i - 1]; } return new PrefixSums(sums); } } static class ADUtils { static void sort(int[] ar) { Random rnd = ThreadLocalRandom.current(); for (int i = ar.length - 1; i > 0; i--) { int index = rnd.nextInt(i + 1); // Simple swap int a = ar[index]; ar[index] = ar[i]; ar[i] = a; } Arrays.sort(ar); } static void reverse(int[] arr) { int last = arr.length / 2; for (int i = 0; i < last; i++) { int tmp = arr[i]; arr[i] = arr[arr.length - 1 - i]; arr[arr.length - 1 - i] = tmp; } } static void sort(long[] ar) { Random rnd = ThreadLocalRandom.current(); for (int i = ar.length - 1; i > 0; i--) { int index = rnd.nextInt(i + 1); // Simple swap long a = ar[index]; ar[index] = ar[i]; ar[i] = a; } Arrays.sort(ar); } } static class MathUtils { static long[] FIRST_PRIMES = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89 , 97 , 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051}; static long[] primes(int to) { long[] all = new long[to + 1]; long[] primes = new long[to + 1]; all[1] = 1; int primesLength = 0; for (int i = 2; i <= to; i ++) { if (all[i] == 0) { primes[primesLength++] = i; all[i] = i; } for (int j = 0; j < primesLength && i * primes[j] <= to && all[i] >= primes[j]; j++) { all[(int) (i * primes[j])] = primes[j]; } } return Arrays.copyOf(primes, primesLength); } static long modpow(long b, long e, long m) { long result = 1; while (e > 0) { if ((e & 1) == 1) { /* multiply in this bit's contribution while using modulus to keep * result small */ result = (result * b) % m; } b = (b * b) % m; e >>= 1; } return result; } static long submod(long x, long y, long m) { return (x - y + m) % m; } } }
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 itertools def cmp(A,B): cnt=0 for i in range(3):cnt+=A[i]!=B[i] return cnt a="123456789" b="mps" x=map(str,input().split()) x=sorted(list(x)) A=[] for i in range(len(a)-2): for j in range(len(b)): B=[a[i]+b[j],a[i+1]+b[j],a[i+2]+b[j]] A.append(B) for i in range(len(a)): for j in range(len(b)): B=[a[i]+b[j],a[i]+b[j],a[i]+b[j]] A.append(B) mn=10 for lst in A: for ls in itertools.permutations(x): mn=min(mn,cmp(lst,ls)) print(mn)
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 main(): a, b, c = input().split() s = set([a, b, c]) if len(s) == 1: print(0) return elif len(s) == 2: curNeed = 1; else: curNeed = 2; lister = [a,b,c] lister.sort(key=lambda x:x[0]); lister.sort(key=lambda x:x[1]); before = '**' counter = 1; jump = 0; for now in lister: if (before[1] == now[1] and int(before[0])+1 == int(now[0])): counter += 1 elif (before[1] == now[1] and int(before[0])+2 == int(now[0])): jump = 1 before = now if counter == 3: print(0) return; if jump == 1: print(1) return; curNeed = min(curNeed, 3-counter); print(curNeed) return 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 sys import stdin s=stdin.readline().strip().split() s1=[] for i in s: s1.append([int(i[0]),i[1]]) aux1=0 for i in range(3): aux=0 for j in range(3): if s[i]==s[j]: aux+=1 aux1=max(aux1,aux) aux2=0 for i in range(3): st=set() for j in range(3): if s[i][1]==s[j][1] and abs(int(s[i][0])-int(s[j][0]))<=2: st.add(int(s[j][0])) arr=list(st) arr.sort() if abs(arr[0]-arr[-1])>2: st.remove(arr[0]) aux2=max(len(st),aux2) print(min(3-aux1,3-aux2))
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 Main { public static void main(String args[]) { long start=System.currentTimeMillis(); FastReader input=new FastReader(); PrintWriter out=new PrintWriter(System.out); int T=1; while(T-->0) { String s1=input.next(); String s2=input.next(); String s3=input.next(); char a=s1.charAt(1); char b=s2.charAt(1); char c=s3.charAt(1); int x=s1.charAt(0); int y=s2.charAt(0); int z=s3.charAt(0); if(a==b && b==c && x==y && y==z) { out.println(0); } else if(a==b && b==c) { int arr[]=new int[3]; arr[0]=x; arr[1]=y; arr[2]=z; Arrays.sort(arr); if(arr[1]==arr[0]+1 && arr[2]==arr[1]+1) { out.println(0); } else { if(arr[0]==arr[1] || arr[1]==arr[2] || arr[0]==arr[2]) { out.println(1); } else { if(arr[0]+1==arr[1] || arr[1]+1==arr[2] || arr[0]+1==arr[2]) { out.println(1); } else if(arr[0]+2==arr[1] || arr[1]+2==arr[2] || arr[0]+2==arr[2]) { out.println(1); } else { out.println(2); } } } } else { if(a==b && b!=c) { if(Math.abs(x-y)<=2) { out.println(1); } else { out.println(2); } } else if(b==c && a!=b) { if(Math.abs(z-y)<=2) { out.println(1); } else { out.println(2); } } else if(a==c && a!=b) { if(Math.abs(x-z)<=2) { out.println(1); } else { out.println(2); } } else { out.println(2); } } } out.close(); } 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
t = input().strip().split() m = 3 for i in range(1, 8): for j in 'mps': r = 3 if str(i) + j in t: r -= 1 if str(i+1) + j in t: r -= 1 if str(i+2) + j in t: r -= 1 m = min(m, r) print(min(m, len(set(t)) - 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
def vsort(a): s=[] m=[] p=[] for i in range(3): k=a[i] if(k[1]=='s'): s.append(k) elif(k[1]=='p'): p.append(k) else: m.append(k) s.sort() m.sort() p.sort() v=[] for i in m: v.append(i) for i in p: v.append(i) for i in s: v.append(i) return v def next(a,b): a1=int(a[0]) b1=int(b[0]) a2=a[1] b2=b[1] if(a1==b1+1 and a2==b2): return 1 elif(a1==b1+2 and a2==b2): return 2 else: return 0 def count(i): ans=2 if(a[i+1]==a[i]): ans=1 if(i+2<len(a) and a[i+2]==a[i]): ans=0 elif(next(a[i+1],a[i])==1): ans-=1 if( i+2<len(a) and next(a[i+2],a[i+1])==1 ): ans-=1 elif(next(a[i+1],a[i])==2): ans-=1 return ans a=[i for i in input().split()] a=vsort(a) min=2 for i in range(2): if(count(i)<min): min=count(i) print(min)
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 input = sys.stdin.readline A=[str(i) for i in input().split()] ans=2 S=[] if A[0]==A[1] and A[1]==A[2]: ans=0 else: for i in range(3): S.append(A[i][1]) if S[0]==S[1] and S[1]==S[2]: N=[] for i in range(3): N.append(int(A[i][0])) N.sort() if N[1]==N[0]+1 and N[2]==N[1]+1: ans=0 if S[0]==S[1]: a0,a1=int(A[0][0]),int(A[1][0]) if abs(a0-a1)<=2: ans=min(1,ans) if S[1]==S[2]: a1,a2=int(A[1][0]),int(A[2][0]) if abs(a1-a2)<=2: ans=min(1,ans) if S[2]==S[0]: a2,a0=int(A[2][0]),int(A[0][0]) if abs(a2-a0)<=2: ans=min(1,ans) 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 = sorted(input().split()) ans = 2 for i in range(3): for j in range(i+1, 3): if a[i] == a[j]: ans = 1 elif a[i][1] == a[j][1] and abs(int(a[i][0])-int(a[j][0])) < 3: ans = 1 if a[0] == a[2]: ans = 0 if a[0][1] == a[1][1] and a[1][1] == a[2][1] and int(a[0][0]) == int(a[1][0]) - 1 and int(a[1][0]) == int(a[2][0])-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; int main() { char s[10], s1[10], s2[10]; scanf("%s", s); scanf("%s", s1); scanf("%s", s2); vector<int> v, v1, v2; for (int i = 0; i < 5; i++) { v.push_back(100); v1.push_back(100); v2.push_back(100); } if (s[1] == 'm') v.push_back((char)s[0] - 48); if (s[1] == 's') v1.push_back((char)s[0] - 48); if (s[1] == 'p') v2.push_back((char)s[0] - 48); if (s1[1] == 'm') v.push_back((char)s1[0] - 48); if (s1[1] == 's') v1.push_back((char)s1[0] - 48); if (s1[1] == 'p') v2.push_back((char)s1[0] - 48); if (s2[1] == 'm') v.push_back((char)s2[0] - 48); if (s2[1] == 's') v1.push_back((char)s2[0] - 48); if (s2[1] == 'p') v2.push_back((char)s2[0] - 48); sort(v.begin(), v.end()); sort(v1.begin(), v1.end()); sort(v2.begin(), v2.end()); int ans = 10000; for (int i = 0; i < v.size(); i++) { if (v[i] == 100) break; if (v[i] == v[i + 1] && v[i + 1] == v[i + 2]) { ans = 0; break; } if (v[i] == v[i + 1] - 1 && v[i] == v[i + 2] - 2) { ans = 0; break; } } for (int i = 0; i < v1.size(); i++) { if (v1[i] == 100) break; if (v1[i] == v1[i + 1] && v1[i + 1] == v1[i + 2]) { ans = 0; break; } if (v1[i] == v1[i + 1] - 1 && v1[i] == v1[i + 2] - 2) { ans = 0; break; } } for (int i = 0; i < v2.size(); i++) { if (v2[i] == 100) break; if (v2[i] == v2[i + 1] && v2[i + 1] == v2[i + 2]) { ans = 0; break; } if (v2[i] == v2[i + 1] - 1 && v2[i] == v2[i + 2] - 2) { ans = 0; break; } } if (!ans) { cout << 0; return 0; } for (int i = 0; i < v.size(); i++) { if (v[i] == 100) break; if (v[i] == v[i + 1] || v[i] == v[i + 1] - 1 || v[i] == v[i + 1] - 2) { cout << 1; return 0; } } for (int i = 0; i < v1.size(); i++) { if (v1[i] == 100) break; if (v1[i] == v1[i + 1] || v1[i] == v1[i + 1] - 1 || v1[i] == v1[i + 1] - 2) { cout << 1; return 0; } } for (int i = 0; i < v2.size(); i++) { if (v2[i] == 100) break; if (v2[i] == v2[i + 1] || v2[i] == v2[i + 1] - 1 || v2[i] == v2[i + 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
s = input().split() s.sort() if s[0] == s[1] == s[2]: print(0) exit(0) s[0] = [int(s[0][0]), s[0][1]] s[1] = [int(s[1][0]), s[1][1]] s[2] = [int(s[2][0]), s[2][1]] if s[0][1] == s[1][1] == s[2][1]: if s[0][0] + 1 == s[1][0] == s[2][0] - 1: print(0) exit(0) def g(x): if x[0][1] == x[1][1]: if abs(x[1][0] - x[0][0]) < 3: return 1 else: return 2 else: return 2 a = min(g([s[0], s[1], s[2]]), g([s[0], s[2], s[1]]), g([s[1], s[0], s[2]]), g([s[1], s[2], s[0]]), g([s[2], s[0], s[1]]), g([s[2], s[1], s[0]])) print(a)
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() ans = 2 for i in range(1,10): for c in "spm": ans = min(ans,max(0,3-a.count(str(i)+c))) ans = min(ans,(not str(i-1)+c in a)+(not str(i)+c in a)+(not str((i+1))+c in a)) 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() res = 2 for i in range(1, 10): for j in "smp": #print(str(i) + j, 3 - (str(i) + j in a) - (str(i+1) + j in a) - (str(i+2) + j in a)) res = min(res, 3 - (str(i) + j in a) - (str(i+1) + j in a) - (str(i+2) + j in a)) res = min(res, 3 - a.count(str(i) + j)) 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
from collections import Counter def Check_2 (letters,num): rep_l = max(set(letters),key = letters.count) ip = [] for i in range (3): if letters[i] in rep_l: ip.append(i) if num[ip[0]] == num[ip[1]]: print(1) elif abs(num[ip[0]] - num[ip[1]]) <=2: print(1) else: print(2) my_String = list(raw_input().split()) my_String.sort() num,letters =[],[] for item in my_String: num.append(int(item[0])) letters.append(item[1]) rep_n = Counter(num) if len(set(my_String)) == 1: print (0) elif len(set(letters)) == 1: if rep_n.most_common(1)[0][1] > 1: print(1) elif num[1]-num[0] == 1 and num[2] - num[1] == 1: print(0) elif num[2] - num[1] <=2 or num[2] - num[0]<=2 or num[1] - num[0]<=2: print(1) else: print(2) elif len(set(letters)) ==2: Check_2(letters,num) 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
cards=list(map(str,input().split(' '))) min_draw=2 dict={'p':[],'m':[],'s':[]} for i in cards: dict[i[1]].append(int(i[0])) for j in dict.keys(): nums=dict[j] if len(nums)==2: if abs(nums[0]-nums[1])<=2 and min_draw>1: min_draw=1 if len(nums)==3: nums.sort() m=len(set(nums))-1 if nums[2]-nums[0]==2 and nums[1]==nums[0]+1: min_draw=0 else: if nums[2]-nums[1]<=2 or nums[1]-nums[0]<=2: min_draw=1 if m >= 0 and min_draw > m: min_draw = m print(min_draw)
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
# your code goes here a,b,c=input().split() d={'m':[],'p':[],'s':[]} d[a[1]].append(int(a[0])) d[b[1]].append(int(b[0])) d[c[1]].append(int(c[0])) l=['m','p','s'] ans=2 for i in l: if d[i]==[]: continue for j in range(1,10): ans=min(ans,3-d[i].count(j)) if ans<0: ans=0 if ans==0: break for j in range(1,8): if j in d[i] and j+1 in d[i] and j+2 in d[i]: ans=0 if ans==0: break if j in d[i] and j+1 in d[i] and j+2 not in d[i]: ans=1 if j in d[i] and j+2 in d[i] and j+1 not in d[i]: ans=1 if j not in d[i] and j+1 in d[i] and j+2 in d[i]: ans=1 if ans==0: break 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
list_str = input().split() list_str.sort() def main(): """ p = ['3p', '5s', '5s'] (after sort) sorted by decimal its mean either ['3p','5p'] or ['5p','5p'] near to koutsu, or whole string koutsu either 1,2,3.... 0 is impossible""" # if koutsu 2 or 3 then cannot be shuntsu if len(set(list_str)) == 1: # all equal print(0) return 0# if koutsu 2 or 3 then cannot be shuntsu elif len(set(list_str)) == 2: # either one equal print(1) return 0# if koutsu 2 or 3 then cannot be shuntsu ############################################### shuntsu_count = 0 """ 1s,5m,3s => after sort 1s,3s,5m 1s,5m,2s => after sort 1s,2s,5m 1s,2m,2s => after sort 1s,2m,2s so i guess better to digits 1,2,2 s,m,s """ num = [] lstr = [] for e in list_str: num.append(int(e[0])) lstr.append(e[1]) # Already sorted so smallest to largest, so need of abs if lstr[0] == lstr[1] and (num[1] - num[0])<=2 and num[0] != num[1]: shuntsu_count += 1 if lstr[0] == lstr[2] and (num[2] - num[0])<=2 and num[0] != num[2]: shuntsu_count += 1 if lstr[1] == lstr[2] and (num[2] - num[1])<=2 and num[1] != num[2]: shuntsu_count += 1 if shuntsu_count >= 3: print(0) elif shuntsu_count == 0: # atleast Count one of kind already print(2) else: print(1) 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
t1, t2, t3 = map(str, input().split()) m = [] s = [] p = [] if t1[1] == 'm': m.append(int(t1[0])) elif t1[1] == 's': s.append(int(t1[0])) else: p.append(int(t1[0])) if t2[1] == 'm': m.append(int(t2[0])) elif t2[1] == 's': s.append(int(t2[0])) else: p.append(int(t2[0])) if t3[1] == 'm': m.append(int(t3[0])) elif t3[1] == 's': s.append(int(t3[0])) else: p.append(int(t3[0])) m.sort() s.sort() p.sort() if len(m) == 0: ans_m = 3 elif len(m) == 1: ans_m = 2 elif len(m) == 2: if m[0] == m[1] or m[1] == m[0] + 1 or m[1] == m[0] + 2: ans_m = 1 else: ans_m = 2 else: if m[0] == m[1] == m[2] or (m[1] == m[0] + 1 and m[2] == m[1] + 1): ans_m = 0 elif m[0] == m[1] or m[1] == m[2] or m[0] == m[2] or m[1] == m[0] + 1 or m[2] == m[1] + 1 or m[1] == m[0] + 2 or m[2] == m[1] + 2: ans_m = 1 else: ans_m = 2 if len(s) == 0: ans_s = 3 elif len(s) == 1: ans_s = 2 elif len(s) == 2: if s[0] == s[1] or s[1] == s[0] + 1 or s[1] == s[0] + 2: ans_s = 1 else: ans_s = 2 else: if s[0] == s[1] == s[2] or (s[1] == s[0] + 1 and s[2] == s[1] + 1): ans_s = 0 elif s[0] == s[1] or s[1] == s[2] or s[0] == s[2] or s[1] == s[0] + 1 or s[2] == s[1] + 1 or s[1] == s[0] + 2 or s[2] == s[1] + 2: ans_s = 1 else: ans_s = 2 if len(p) == 0: ans_p = 3 elif len(p) == 1: ans_p = 2 elif len(p) == 2: if p[0] == p[1] or p[1] == p[0] + 1 or p[1] == p[0] + 2: ans_p = 1 else: ans_p = 2 else: if p[0] == p[1] == p[2] or (p[1] == p[0] + 1 and p[2] == p[1] + 1): ans_p = 0 elif p[0] == p[1] or p[1] == p[2] or p[0] == p[2] or p[1] == p[0] + 1 or p[2] == p[1] + 1 or p[1] == p[0] + 2 or p[2] == p[1] + 2: ans_p = 1 else: ans_p = 2 print(min(ans_m, ans_s, ans_p))
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 = [x for x in input().split()] m = [] p = [] s = [] for x in a: if x[1] == 'm': m.append(int(x[0])) elif x[1] == 'p': p.append(int(x[0])) else: s.append(int(x[0])) maxi = max(len(m), len(p), len(s)) new = [m, p, s] if maxi == 1: print("2") elif maxi == 2: for x in new: if len(x) == maxi: x.sort() if x[0]==x[1] or x[0] + 1 == x[1] or x[0]+2==x[1]: print("1") else: print("2") break else: for x in new: if len(x) == maxi: x.sort() if x[0]==x[1]==x[2] or (x[0]+1==x[1] and x[1]+1==x[2]): print("0") elif x[0]==x[1] or x[1]==x[2]: print("1") elif x[0]+1==x[1] or x[1]+1==x[2]: print("1") elif x[0]+2==x[1] or x[0]+2==x[2] or x[1]+2==x[2]: print("1") else: print("2") 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
#include <bits/stdc++.h> using namespace std; int main() { string s1, s2, s3; cin >> s1 >> s2 >> s3; if (s1 == s2 && s2 == s3) { cout << "0"; return 0; } else if (s1 == s2 || s1 == s3 || s2 == s3) { cout << "1"; return 0; } int a = s1[0] - '0', b = s2[0] - '0', c = s3[0] - '0'; char x = s1[1], y = s2[1], z = s3[1]; if (x == y && x == z) { int k = min(a, min(b, c)); int l = max(a, max(b, c)); if ((a + b + c) * 2 == (min(a, min(b, c)) + max(a, max(b, c))) * 3 && k == l - 2) { cout << "0"; } else if (abs(a - b) == 1) cout << "1"; else if (abs(c - b) == 1) cout << "1"; else if (abs(a - c) == 1) cout << "1"; else if (abs(a - c) == 2 || abs(a - b) == 2 || abs(b - c) == 2) cout << "1"; else cout << "2"; } else if (x == y) { if (abs(a - b) == 1 || abs(a - b) == 2) cout << "1"; else cout << "2"; } else if (x == z) { if (abs(c - a) == 1 || abs(a - c) == 2) cout << "1"; else cout << "2"; } else if (y == z) { if (abs(c - b) == 1 || abs(c - b) == 2) cout << "1"; else cout << "2"; } 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
from collections import Counter from itertools import islice def check_hand(): hand = list(input().rstrip().split()) tiles_count = Counter(hand) needs = 3 - tiles_count.most_common(1)[0][1] if needs == 0: print(0) return by_suit = dict() for tile in hand: if tile[1] in by_suit: by_suit[tile[1]].append(tile[0]) else: by_suit[tile[1]] = [tile[0]] for tiles in by_suit: by_suit[tiles].sort() for tiles in by_suit.values(): if len(tiles) > 1: diffs = [r - l for l,r in zip(map(int, tiles), islice(map(int, tiles), 1, None)) if r - l > 0] if diffs == [1, 1]: print(0) return elif 2 in diffs or 1 in diffs: needs = min(needs, 1) print(needs) check_hand()
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.*; public class B { public static void main(String[] args) { // TODO Auto-generated method stub Scanner stdin = new Scanner(System.in); String[] tiles = new String[3]; char[] suit = new char[3]; int[] nums = new int[3]; for(int i = 0; i < 3; i++){ tiles[i] = stdin.next(); } for(int i =0; i <3; i++){ suit[i] = tiles[i].charAt(1); nums[i] = Character.getNumericValue(tiles[i].charAt(0)); } if(allSuitMatch(suit) && allNumMatch(nums)){ System.out.println(0); return; } if(allSuitMatch(suit) && inOrder(nums)){ System.out.println(0); return; } if(numMatch(suit, nums) == 2){ System.out.println(1); return; } int diff = 3; for(int i = 0; i<3; i++){ for (int j = i + 1; j<3; j++){ if(suit[i] == suit[j]){ diff = Math.min(diff, Math.abs(nums[i] - nums[j])); } } } if(diff <=2){ System.out.println(1); return; } System.out.println(2); } public static int numMatch(char[] suit, int[] nums){ int ret = 0; for(int i = 0; i<3; i++){ for (int j = i + 1; j<3; j++){ if(suit[i] == suit[j] && nums[i] == nums[j]) ret ++; } } return ret; } public static boolean inOrder(int[] nums){ boolean ret = true; int[] temp = new int[3]; for(int i = 0; i<3; i++){ temp[i] = nums[i]; } Arrays.sort(temp); for(int i = 1; i < 3; i++){ if(Math.abs(temp[i] - temp[i-1]) != 1) return false; } return true; } public static boolean allSuitMatch(char[] suit){ boolean ret = false; if(suit[0] == suit[1] && suit[1] == suit[2]){ ret = true; } return ret; } public static boolean allNumMatch(int[] nums){ if(nums[0] == nums[1] && nums[1] == nums[2]){ return true; } return false; } }
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
def func(arr): if(len(arr)==3): if(arr[0]==arr[1] and arr[1]==arr[2]): return 0 elif(arr[1]==arr[0]+1 and arr[2]==arr[0]+2): return 0 elif(arr[0]==arr[1] or arr[1]==arr[2]): return 1 elif(arr[0]==arr[1]-1 or arr[2]==arr[1]+1): return 1 elif(arr[0]==arr[1]-2 or arr[2]==arr[1]+2): return 1 else: return 2 elif(len(arr)==2): if(arr[0]==arr[1]): return 1 elif(arr[0]==arr[1]-1 or arr[0]==arr[1]-2): return 1 else: return 2 elif(len(arr)==1): return 2 else: return 3 arr1=[] arr2=[] arr3=[] arr=list(map(str,input().split())) for i in range(3): if(arr[i][1]=='m'): arr1.append(int(arr[i][0])) elif(arr[i][1]=='p'): arr2.append(int(arr[i][0])) else: arr3.append(int(arr[i][0])) arr1.sort() arr2.sort() arr3.sort() ans=2 if(len(arr1)==1 and len(arr2)==1 and len(arr3)==1): print(2) else: if(len(arr1)>1): ans=min(ans,func(arr1)) elif(len(arr2)>1): ans=min(ans,func(arr2)) elif(len(arr3)>1): ans=min(ans,func(arr3)) 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; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int s = 0, p = 0, m = 0, i, j, k, l; string s1, s2, s3; cin >> s1 >> s2 >> s3; if (s1 > s2) swap(s1, s2); if (s2 > s3) swap(s2, s3); if (s1 > s2) swap(s1, s2); if (s1 == s2 && s2 == s3) { cout << "0"; return 0; } if (s1[0] + 1 == s2[0] && s2[0] + 1 == s3[0] && (s1[1] == s2[1] && s2[1] == s3[1])) { cout << "0"; return 0; } if (s1 == s2 || s2 == s3) { cout << "1"; return 0; } if (s1[1] == s2[1] && (s1[0] + 1 == s2[0] || s1[0] + 2 == s2[0])) { cout << "1"; return 0; } if (s2[1] == s3[1] && (s2[0] + 1 == s3[0] || s2[0] + 2 == s3[0])) { cout << "1"; return 0; } if (s1[1] == s3[1] && (s1[0] + 1 == s3[0] || s1[0] + 2 == s3[0])) { 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
#include <bits/stdc++.h> using namespace std; void ECHO(string _s) { cout << endl; (void)_s; } template <typename T, typename... Args> void ECHO(string _s, T x, Args... args) { unsigned _i; string _s2 = ""; for (_i = 0; _i < _s.length(); ++_i) { if (_s[_i] == ',') break; if (_s[_i] != ' ') _s2 += _s[_i]; } if (_i == _s.length()) { --_i; } cout << " (" << _s2 << "):" << x; ECHO(_s.substr(_i + 1, _s.length() - _i - 1), args...); } template <typename T0, typename T1> inline ostream& operator<<(ostream& os, pair<T0, T1>& p) { return os << "(" << p.first << ", " << p.second << ")"; } template <typename T> inline ostream& operator<<(ostream& os, vector<T>& v) { for (unsigned i = 0; i < v.size(); ++i) { cout << v[i] << "_"; } cout << endl; return os; } template <typename T> inline T _min(T x1, T x2, T x3) { return min(x1, min(x2, x3)); } template <typename T> inline T _min(T x1, T x2, T x3, T x4) { return min(min(x1, x2), min(x2, x3)); } inline int _gcd(int a, int b) { while (b) b %= a ^= b ^= a ^= b; return a; } int main() { ios::sync_with_stdio(false); string s[3]; cin >> s[0] >> s[1] >> s[2]; int aux, aux2; if (s[0] == s[1] && s[1] == s[2]) aux = 0; else if (s[0] == s[1] || s[1] == s[2] || s[2] == s[0]) aux = 1; else aux = 2; sort(s, s + 3); if ((s[1][0] - s[0][0] == 1) && (s[2][0] - s[1][0] == 1) && s[0][1] == s[1][1] && s[2][1] == s[1][1]) aux2 = 0; else if ((s[1][1] == s[0][1] && s[1][0] - s[0][0] <= 2) || (s[1][1] == s[2][1] && s[2][0] - s[1][0] <= 2) || (s[0][1] == s[2][1] && s[2][0] - s[0][0] <= 2)) aux2 = 1; else aux2 = 2; cout << min(aux, aux2); 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
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
#include <bits/stdc++.h> using namespace std; int main() { vector<int> v1, v2, v3; string s; string a[3]; for (int i = 0; i < 3; i++) { cin >> s; a[i] = s; if (s[1] == 's') { v1.push_back(int(s[0]) - 48); } if (s[1] == 'p') { v2.push_back(int(s[0]) - 48); } if (s[1] == 'm') { v3.push_back(int(s[0]) - 48); } } int eqcount = 1; for (int i = 0; i < 2; i++) { if (a[i] == a[i + 1]) { eqcount++; } } if (eqcount == 3) { cout << "0"; exit(0); } if ((a[0] == a[1]) || a[1] == a[2] || a[2] == a[0]) { eqcount = 2; cout << "1"; exit(0); } if (eqcount == 1) { int eqcount2 = 0; if (v1.size() > 1) { sort(v1.begin(), v1.end()); for (int i = 0; i < v1.size() - 1; i++) { if (v1[i + 1] - v1[i] == 1) { eqcount2++; } else if (v1[i + 1] - v1[i] == 2) { cout << "1"; exit(0); } } cout << 2 - eqcount2; exit(0); } if (v2.size() > 1) { sort(v2.begin(), v2.end()); for (int i = 0; i < v2.size() - 1; i++) { if (v2[i + 1] - v2[i] == 1) { eqcount2++; } else if (v2[i + 1] - v2[i] == 2) { cout << "1"; exit(0); } } cout << 2 - eqcount2; exit(0); } if (v3.size() > 1) { sort(v3.begin(), v3.end()); for (int i = 0; i < v3.size() - 1; i++) { if (v3[i + 1] - v3[i] == 1) { eqcount2++; } else if (v3[i + 1] - v3[i] == 2) { cout << "1"; exit(0); } } cout << 2 - eqcount2; exit(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
a = sorted(list(map(lambda x: ord(x[0]) + 256 * ord(x[1]), input().split()))) res = 2 if a[1] - a[0] in [0, 1, 2] or a[2] - a[1] in [0, 1, 2]: res = 1 if (a[0] == a[1] and a[1] == a[2]) or (a[0] + 1 == a[1] and a[1] + 1 == a[2]): res = 0 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
#include <bits/stdc++.h> using namespace std; vector<int> v[5]; int a, b, c, flag[5], flag1[5], flag2[5], mx; char x, y, z; int main() { for (int i = 0; i < 3; i++) { scanf("%d%c%c", &a, &x, &y); if (x == 'm') { v[0].push_back(a); } if (x == 'p') { v[1].push_back(a); } if (x == 's') { v[2].push_back(a); } } sort(v[0].begin(), v[0].end()); sort(v[1].begin(), v[1].end()); sort(v[2].begin(), v[2].end()); for (int i = 0; i < 3; i++) { flag[i] = 1; flag1[i] = 1; flag2[i] = 1; for (int j = 1; j < v[i].size(); j++) { if ((v[i][j - 1] + 1) == v[i][j]) { flag1[i]++; } if ((v[i][j - 1]) == v[i][j]) { flag2[i]++; } if ((v[i][j - 1] + 2) == v[i][j]) { flag[i] = 2; } } } int f = 1, f1 = 1, f2 = 1; for (int i = 0; i < 3; i++) { f = max(f, flag[i]); f1 = max(f1, flag1[i]); f2 = max(f2, flag2[i]); } mx = max(f1, f2); mx = max(mx, f); if (mx > 3) mx = 3; printf("%d\n", 3 - mx); }
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 diff(a,b): a=int(a) b=int(b) if a>b: return(a-b) else: return(b-a) x,y,z=input().split() if x==y and y==z: p=0 elif x==y or y==z or x==z: p=1 else: l=[x[1]] if y[1] not in l: l.append(y[1]) if z[1] not in l: l.append(z[1]) if len(l)==3: p=2 elif len(l)==2: if x[1]==y[1]: t=(x,y) elif x[1]==z[1]: t=(x,z) else: t=(y,z) if diff(t[0][0],t[1][0])==1: p=1 elif diff(t[0][0],t[1][0])==2: p=1 else: p=2 else: q=0 if diff(x[0],y[0])==1: q+=1 if diff(y[0],z[0])==1: q+=1 if diff(x[0],z[0])==1: q+=1 if q==2: p=0 elif q==1: p=1 elif diff(x[0],y[0])==2 or diff(x[0],z[0])==2 or diff(y[0],z[0])==2: p=1 else: p=2 print(p)
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.lang.*; import java.util.*; import java.io.*; public class Main { void solve() { char s[][]=new char[3][]; for(int i=0;i<3;i++) s[i]=ns().toCharArray(); int ans=3; HashSet<String> hs=new HashSet<>(); for(int i=0;i<3;i++) hs.add(new String(s[i])); if(hs.size()==1) ans=0; else if(hs.size()==2) ans=1; else if(hs.size()==3) ans=2; ans=Math.min(ans,get(s,'s')); ans=Math.min(ans,get(s,'p')); ans=Math.min(ans,get(s,'m')); pw.println(ans); } int get(char s[][],char ch){ int a[]=new int[10]; for(int i=0;i<3;i++){ if(s[i][1]==ch) a[s[i][0]-'0']=1; } int ans=3; for(int i=1;i<=7;i++) ans=Math.min(ans,3-(a[i]+a[i+1]+a[i+2])); return ans; } long M = (long)1e9+7; // END PrintWriter pw; StringTokenizer st; BufferedReader br; void run() throws Exception { br = new BufferedReader(new InputStreamReader(System.in)); pw = new PrintWriter(System.out); long s = System.currentTimeMillis(); solve(); pw.flush(); } public static void main(String[] args) throws Exception { new Main().run(); } String ns() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } String nextLine() throws Exception { String str = ""; try { str = br.readLine(); } catch (IOException e) { throw new Exception(e.toString()); } return str; } int ni() { return Integer.parseInt(ns()); } long nl() { return Long.parseLong(ns()); } double nd() { return Double.parseDouble(ns()); } }
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> #pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") using namespace std; 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); } struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); inline int64_t random_long(long long l = LLONG_MIN, long long r = LLONG_MAX) { uniform_int_distribution<int64_t> generator(l, r); return generator(rng); } void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr << '\'' << x << '\''; } void __print(const char *x) { cerr << '\"' << x << '\"'; } void __print(const string &x) { cerr << '\"' << x << '\"'; } void __print(bool x) { cerr << (x ? "true" : "false"); } template <typename T, typename V> void __print(const pair<T, V> &x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; } template <typename T> void __print(const T &x) { int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; } void _print() { cerr << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); } const long long inf = 1e18; const int32_t M = 1e9 + 7; const int32_t MM = 998244353; bool isPowerOfTwo(long long x) { return x && (!(x & (x - 1))); } long long binpow(long long a, long long b, long long m) { a %= m; long long res = 1; while (b > 0) { if (b & 1) res = res * a % m; a = a * a % m; b >>= 1; } return res; } const int N = 2e6 + 1; void solve() { string s, t, v; cin >> s >> t >> v; vector<int> ve; ve.push_back(s[0] - '0'); ve.push_back(t[0] - '0'); ve.push_back(v[0] - '0'); ; sort((ve).begin(), (ve).end()); if ((s == t && t == v) || (s[1] == t[1] && t[1] == v[1] && ve[1] == ve[0] + 1 && ve[2] == ve[1] + 1)) { cout << 0 << "\n"; return; } if ((s == t) || (t == v) || (v == s)) { cout << 1 << "\n"; return; } if (s[1] == t[1] && (abs(s[0] - t[0]) == 1 || abs(s[0] - t[0]) == 2)) { cout << 1 << "\n"; return; } if (t[1] == v[1] && (abs(v[0] - t[0]) == 1 || abs(v[0] - t[0]) == 2)) { cout << 1 << "\n"; return; } if (s[1] == v[1] && (abs(s[0] - v[0]) == 1 || abs(s[0] - v[0]) == 2)) { cout << 1 << "\n"; return; } cout << 2 << "\n"; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long t = 1; while (t--) { solve(); } cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\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.util.Scanner; public class Q2 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner read = new Scanner(System.in); int[][] st = new int[2][3]; String a = read.next(); String b = read.next(); String c = read.next(); int common = 0; if(a.equals(b)) { if(b.equals(c)) { common++; } common++; } else if(a.equals(c)) { if(a.equals(b)) { common++; } common++; } else if(b.equals(c)) { if(a.equals(c)) { common++; } common++; } int conc = 0; int flag = 0; if(a.charAt(1)==b.charAt(1)) { int v1 = Integer.valueOf(a.substring(0, 1)); int v2 = Integer.valueOf(b.substring(0, 1)); int v3 = Integer.valueOf(c.substring(0, 1)); if(v1>v2) { if((v1-v2<3 ) && v2!=v1) { conc++; } else { flag=1; } } else { if((v2-v1<3 ) && v2!=v1) { conc++; } else { flag=1; } } } else { flag=1; } if(c.charAt(1)==b.charAt(1)) { int v1 = Integer.valueOf(a.substring(0, 1)); int v2 = Integer.valueOf(b.substring(0, 1)); int v3 = Integer.valueOf(c.substring(0, 1)); if(v3>v2) { if((v3-v2<3 ) && v2!=v3) { conc++; } else { flag=1; } } else { if((v2-v3<3 ) && v2!=v3) { conc++; } else { flag=1; } } } else { flag=1; } if(c.charAt(1)==a.charAt(1)) { int v1 = Integer.valueOf(a.substring(0, 1)); int v2 = Integer.valueOf(b.substring(0, 1)); int v3 = Integer.valueOf(c.substring(0, 1)); if(v3>v1) { if((v3-v1<3 ) && v1!=v3) { conc++; } else { flag=1; } } else { if((v1-v3<3 ) && v1!=v3) { conc++; } else { flag=1; } } } else { flag=1; } if(common>conc) { System.out.println(2-common); } else { if(conc>0 && flag==0) { System.out.println(3-conc); } else { if(flag==1 && conc>0) { System.out.println(1); } else { 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
#include <bits/stdc++.h> using namespace std; int main() { string str; int m, s, p; m = s = p = 0; vector<pair<char, int>> hai; for (int i = 0; i < 3; i++) { cin >> str; hai.push_back(make_pair(str[1], str[0] - '0')); if (str[1] == 'm') m++; else if (str[1] == 's') s++; else p++; } sort(hai.begin(), hai.end()); if (hai[0] == hai[1] && hai[1] == hai[2]) cout << 0 << endl; else if (hai[0] == hai[1] || hai[1] == hai[2] || hai[2] == hai[0]) cout << 1 << endl; else { if (m == 3 || p == 3 || s == 3) { if (hai[2].second - hai[0].second == 2) cout << 0 << endl; else if (hai[1].second - hai[0].second <= 2 || hai[2].second - hai[1].second <= 2) cout << 1 << endl; else cout << 2 << endl; } else if (m == 2) { if (hai[1].second - hai[0].second <= 2) cout << 1 << endl; else cout << 2 << endl; } else if (m == 1 && p == 2) { if (hai[2].second - hai[1].second <= 2) cout << 1 << endl; else cout << 2 << endl; } else if (p == 2 && s == 1) { if (hai[1].second - hai[0].second <= 2) cout << 1 << endl; else cout << 2 << endl; } else if (s == 2) { if (hai[2].second - hai[1].second <= 2) cout << 1 << endl; else cout << 2 << 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
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 9; int t, id, n, m, x, y, k, c, p, dif, ans, pre, rem, cur, tmp, tot, r, l, u, d, xx, yy; vector<int> v, adj[N]; bool fl, ok; long long res, sum; char ch; string s, z; map<string, int> ide; map<char, set<int>> sui; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ; for (int i = 0; i < (int)3; ++i) { cin >> s; ++ide[s]; sui[s[1]].insert(s[0] - '0'); } x = y = 0x3f3f3f3f; for (auto it : ide) { x = min(x, 3 - it.second); } for (auto it : sui) { set<int> v = it.second; if (v.size() == 1) y = min(y, 2); else if (v.size() == 2) { if (abs(*v.begin() - *v.rbegin()) <= 2) y = min(y, 1); } else if (v.size() == 3) { int arr[3]; auto it = v.begin(); for (int i = 0; i < (int)3; ++i) { arr[i] = *it; ++it; } if (abs(arr[0] - arr[2]) == 2) y = min(y, 0); if (abs(arr[0] - arr[1]) <= 2 || abs(arr[1] - arr[2]) <= 2) y = min(y, 1); } } printf("%d\n", min(x, y)); 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
def cm(a,b,c): if a[1]==b[1]==c[1]: if a[0]==b[0]==c[0]: return True m=[int(a[0]),int(b[0]),int(c[0])] m.sort() if (m[2]-m[1])==1 and (m[1]-m[0])==1: return True return False a,b,c=input().split() ans=False if cm(a,b,c): print(0) ans=True elif not(ans): p=[] for i in range(10): for j in ['m','p','s']: p.append(str(i)+j) for i in p: if cm(i,b,c): ans=True break if cm(i,a,b): ans=True break if cm(i,a,c): ans=True if ans: print(1) if not(ans): 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() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); map<char, vector<int>> check; check['m'] = vector<int>(10); check['p'] = vector<int>(10); check['s'] = vector<int>(10); for (int i = 0; i < 3; i++) { string cur; cin >> cur; check[cur[1]][cur[0] - '0']++; } vector<char> chars = {'m', 'p', 's'}; for (int i = 0; i < 3; i++) { char c = chars[i]; for (int j = 1; j < 10; j++) { bool flag = false; if (check[c][j] > 2) flag = true; if (j <= 7 && check[c][j] > 0 && check[c][j + 1] > 0 && check[c][j + 2] > 0) flag = true; if (flag) { cout << 0 << endl; return 0; } } } for (int i = 0; i < 3; i++) { char c = chars[i]; for (int j = 1; j < 10; j++) { bool flag = false; if (check[c][j] > 1) flag = true; if (j <= 8 && check[c][j] > 0 && check[c][j + 1] > 0) flag = true; if (j <= 7 && check[c][j] > 0 && check[c][j + 2] > 0) flag = true; if (flag) { 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
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; char x, y, z; cin >> a >> x >> b >> y >> c >> z; if (x != y && x != z && y != z) { cout << 2 << endl; } else if (x == y && y != z) { if (abs(a - b) == 1 || abs(a - b) == 2) cout << 1 << endl; else if (a == b) cout << 1 << endl; else cout << 2 << endl; } else if (x == z && z != y) { if (abs(a - c) == 1 || abs(a - c) == 2) cout << 1 << endl; else if (a == c) cout << 1 << endl; else cout << 2 << endl; } else if (z == y && x != z) { if (abs(c - b) == 1 || abs(c - b) == 2) cout << 1 << endl; else if (c == b) cout << 1 << endl; else cout << 2 << endl; } else { int temp; if (a > b) { temp = a; a = b; b = temp; } if (a > c) { temp = a; a = c; c = temp; } if (b > c) { temp = b; b = c; c = temp; } if ((a + c == 2 * b && b - a == 1) || (a == b && b == c)) cout << "0" << endl; else if (abs(b - a) == 2 || abs(b - c) == 2 || abs(b - a) == 1 || abs(b - c) == 1) cout << 1 << endl; else if (a == b || b == c) cout << 1 << endl; else 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
import java.util.*; public class E1191B { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int [] m = new int[10]; // whether m[i] is present int [] p = new int[10]; int [] s = new int[10]; int min = 2; for (int i= 0; i< 3 ; i++) { String s1 = sc.next(); char [] c1 = s1.toCharArray(); if (c1[1] == 'm') m[c1[0] - '1' +1 ]++; else { if (c1[1] == 'p') p[c1[0] - '1' +1 ]++; else s[c1[0] - '1' +1 ]++; } } for (int i= 1; i< 10; i++) { min = Math.min(min, 3 - m[i]); min = Math.min(min, 3 - p[i]); min = Math.min(min, 3 - s[i]); } for (int i= 1; i<= 7; i++) { // Wrong answer on test 48 int m_t = 0; int p_t = 0; int s_t = 0; for (int j=i; j< i+3; j++) { if (m[j] >0) m_t ++; if (p[j] >0) p_t ++; if (s[j] >0) s_t ++; } min = Math.min(min, 3 - m_t); min = Math.min(min, 3 - p_t); min = Math.min(min, 3 - s_t); } 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
s = input().split() s.sort() if s[0] == s[2] or (s[0] == s[1] and s[0] == s[2]): print(0) exit() d = [int(i[0]) for i in s] c = [ord(i[1]) for i in s] if d[1] == d[0]+1 and d[2] == d[0]+2 and c[0] == c[1] and c[0] == c[2]: print(0) exit() dem = {i for i in s} ans = len(dem) - 1 for i in range(3): for j in range(3): if i == j: continue if (abs(d[i] - d[j]) == 1 or abs(d[i] - d[j]) == 2) and c[i] == c[j]: ans = 1 break 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, b, c = sorted(input().split(), key = lambda x: int(x[0])) if a == b == c: print(0) elif a[1] == b[1] == c[1] and int(a[0])+2 == int(b[0])+1 == int(c[0]): print(0) elif a == b or b == c or c == a: print(1) elif a[1] == b[1] and (int(a[0])+1 == int(b[0]) or int(a[0])+2 == int(b[0])): print(1) elif b[1] == c[1] and (int(b[0])+1 == int(c[0]) or int(b[0])+2 == int(c[0])): print(1) elif a[1] == c[1] and (int(a[0])+1 == int(c[0]) or int(a[0])+2 == int(c[0])): 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
tiles = input().split() m = [] p = [] s = [] for tile in tiles: if tile[-1] == 'm': m.append(int(tile[:-1])) elif tile[-1] == 'p': p.append(int(tile[:-1])) elif tile[-1] == 's': s.append(int(tile[:-1])) def get_minimum_extra_tiles(_list): if not _list: return 3 _list = sorted(_list) max_sequential = 1 sequential = 1 max_equal = 1 equal = 1 prev = _list[0] for item in _list[1:]: if item == prev: equal += 1 if equal == 3: return 0 elif item == prev + 1: sequential += 1 if sequential == 3: return 0 if max_equal < equal: max_equal = equal equal = 1 prev = item elif item == prev + 2: if max_sequential < 2: max_sequential = 2 sequential = 1 if max_equal < equal: max_equal = equal equal = 1 prev = item else: if max_sequential < sequential: max_sequential = sequential sequential = 1 if max_equal < equal: max_equal = equal equal = 1 prev = item if max_sequential < sequential: max_sequential = sequential if max_equal < equal: max_equal = equal return max(0, 3 - max(max_equal, max_sequential)) m_min_extra_tiles = get_minimum_extra_tiles(m) p_min_extra_tiles = get_minimum_extra_tiles(p) s_min_extra_tiles = get_minimum_extra_tiles(s) print(min(m_min_extra_tiles, p_min_extra_tiles, s_min_extra_tiles))
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 = int(input()) # m, n = map(int, input().split()) # nums = list(map(int, input().split())) import functools class node(object): def __init__(self): self.num=0 self.c='0' p=node() s=[node() for i in range(3)] def cmp_new(a,b): if a.num == b.num: return ord(a.c) - ord(b.c) return ord(a.num) - ord(b.num) s1,s2,s3=map(list,input().split()) s[0].num = chr(ord(s1[0]) - ord('0')) s[1].num = chr(ord(s2[0]) - ord('0')) s[2].num = chr(ord(s3[0]) - ord('0')) s[0].c = s1[1] s[1].c = s2[1] s[2].c = s3[1] s.sort(key=functools.cmp_to_key(cmp_new)) ans = 2 if (ord(s[0].num)== ord(s[2].num) - 2 and ord(s[1].num) == ord(s[2].num) - 1 and (s[0].c == s[1].c and s[1].c == s[2].c)): ans = 0 elif(s[0].num == s[2].num and s[1].num == s[2].num and (s[0].c == s[1].c and s[1].c == s[2].c)): ans = 0 elif(ord(s[1].num) - ord(s[0].num) == 1 and s[1].c == s[0].c): ans = 1 elif (s[1].num == s[0].num and s[1].c == s[0].c): ans = 1 elif (ord(s[2].num) - ord(s[1].num) == 1 and s[2].c == s[1].c): ans = 1 elif (s[2].num == s[1].num and s[2].c == s[1].c): ans = 1 elif (ord(s[2].num) - ord(s[0].num) == 2 and s[2].c == s[0].c): ans = 1 elif (ord(s[1].num) - ord(s[0].num) == 2 and s[1].c == s[0].c): ans = 1 elif (ord(s[2].num) - ord(s[1].num) == 2 and s[2].c == s[1].c): ans = 1 elif (ord(s[2].num) - ord(s[0].num) == 1 and s[2].c == s[0].c): 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
a, b, c = input().split() t = sorted([(int(a[0]), a[1]), (int(b[0]), b[1]), (int(c[0]), c[1])]) if t[0] == t[1] and t[1] == t[2]: print(0) exit(0) if t[0][1] == t[1][1] and t[1][1] == t[2][1] and t[0][0]+1 == t[1][0] and t[1][0]+1 == t[2][0]: print(0) exit(0) if t[0] == t[1]: print(1) exit(0) if t[1] == t[2]: print(1) exit(0) if t[0] == t[2]: print(1) exit(0) if t[0][1] == t[1][1] and t[0][0]+1 == t[1][0]: print(1) exit(0) if t[1][1] == t[2][1] and t[1][0]+1 == t[2][0]: print(1) exit(0) if t[0][1] == t[2][1] and t[0][0]+1 == t[2][0]: print(1) exit(0) if t[0][1] == t[1][1] and t[0][0]+2 == t[1][0]: print(1) exit(0) if t[1][1] == t[2][1] and t[1][0]+2 == t[2][0]: print(1) exit(0) if t[0][1] == t[2][1] and t[0][0]+2 == t[2][0]: 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
a = [x for x in input().split()] a.sort() if a[0] == a[1] == a[2]: print(0) elif a[0] == a[1] or a[1] == a[2] or a[0] == a[2]: print(1) else: if a[0][1] == a[1][1] == a[2][1] and (abs(int(a[0][0]) - int(a[1][0])) == abs(int(a[1][0]) - int(a[2][0])) == 1): print(0) elif ((abs(int(a[1][0]) - int(a[0][0])) == 1 or abs(int(a[1][0]) - int(a[0][0])) == 2) and a[1][1] == a[0][1]) or ((int(a[2][0]) - int(a[1][0]) == 1 or int(a[2][0]) - int(a[1][0]) == 2) and a[2][1] == a[1][1]) or ((abs(int(a[2][0]) - int(a[0][0])) == 1 or abs(int(a[2][0]) - int(a[0][0])) == 2) and a[2][1] == a[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
input = input().split() if input.count(input[0]) == 3: print(0) elif input.count(input[0]) == 2: print(1) elif input.count(input[1]) == 2: print(1) elif input.count(input[2]) == 2: print(1) else: num_0 = [int(i) for i in input[0] if i in '123456789'] num_1 = [int(i) for i in input[1] if i in '123456789'] num_2 = [int(i) for i in input[2] if i in '123456789'] char_0 = [i for i in input[0] if i not in '123456789'] char_1 = [i for i in input[1] if i not in '123456789'] char_2 = [i for i in input[2] if i not in '123456789'] num=[] num.extend(num_0) num.extend(num_1) num.extend(num_2) num.sort() if char_0 == char_2 and char_2 == char_1 and (num[0] + 1) == num[1] and (num[1] + 1) == num[2]: print(0) elif abs(num_0[0] - num_1[0]) < 3 and char_0 == char_1: print(1) elif abs(num_1[0] - num_2[0]) < 3 and char_1 == char_2: print(1) elif abs(num_2[0] - num_0[0]) < 3 and char_2 == char_0: 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
s = list(input().split()) s.sort() if s[0] == s[2]: print(0) exit() elif int(s[0][0])+2 == int(s[1][0])+1 == int(s[2][0]) and s[0][1] == s[1][1] == s[2][1]: print(0) exit() elif s[0][1] == s[1][1] and int(s[1][0]) - int(s[0][0]) <= 2: print(1) elif s[1][1] == s[2][1] and int(s[2][0]) - int(s[1][0]) <= 2: print(1) elif s[2][1] == s[0][1] and int(s[2][0]) - int(s[0][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
import sys import math import bisect from collections import deque sys.setrecursionlimit(1000000000) def input(): return sys.stdin.readline().strip() def iinput(): return int(input()) def finput(): return float(input()) def tinput(): return input().split() def rinput(): return map(str, tinput()) def rlinput(): return list(rinput()) def modst(a, s): res = 1 while s: if s % 2: res *= a a *= a s //= 2 return res def main(): s = rlinput() res = 10 ** 18 for i in map(str, range(1, 10)): for p in ('m', 'p', 's'): k = s.count(i + p) res = min(res, 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 res = min(res, 3 - k) print(res) for i in range(1): 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
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]<=2: ans=min(1,ans) elif 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
input_data = str(input()).split(" ") local_dict = {"m": 0, "s": 1, "p": 2} def koutsu_distance(data): top_same = 1 for i, tile in enumerate(data[0:2]): local_same = 1 for next_tile in data[i+1:]: if next_tile == tile: local_same += 1 if local_same > top_same: top_same = local_same return 3 - top_same def shuntsu_distance(data): num_data = list(map(lambda x: int(x[0]) + 20 * local_dict[x[1]], data)) max_diff = 0 min_diff = 99 for i, num in enumerate(num_data[:2]): for next_num in num_data[i+1:]: diff = abs(num - next_num) if diff > max_diff: max_diff = diff if diff < min_diff: min_diff = diff if min_diff == 1 and max_diff == 2: return 0 if min_diff <= 2: return 1 return 2 koutsu = koutsu_distance(input_data) shuntsu = shuntsu_distance(input_data) print(min(koutsu, shuntsu))
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() y = sorted([a[0], b[0], c[0]]) y1 = [int(y[i + 1]) - int(y[i]) for i in range(2)] y2 = sorted([a[1], b[1], c[1]]) if len(set(y2)) == 1: if set(y1) == {0}: print(0) elif set(y1) == {1}: print(0) elif 0 in set(y1) or 1 in set(y1) or 2 in set(y1): print(1) else: print(2) elif len(set(y2)) == 2: x = sorted([a, b, c], key=lambda m: m[1]) if x[0][1] == x[1][1]: if int(x[0][0])-int(x[1][0]) == 0 or abs(int(x[1][0])-int(x[0][0])) == 1 or abs(int(x[1][0])-int(x[0][0])) == 2: print(1) else: print(2) elif x[1][1] == x[2][1]: if int(x[1][0])-int(x[2][0]) == 0 or abs(int(x[2][0])-int(x[1][0])) == 1 or abs(int(x[2][0])-int(x[1][0])) == 2: print(1) else: print(2) 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
s1,s2,s3 = input().split() A = [] if (s1[1]==s2[1])and(s2[1]==s3[1]): if (s1[0]==s2[0])and(s2[0]==s3[0]): print(0) exit() A.append(int(s1[0])) A.append(int(s2[0])) A.append(int(s3[0])) A.sort() if (A[0]==A[1]-1) and(A[0]==A[2]-2): print(0) exit() if (s1[1]==s2[1]): if (s1[0]==s2[0]): print(1) exit() if (int(s1[0])==(int(s2[0])+1))or(int(s1[0])==(int(s2[0])-1)): print(1) exit() if (int(s1[0])==(int(s2[0])+2))or(int(s1[0])==(int(s2[0])-2)): print(1) exit() if (s1[1] == s3[1]): if (s1[0]==s3[0]): print(1) exit() if (int(s1[0])==(int(s3[0])+1))or(int(s1[0])==(int(s3[0])-1)): print(1) exit() if (int(s1[0])==(int(s3[0])+2))or(int(s1[0])==(int(s3[0])-2)): print(1) exit() if (s2[1]==s3[1]): if (s2[0]==s3[0]): print(1) exit() if (int(s2[0])==(int(s3[0])+1))or(int(s2[0])==(int(s3[0])-1)): print(1) exit() if (int(s2[0])==(int(s3[0])+2))or(int(s2[0])==(int(s3[0])-2)): print(1) 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
#include <bits/stdc++.h> using namespace std; int main(void) { vector<string> s(3); cin >> s[0] >> s[1] >> s[2]; reverse(s[0].begin(), s[0].end()); reverse(s[1].begin(), s[1].end()); reverse(s[2].begin(), s[2].end()); sort(s.begin(), s.end()); if (s[0] == s[1] && s[1] == s[2]) { cout << 0 << endl; } else if (s[0] == s[1] || s[1] == s[2]) { cout << 1 << endl; } else if (s[0][0] == s[1][0] && s[2][0] == s[1][0] && (int)(s[2][1]) - (int)(s[0][1]) == 2) { cout << 0 << endl; } else if (s[0][0] == s[1][0] && (int)(s[1][1]) - (int)(s[0][1]) <= 2) { cout << 1 << endl; } else if (s[1][0] == s[2][0] && (int)(s[2][1]) - (int)(s[1][1]) <= 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 java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class Majiang { public static void main(String[] args) { var scanner = new Scanner(System.in); var tiles = scanner.nextLine().split(" "); // System.out.println(Arrays.toString(tiles)); // if (tiles[0].equals(tiles[1]) || tiles[0].equals[tiles[2] || // tiles[1].equals(tiles[2])]) { // System.out.println(1); // } // System.out.println(code(tiles[0])); int[] codes = { 0, 0, 0 }; for (int i = 0; i < 3; i++) { codes[i] = code(tiles[i]); } Arrays.sort(codes); // System.out.println(Arrays.toString(codes)); if (codes[0] == codes[1] && codes[0] == codes[2]) { // ็‰นๅˆค koutsu answer(0); } else if (codes[0] == codes[1] || codes[0] == codes[2] || codes[1] == codes[2]) { // ไธคไธช็‰Œไธ€ๆ ท answer(1); } else if (codes[0] + 1 == codes[1] && codes[1] + 1 == codes[2]) { // ็‰นๅˆค shuntsu answer(0); } else if (codes[0] + 1 == codes[1] || codes[1] + 1 == codes[2]) { // ๆœ‰ไธคไธช่ฟž็ปญ็š„ answer(1); } else if (codes[0] + 2 == codes[1] || codes[1] + 2 == codes[2]) { // ไธคไธชไธญ้—ดๅˆšๅฅฝๅทฎไธ€ไธช answer(1); } else { answer(2); } scanner.close(); } public static void answer(int ans) { System.out.println(ans); } public static int code(String str) { int index = str.charAt(0) - '0'; int type = str.charAt(1) - 'm'; return index + type * 10; } }
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
l = list(input().split()) for i in range(3): l[i] = [l[i][1],l[i][0]] l.sort() for i in range(3): l[i] = [l[i][1],l[i][0]] #print(l) flag = 0 if l[0] == l[1]: if l[1] == l[2]: print(0) else: print(1) elif l[1] == l[2]: print(1) elif l[0][1] == l[1][1]: if abs(int(l[1][0]) - int(l[0][0])) == 1: if l[2][1] == l[1][1]: if abs(int(l[2][0]) - int(l[1][0])) == 1: print(0) else: print(1) else: print(1) elif abs(int(l[1][0]) - int(l[0][0])) == 2: print(1) else: flag = 1 else: flag = 1 if flag == 1: if l[1][1] == l[2][1]: #print(int(l[2][0]) - int(l[1][0])) if abs(int(l[2][0]) - int(l[1][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() k=0 a1 = a[0]+a[1] a2 = a[3]+a[4] a3 = a[6]+a[7] q=[] w=[] w1=[] q1=[] t=[] t1=[0]*3 w.append(int(a[0])) w.append(int(a[3])) w.append(int(a[6])) q.append(a[1]) q.append(a[4]) q.append(a[7]) t = sorted(w) t = list(t) for i in range(3): m = w.index(t[i]) del w[w.index(t[i])] t1[i] = q[m] del q[m] if a1 == a2 and a2 == a3 and a1 == a3: print(0) elif a1 == a2 or a2 == a3 or a1 == a3: print(1) elif t1[0]==t1[1]==t1[2] and (t[0]+1) == t[1] ==(t[2]-1): print(0) elif ((t1[0] == t1[1]) and ((abs(t[1] - t[0])==1) or (abs(t[1] - t[0])==2))) or ((t1[0] == t1[2]) and ((abs(t[2] - t[0])==1) or (abs(t[2] - t[0])==2))) or ((t1[2] == t1[1]) and ((abs(t[1] - t[2])==1) or (abs(t[1] - t[2])==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
import sys def solve(t): if t[0][1] != t[1][1] and t[0][1] != t[2][1] and t[1][1] != t[2][1]: return 2 if t[0][1] == t[1][1] and t[1][1] != t[2][1] \ or t[0][1] == t[2][1] and t[1][1] != t[0][1] \ or t[1][1] == t[2][1] and t[1][1] != t[0][1]: if t[0][1] == t[1][1] and t[1][0] - t[0][0] < 3: return 1 if t[0][1] == t[2][1] and t[2][0] - t[0][0] < 3: return 1 if t[1][1] == t[2][1] and t[2][0] - t[1][0] < 3: return 1 return 2 if t[0][0] == t[1][0] == t[2][0] or t[0][0] == t[1][0] - 1 == t[2][0] - 2: return 0 if t[1][0] - t[0][0] < 3 or t[2][0] - t[1][0] < 3: return 1 return 2 tiles = [[int(t[0]), t[1]] for t in input().split()] tiles.sort(key = lambda x: x[0]) print(solve(tiles))
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 num, m, tc, t = 1; int arr[3]; for (long long i = 0; i < 3; i++) { char ch; cin >> num >> ch; if (ch == 'm') arr[i] = num + 100; else if (ch == 'p') arr[i] = num + 200; else arr[i] = num + 300; } sort(arr, arr + 3); if (arr[0] == arr[1] && arr[1] == arr[2]) { cout << "0" << endl; } else if (arr[0] + 1 == arr[1] && arr[1] + 1 == arr[2]) { cout << "0" << endl; } else if (arr[0] == arr[1] || arr[1] == arr[2] || arr[0] + 1 == arr[1] || arr[1] + 1 == arr[2] || arr[0] + 2 == arr[1] || arr[1] + 2 == arr[2]) { cout << "1" << endl; } else 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
import java.util.*; import java.lang.*; import java.io.*; public class Codechef { static PrintWriter out=new PrintWriter(System.out); static FastScanner in = new FastScanner(System.in); static class FastScanner { BufferedReader br; StringTokenizer stok; FastScanner(InputStream is) { br = new BufferedReader(new InputStreamReader(is)); } String next() throws IOException { while (stok == null || !stok.hasMoreTokens()) { String s = br.readLine(); if (s == null) { return null; } stok = new StringTokenizer(s); } return stok.nextToken(); } int ni() throws IOException { return Integer.parseInt(next()); } long nl() throws IOException { return Long.parseLong(next()); } double nd() throws IOException { return Double.parseDouble(next()); } char nc() throws IOException { return (char) (br.read()); } String ns() throws IOException { return br.readLine(); } int[] nia(int n) throws IOException{ int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = ni(); } return a; } long[] nla(int n) throws IOException { long a[] = new long[n]; for (int i = 0; i < n; i++) a[i] = nl(); return a; } double[] nda(int n)throws IOException { double a[] = new double[n]; for (int i = 0; i < n; i++) a[i] = nd(); return a; } int [][] imat(int n,int m) throws IOException { int mat[][]=new int[n][m]; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) mat[i][j]=ni(); } return mat; } } /// PRINTING FUNCTIONS static void pia(int arr[]) throws IOException { for(int i=0;i<arr.length;i++) out.print(arr[i]+" "); out.println(); } static void pla(long arr[]) throws IOException { for(int i=0;i<arr.length;i++) out.print(arr[i]+" "); out.println(); } static void pimat(int mat[][]) { for(int i=0;i<mat.length;i++) { for(int j=0;j<mat[0].length;j++) out.print(mat[i][j]); out.println(); } } ///MAIN METHOD static long mod=Long.MAX_VALUE; public static void main (String[] args) throws java.lang.Exception { int i,j; HashMap<Integer,Integer> hm=new HashMap<Integer,Integer>(); /* if(hm.containsKey(z)) hm.put(z,hm.get(z)+1); else hm.put(z,1); */ ArrayList<Integer> arr=new ArrayList<Integer>(); HashSet<Integer> set=new HashSet<Integer>(); PriorityQueue<Integer> pq=new PriorityQueue<Integer>(); /* int n = in.ni(); int m = in.ni(); String s=in.ns(); int a[]=in.nia(n); int b[][]=in.im(n,m); pia(a); pimat(b); */ String s[]=new String[3]; s[0]=in.next(); s[1]=in.next(); s[2]=in.next(); int min=1000,temp=0; //THREE SAME if(s[0].equals(s[1])) temp++; if(s[1].equals(s[2])) temp++; if(s[2].equals(s[0])) temp++; if(temp>=2) min=0; else if(temp==1) min=1; else min=2; //SEQUENCE for(i=0;i<3;i++) { int temp2=0; char p=s[i].charAt(1); int z=(int)s[i].charAt(0)-'0'; String pp=Integer.toString(z+1)+Character.toString(p); String pp1=Integer.toString(z+2)+Character.toString(p); // System.out.println("pp="+pp+" pp1="+pp1); //System.out.println("---------"); // System.out.println(s[(i+1)%3]+" "+s[(i+2)%3]); //System.out.println("---------"); //System.out.println(s[(i+1)%3]+" "+s[(i+2)%3]); if(pp.equals(s[(i+1)%3])) { temp2++; //System.out.println(pp+" EQUALS"+s[(i+2)%3]); if(pp1.equals(s[(i+2)%3])) {temp2++; //System.out.println(pp+" EQUALS"+s[(i+1)%3]); } } //System.out.println("3-temp2-1="+(3-temp2-1)); min=Math.min(min,3-temp2-1); temp2=0; if(pp.equals(s[(i+2)%3])) { temp2++; //System.out.println(pp+" EQUALS"+s[(i+2)%3]); if(pp1.equals(s[(i+1)%3])) {temp2++; //System.out.println(pp+" EQUALS"+s[(i+1)%3]); } } min=Math.min(min,3-temp2-1); if(pp1.equals(s[(i+1)%3])) { temp2++; //System.out.println(pp+" EQUALS"+s[(i+2)%3]); if(pp.equals(s[(i+2)%3])) {temp2++; //System.out.println(pp+" EQUALS"+s[(i+1)%3]); } } //System.out.println("3-temp2-1="+(3-temp2-1)); min=Math.min(min,3-temp2-1); temp2=0; if(pp1.equals(s[(i+2)%3])) { temp2++; // System.out.println(pp+" EQUALS"+s[(i+2)%3]); if(pp.equals(s[(i+1)%3])) {temp2++; //System.out.println(pp+" EQUALS"+s[(i+1)%3]); } } min=Math.min(min,3-temp2-1); } if(min<0) min=0; out.println(min); out.close(); } static long gcd(long a,long b) { if(b==0) return a; return gcd(b,a%b); } static long exponent(long a,long n) { long ans=1; while(n!=0) { if(n%2==1) ans=(ans*a)%mod; a=(a*a)%mod; n=n>>1; } return ans; } static int binarySearch(int a[], int item, int low, int high) { if (high <= low) return (item > a[low])? (low + 1): low; int mid = (low + high)/2; if(item == a[mid]) return mid+1; if(item > a[mid]) return binarySearch(a, item, mid+1, high); return binarySearch(a, item, low, mid-1); } }
JAVA