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.*; import java.util.*; public class Codeforces { public static class Pair implements Comparable<Pair> { int x; char c; public Pair(int x, char c) { this.x = x; this.c = c; } @Override public int compareTo(Pair o) { return x - o.x; } @Override public String toString() { return x + "" + c; } public boolean equals(Pair obj) { return x == obj.x && c == obj.c; } } public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); Pair[] arr = new Pair[3]; StringTokenizer st = new StringTokenizer(br.readLine()); for (int i = 0; i < 3; i++) { String tmp = st.nextToken(); arr[i] = new Pair(Integer.parseInt("" + tmp.charAt(0)), tmp.charAt(1)); } Arrays.sort(arr); if (arr[0].equals(arr[1]) && arr[0].equals(arr[2]) && arr[1].equals(arr[2])) { System.out.println(0); } else if (arr[0].c == arr[1].c && arr[0].c == arr[2].c && arr[1].c == arr[2].c && arr[2].x - arr[0].x == 2 && arr[1].x - arr[0].x == 1) { System.out.println(0); } else if ((arr[0].c == arr[1].c && arr[1].x - arr[0].x == 1) || (arr[1].c == arr[2].c && arr[2].x - arr[1].x == 1) || (arr[0].c == arr[2].c && arr[2].x - arr[0].x == 1)) { System.out.println(1); } else if (arr[0].equals(arr[1]) || arr[1].equals(arr[2])) { System.out.println(1); } else if ((arr[0].c == arr[1].c && arr[1].x - arr[0].x == 2) || (arr[1].c == arr[2].c && arr[2].x - arr[1].x == 2) || (arr[0].c == arr[2].c && arr[2].x - arr[0].x == 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
a,b,c=sorted(10*ord(y)+int(x)for x,y in input().split()) s={b-a,c-b} print(2-bool(s&{0,1,2})-(s in({0},{1})))
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, …, 9m, 1p, 2p, …, 9p, 1s, 2s, …, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] β€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] β€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings β€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer β€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
import java.io.*; import java.util.*; import java.math.*; public class temp { public static void main(String args[])throws IOException { FastReader in=new FastReader(); PrintWriter out=new PrintWriter(System.out, true); int m[]=new int[10]; int p[]=new int[10]; int s[]=new int[10]; String a=in.next(); if(a.charAt(1)=='m') m[a.charAt(0)-48]++; if(a.charAt(1)=='p') p[a.charAt(0)-48]++; if(a.charAt(1)=='s') s[a.charAt(0)-48]++; a=in.next(); if(a.charAt(1)=='m') m[a.charAt(0)-48]++; if(a.charAt(1)=='p') p[a.charAt(0)-48]++; if(a.charAt(1)=='s') s[a.charAt(0)-48]++; a=in.next(); if(a.charAt(1)=='m') m[a.charAt(0)-48]++; if(a.charAt(1)=='p') p[a.charAt(0)-48]++; if(a.charAt(1)=='s') s[a.charAt(0)-48]++; if(cont(m,3)||cont(p,3)||cont(s,3)|| trip(m) ||trip(p)||trip(s)) { out.println(0); return; } else if(conseq(m)|| conseq(p)|| conseq(s)) { out.println(1); return; } else if(tocc(m)|| tocc(p)|| tocc(s)) out.println(1); else if(bet(m)|| bet(p)||bet(s)) out.println(1); else out.println(2); } public static boolean bet(int arr[]) { for(int i=0;i<=7;i++) if(arr[i]==1 && arr[i+1]==0 && arr[i+2]==1) return true; return false; } public static boolean tocc(int arr[]) { for(int i=0;i<10;i++) if(arr[i]==2) return true; return false; } public static boolean cont(int arr[], int v) { for(int i=0;i<arr.length;i++) if(arr[i]==v) return true; return false; } public static boolean trip(int arr[]) { for(int i=2;i<=9;i++) { if(arr[i]==arr[i-1] && arr[i-1]==arr[i-2] && arr[i]==1) return true; } return false; } public static boolean conseq(int arr[]) { for(int i=1;i<=9;i++) if(arr[i]==arr[i-1] && arr[i]==1) return true; return false; } } 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
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class B_573 { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] input = br.readLine().split( " "); int min = 10; for(int i = 0; i < input.length; i++){ int c = count(input, input[i]); min = Integer.min(c, min); int n = Integer.valueOf(input[i].substring(0, 1)); String ch = input[i].substring(1, 2); int c2 = contains(input, (n+1)+ch) + contains(input, (n+2)+ch); min = Integer.min(c2, min); } System.out.println(min); } static int count(String[] arr, String s){ int counter = 3; for(int i = 0; i < arr.length; i++){ if(arr[i].equals(s)){ counter--; } } return counter; } static int contains(String[] arr, String s){ for(int i = 0; i < arr.length; i++){ if(arr[i].equals(s)){ return 0; } } return 1; } }
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 s[3]; map<string, long long> map1; map<char, long long> map2; map2['m'] = 0, map2['p'] = 1, map2['s'] = 2; long long a[10][3] = {}; for (int i = 0; i < 3; i++) { cin >> s[i]; map1[s[i]]++; a[s[i][0] - '0'][map2[s[i][1]]] = 1; } for (int i = 0; i < 3; i++) { for (int j = 1; j < 10; j++) { a[j][i] += a[j - 1][i]; } } long long count1 = 0; for (int i = 0; i < 3; i++) { for (int j = 3; j < 10; j++) { count1 = max(count1, a[j][i] - a[j - 3][i]); } } map<string, long long>::iterator itr; long long max1 = 1; for (itr = map1.begin(); itr != map1.end(); itr++) { max1 = max(max1, itr->second); } cout << 3 - max(max1, count1); 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 = map(lambda x: [int(x[0]),x[1]], raw_input().split()) ck = 3 - max(a.count(a[0]), max(a.count(a[1]), a.count(a[2]))) cs0, cs1, cs2 = 2, 2, 2 if [a[0][0]+1, a[0][1]] in a : cs0 -= 1 if [a[0][0]+2, a[0][1]] in a : cs0 -= 1 if [a[1][0]+1, a[1][1]] in a : cs1 -= 1 if [a[1][0]+2, a[1][1]] in a : cs1 -= 1 if [a[2][0]+1, a[2][1]] in a : cs2 -= 1 if [a[2][0]+2, a[2][1]] in a : cs2 -= 1 print min([cs0, cs1, cs2, ck])
PYTHON
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, …, 9m, 1p, 2p, …, 9p, 1s, 2s, …, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] β€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] β€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings β€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer β€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
def main(): ss = list(map(str,input().split())) for i in range(0,len(ss)): ss[i] = ss[i][::-1] ss = sorted(ss) for i in range(0,len(ss)): ss[i] = ss[i][::-1] for i in range(0,len(ss)-2): if ss[i]==ss[i+1]==ss[i+2]: print(0) exit(0) elif (ord(ss[i][0])+2 == ord(ss[i+1][0])+1 == ord(ss[i+2][0])) and ss[i][1]==ss[i+1][1]==ss[i+2][1]: print(0) exit(0) for i in range(0,len(ss)-1): if ss[i]==ss[i+1]: print(1) exit(0) elif (ord(ss[i][0])+1 == ord(ss[i+1][0]) or ord(ss[i][0])+2 == ord(ss[i+1][0])) and ss[i][1]==ss[i+1][1]: print(1) exit(0) print(2) if __name__ == "__main__" : main()
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, …, 9m, 1p, 2p, …, 9p, 1s, 2s, …, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] β€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] β€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings β€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer β€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
m,p,s = input().split() sp = [(int(m[0]),m[1]),(int(p[0]),p[1]),(int(s[0]),s[1])] sp.sort() g = set() g.add(m[1]) g.add(p[1]) g.add(s[1]) if m == p and p == s or sp[2][0]-sp[1][0] == 1 and sp[2][0]-sp[0][0] == 2 and len(g) == 1: print(0) else: if m == p or p == s or m == s: print(1) elif sp[2][0]-sp[1][0] == 1 and sp[2][1] == sp[1][1]: print(1) elif sp[1][0]-sp[0][0] == 1 and sp[1][1] == sp[0][1]: print(1) elif sp[2][0]-sp[0][0] == 1 and sp[2][1] == sp[0][1]: print(1) elif sp[2][0]-sp[1][0] == 2 and sp[2][1] == sp[1][1]: print(1) elif sp[1][0]-sp[0][0] == 2 and sp[1][1] == sp[0][1]: print(1) elif sp[2][0]-sp[0][0] == 2 and sp[2][1] == sp[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
def smaller(x, y): if x < y: return x return y def kohtsu(a, b, c): if a == b: if b == c: return 0 else: return 1 return 2 def shuntsu(a, b, c): if a[1] == b[1]: if int(a[0])+2 == int(b[0]): if (c[1] == a[1]) and (int(a[0])+1 == int(c[0])): return 0 else: return 1 if int(a[0])+1 == int(b[0]): if (c[1] == a[1]) and (int(a[0])-1 == int(c[0]) or int(b[0])+1 == int(c[0])): return 0 else: return 1 return 2 inpt = input().split() ans = 2 ans = smaller(ans, kohtsu(inpt[0], inpt[1], inpt[2])) ans = smaller(ans, shuntsu(inpt[0], inpt[1], inpt[2])) ans = smaller(ans, kohtsu(inpt[0], inpt[2], inpt[1])) ans = smaller(ans, shuntsu(inpt[0], inpt[2], inpt[1])) ans = smaller(ans, kohtsu(inpt[1], inpt[0], inpt[2])) ans = smaller(ans, shuntsu(inpt[1], inpt[0], inpt[2])) ans = smaller(ans, kohtsu(inpt[1], inpt[2], inpt[0])) ans = smaller(ans, shuntsu(inpt[1], inpt[2], inpt[0])) ans = smaller(ans, kohtsu(inpt[2], inpt[0], inpt[1])) ans = smaller(ans, shuntsu(inpt[2], inpt[0], inpt[1])) ans = smaller(ans, kohtsu(inpt[2], inpt[1], inpt[0])) ans = smaller(ans, shuntsu(inpt[2], inpt[1], inpt[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; void putitin(string ss, vector<int> &s, vector<int> &m, vector<int> &p) { int ele = (int)ss[0] - (int)'0'; if (ss[1] == 's') { s.push_back(ele); } if (ss[1] == 'm') { m.push_back(ele); } if (ss[1] == 'p') { p.push_back(ele); } } void solve() { string s1, s2, s3; cin >> s1 >> s2 >> s3; vector<int> s; vector<int> m; vector<int> p; putitin(s1, s, m, p); putitin(s2, s, m, p); putitin(s3, s, m, p); sort(s.begin(), s.end()); sort(m.begin(), m.end()); sort(p.begin(), p.end()); if (s.size() == 3) { sort(s.begin(), s.end()); bool identical = true; bool sequential = true; int id = 0; int sq = 0; for (int i = 0; i < s.size() - 1; i++) { if (s[i] != s[i + 1]) { identical = false; } else { id++; } } for (int i = 0; i < s.size() - 1; i++) { if (s[i] + 1 != s[i + 1]) { sequential = false; } else { sq++; } } if (identical || sequential) { cout << 0 << endl; } else if (id || sq) { cout << 1 << endl; } else if ((s[0] + 2 == s[1]) || (s[1] + 2 == s[2])) { cout << 1 << endl; } else { cout << 2 << endl; } } else if (m.size() == 3) { sort(m.begin(), m.end()); bool identical = true; bool sequential = true; int id = 0; int sq = 0; for (int i = 0; i < m.size() - 1; i++) { if (m[i] != m[i + 1]) { identical = false; } else { id++; } } for (int i = 0; i < m.size() - 1; i++) { if (m[i] + 1 != m[i + 1]) { sequential = false; } else { sq++; } } if (identical || sequential) { cout << 0 << endl; } else if (id || sq) { cout << 1 << endl; } else if ((m[0] + 2 == m[1]) || (m[1] + 2 == m[2])) { cout << 1 << endl; } else { cout << 2 << endl; } } else if (p.size() == 3) { sort(p.begin(), p.end()); bool identical = true; bool sequential = true; int id = 0; int sq = 0; for (int i = 0; i < p.size() - 1; i++) { if (p[i] != p[i + 1]) { identical = false; } else { id++; } } for (int i = 0; i < p.size() - 1; i++) { if (p[i] + 1 != p[i + 1]) { sequential = false; } else { sq++; } } if (identical || sequential) { cout << 0 << endl; } else if (id || sq) { cout << 1 << endl; } else if ((p[0] + 2 == p[1]) || (p[1] + 2 == p[2])) { cout << 1 << endl; } else { cout << 2 << endl; } } else if (s.size() == 2) { if ((s[0] == s[1]) || (s[0] + 1 == s[1])) { cout << 1 << endl; } else if ((s[0] + 2 == s[1])) { cout << 1 << endl; } else { cout << 2 << endl; } } else if (m.size() == 2) { if ((m[0] == m[1]) || (m[0] + 1 == m[1])) { cout << 1 << endl; } else if ((m[0] + 2 == m[1])) { cout << 1 << endl; } else { cout << 2 << endl; } } else if (p.size() == 2) { if ((p[0] == p[1]) || (p[0] + 1 == p[1])) { cout << 1 << endl; } else if ((p[0] + 2 == p[1])) { cout << 1 << endl; } else { cout << 2 << endl; } } else { cout << 2 << endl; } } int main() { int t = 1; while (t--) { solve(); } }
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 = { 'm': 10, 's': 30, 'p': 60 } a, b, c = list(sorted([int(i[0]) + d[i[1]] for i in input().split(' ')])) if (a == b and b == c) or (a == b - 1 and b == c - 1): print(0) exit() if a == b - 1 or b == c - 1 or a == b or b == c or a == c - 2 or a == b - 2 or b == c - 2: print(1) exit() print(2) ''' d={'m':10,'p':30,'s':50} #men=> kou or shu a,y,z=sorted([int(x[0])+d[x[1]] for x in (input().split())]) print(a,y,z) #kou and sust if (a==y and y==z) or (a==y-1 and y==z-1): print(0) elif a==y or y==z or a==z or a==y-1 or y==z-1 or a==y-2 or y==z-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
from __future__ import division, print_function def main(): from itertools import product, combinations s = input().split() c = [(int(d), t) for d, t in s] def f(c): if c[0] == c[1] == c[2]: return True sc = sorted(c) if c[0][1] == c[1][1] == c[2][1] and sc[0][0]+2 == sc[1][0]+1 == sc[2][0]: return True return False if f(c): print(0) return for d, t in product(range(1, 10), 'mps'): nc = c + [(d, t)] for ci in combinations(nc, 3): if f(ci): print(1) return print(2) INF = float('inf') MOD = 10**9 + 7 import os, sys from atexit import register from io import BytesIO import itertools if sys.version_info[0] < 3: input = raw_input range = xrange filter = itertools.ifilter map = itertools.imap zip = itertools.izip if "LOCAL_" in os.environ: debug_print = print else: sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size)) sys.stdout = BytesIO() register(lambda: os.write(1, sys.stdout.getvalue())) input = lambda: sys.stdin.readline().rstrip('\r\n') debug_print = lambda *x, **y: None def input_as_list(): return list(map(int, input().split())) def array_of(f, *dim): return [array_of(f, *dim[1:]) for _ in range(dim[0])] if dim else f() main()
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
from collections import Counter as ct a = map(lambda x: (int(x[0]), x[1]), input().split()) ms = { 's': [], 'p': [], 'm': [], } for num, suit in a: ms[suit].append(num) def to_koutsu(arr: list): st = ct(arr).most_common() return 3 - st[0][1] def to_shuntsu(arr: list): st = list(sorted(arr)) step = 0 for x, y in zip(st[:-1], st[1:]): if y - x == 1: step += 1 if y - x == 2: return 1 return 3 - (step + 1) minNum = 3 for tile in ms.values(): if not tile: continue elif len(tile) == 1: minNum = min(minNum, 2) else: minNum = min(minNum, min(to_koutsu(tile), to_shuntsu(tile))) print(minNum)
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<string> v; for (int i = 0; i < 3; i++) { string s; cin >> s; v.push_back(s); } vector<string> so; vector<string> po; vector<string> mo; for (int i = 0; i < v.size(); i++) { if (v[i][1] == 's') so.push_back(v[i]); else if (v[i][1] == 'p') po.push_back(v[i]); else if (v[i][1] == 'm') mo.push_back(v[i]); } sort(so.begin(), so.end()); sort(po.begin(), po.end()); sort(mo.begin(), mo.end()); if (v[0] == v[1] && v[1] == v[2]) cout << 0 << endl; else if (v[0] == v[1] || v[0] == v[2] || v[1] == v[2]) cout << 1 << endl; else if (so.size() == 3) { int m1 = (so[2][0] - '0') - (so[1][0] - '0'); int m2 = (so[1][0] - '0') - (so[0][0] - '0'); if (m1 == 1 && m2 == 1) cout << "0" << endl; else if (m1 <= 2 || m2 <= 2) cout << "1" << endl; else cout << "2" << endl; } else if (mo.size() == 3) { int m1 = (mo[2][0] - '0') - (mo[1][0] - '0'); int m2 = (mo[1][0] - '0') - (mo[0][0] - '0'); if (m1 == 1 && m2 == 1) cout << "0" << endl; else if (m1 <= 2 || m2 <= 2) cout << "1" << endl; else cout << "2" << endl; } else if (po.size() == 3) { int m1 = (po[2][0] - '0') - (po[1][0] - '0'); int m2 = (po[1][0] - '0') - (po[0][0] - '0'); if (m1 == 1 && m2 == 1) cout << "0" << endl; else if (m1 <= 2 || m2 <= 2) cout << "1" << endl; else cout << "2" << endl; } else if (so.size() == 2) { int m1 = (so[1][0] - '0') - (so[0][0] - '0'); if (m1 == 1 || m1 == 2) cout << "1" << endl; else cout << "2\n"; } else if (mo.size() == 2) { int m1 = (mo[1][0] - '0') - (mo[0][0] - '0'); if (m1 == 1 || m1 == 2) cout << "1" << endl; else cout << "2\n"; } else if (po.size() == 2) { int m1 = (po[1][0] - '0') - (po[0][0] - '0'); if (m1 == 1 || m1 == 2) cout << "1" << endl; else cout << "2\n"; } else cout << "2\n"; return 0; }
CPP
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, …, 9m, 1p, 2p, …, 9p, 1s, 2s, …, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] β€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] β€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings β€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer β€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
hand = input().split() s_hand = [[] for i in range(3)] # m, p, s shuntsu = 100 for i in hand: s_hand['mps'.index(i[1])].append(int(i[0])) for i in s_hand: if not i: continue if len(i) == 1: shuntsu = min(shuntsu, 2) elif len(i) == 2: shuntsu = min(shuntsu, 1 if abs(i[0] - i[1]) in (1, 2) else 100) else: s_i = sorted(i) if s_i[0] + 1 == s_i[1] and s_i[1] + 1 == s_i[2]: shuntsu = 0 else: shuntsu = min(shuntsu, min(1 if abs(i[0] - i[1]) in (1, 2) else 100, 1 if abs(i[1] - i[2]) in (1, 2) else 100, 1 if abs(i[0] - i[2]) in (1, 2) else 100)) t = len(set(hand)) koutsu = 0 if t == 1 else 1 if t == 2 else 2 print(min(shuntsu, koutsu))
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, …, 9m, 1p, 2p, …, 9p, 1s, 2s, …, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] β€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] β€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings β€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer β€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
s = input().split() s.sort() if s[0] == s[1] == s[2]: print(0) exit() if s[0][1] == s[1][1] == s[2][1]: if ord(s[0][0]) + 1 == ord(s[1][0]) == ord(s[2][0]) - 1: print(0) exit() if s[0][1] == s[1][1] and ord(s[0][0]) + 2 >= ord(s[1][0]) or s[1][1] == s[2][1] and ord(s[1][0]) + 2 >= ord(s[2][0]) or s[0][1] == s[2][1] and ord(s[0][0]) + 2 >= ord(s[2][0]): print(1) exit() if s[0] == s[1] or s[1] == s[2] or s[0] == s[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
a=list(input().split()) ar1=[] ar2=[] for i in a: ar1.append(int(i[0])) ar2.append(i[1]) s=set() for i in range(3): for j in range(i+1,3): if ar2[i]==ar2[j]: s.add(i) s.add(j) if len(s)==0: print(2) elif len(s)==2: i1=s.pop() i2=s.pop() if abs(ar1[i1]-ar1[i2])<=2: print(1) else: print(2) else: ar1.sort() d1=ar1[1]-ar1[0] d2=ar1[2]-ar1[1] if d1==0: if d2==0: print(0) else: print(1) elif d1==1: if d2==1: print(0) else: print(1) elif d1==2 or d2==2: print(1) else: if d2==0 or d2==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
from collections import Counter a,b,c=list(map(str,input().split())) s=[a[1],b[1],c[1]] t=[a[0],b[0],c[0]] u=Counter(s) v=Counter(t) if(len(u.keys())==1): if(len(v.keys())==1): print(0) elif(len(v.keys())==2): print(1) else: t[0]=int(t[0]) t[1]=int(t[1]) t[2]=int(t[2]) t.sort() if(t[0]+1==t[1] and t[2]-1==t[1]): print(0) elif(t[0]+1==t[1] or t[2]-1==t[1] or t[0]+2==t[1]): print(1) else: print(2) else: if(len(u.keys())==3): print(2) elif(len(u.keys())==2): if(a[1]==b[1]): k=a j=b elif(a[1]==c[1]): k=a j=c elif(b[1]==c[1]): k=b j=c if(k[0]==j[0]): print(1) else: if(abs(ord(k[0])-ord(j[0]))==1 or abs(ord(k[0])-ord(j[0]))==2 or abs(ord(k[0])-ord(j[0]))==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
import collections nums = list(map(str,input().split())) dd = collections.defaultdict(int) for i in nums: dd[i] += 1 if dd[i] == 3: print(0) exit() for key in dd: if dd[key] == 2: print(1) exit() else: tk0 = str(int(key[0]) + 1) + key[1] tk1 = str(int(key[0]) + 2) + key[1] tk2 = str(int(key[0]) - 1) + key[1] tk3 = str(int(key[0]) - 2) + key[1] if tk1 in dd and tk0 in dd: print(0) exit() elif tk0 in dd and tk2 in dd: print(0) exit() elif tk2 in dd and tk3 in dd: print(0) exit() elif tk0 in dd or tk1 in dd or tk2 in dd or tk3 in dd: print(1) exit() print(2) exit()
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, …, 9m, 1p, 2p, …, 9p, 1s, 2s, …, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] β€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] β€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings β€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer β€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
####################################################################################################################### # Author: BlackFyre # Language: PyPy 3.7 ####################################################################################################################### from sys import stdin, stdout, setrecursionlimit from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log from collections import defaultdict as dd, deque from heapq import merge, heapify, heappop, heappush, nsmallest from bisect import bisect_left as bl, bisect_right as br, bisect from collections import defaultdict as dd mod = pow(10, 9) + 7 mod2 = 998244353 # setrecursionlimit(3000) def inp(): return stdin.readline().strip() def iinp(): return int(inp()) def out(var, end="\n"): stdout.write(str(var) + "\n") def outa(*var, end="\n"): stdout.write(' '.join(map(str, var)) + end) def lmp(): return list(mp()) def mp(): return map(int, inp().split()) def smp(): return map(str, inp().split()) def l1d(n, val=0): return [val for i in range(n)] def l2d(n, m, val=0): return [l1d(m, val) for j in range(n)] def remadd(x, y): return 1 if x % y else 0 def ceil(a, b): return (a + b - 1) // b def def_value(): return 0 a = list(smp()) a.sort() if a[0]==a[1] and a[1]==a[2]: print(0) elif a[0]==a[2] or a[0]==a[1] or a[1]==a[2]: print(1) elif a[0][1]==a[1][1] and a[1][1]==a[2][1] and int(a[0][0])+1==int(a[1][0]) and int(a[1][0])+1==int(a[2][0]): print(0) elif a[0][1]==a[1][1] and (int(a[0][0])+1==int(a[1][0]) or int(a[0][0])+2==int(a[1][0])): print(1) elif a[0][1]==a[2][1] and (int(a[0][0])+1==int(a[2][0]) or int(a[0][0])+2==int(a[2][0])): print(1) elif a[1][1]==a[2][1] and (int(a[1][0])+1==int(a[2][0]) or int(a[1][0])+2==int(a[2][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
a=input().split() b=[a[0][1],a[1][1],a[2][1]] c=sorted([int(a[0][0]),int(a[1][0]),int(a[2][0])]) d=len(list(set(a))) e=len(list(set(b))) if e==1: if d==1: print(0) elif d==2: print(1) elif d==3: if c[1]-c[0]==1 and c[2]-c[1]==1: print(0) elif c[1]-c[0]==1 or c[2]-c[1]==1 or c[1]-c[0]==2 or c[2]-c[1]==2: print(1) else: print(2) elif e==3: print(2) elif e==2: a.sort() if d==2: print(1) elif a[0][1]==a[1][1]: if int(a[1][0])-int(a[0][0])==1 or int(a[1][0])-int(a[0][0])==2: print(1) else: print(2) elif a[1][1]==a[2][1]: if int(a[2][0])-int(a[1][0])==1 or int(a[2][0])-int(a[1][0])==2: print(1) else: print(2) elif a[0][1]==a[2][1]: if int(a[2][0])-int(a[0][0])==1 or int(a[2][0])-int(a[0][0])==2: 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 = input().split() p = [] m = [] s = [] for i in l: if i[1] == "p": p.append(int(i[0])) if i[1] =="m": m.append(int(i[0])) if i[1] == "s": s.append(int(i[0])) same = 1 conseq = 1 ans = 2 if p and m and s: print(2) exit() if len(p)>1: p.sort() for i in p: same = max(same,p.count(i)) for i in range(len(p)-1): j =i+1 if p[j]-p[i]==1: conseq+=1 for i in range(len(p)-1): j =i+1 if p[j]-p[i]==2: conseq =(max(conseq,2)) if len(m) > 1: m.sort() for i in m: same = max(same,m.count(i)) for i in range(len(m)-1): j =i+1 if m[j]-m[i]==1: conseq +=1 for i in range(len(m)-1): j =i+1 if m[j]-m[i]==2: conseq =(max(conseq,2)) if len(s) > 1: s.sort() for i in s: same = max(same,s.count(i)) for i in range(len(s)-1): j =i+1 if s[j]-s[i]==1: conseq +=1 for i in range(len(s)-1): j =i+1 if s[j]-s[i]==2: conseq =(max(conseq,2)) print(min(2,3-max(same,conseq)))
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 = input().split() ans = 2 if t1 == t2 or t2 == t3 or t3 == t1: if t1 == t2 == t3: ans = 0 else: ans = 1 aaa = [] for i in range(10): for j in range(10): for k in range(10): if k - j == j - i == 1: aaa.append({i, j, k}) if t1[1] == t2[1] == t3[1] and {int(t1[0]), int(t2[0]), int(t3[0])} in aaa: ans = 0 elif (t1[1] == t2[1] and (abs(int(t1[0]) - int(t2[0])) == 1 or abs(int(t1[0]) - int(t2[0])) == 2)) or (t1[1] == t3[1] and (abs(int(t1[0]) - int(t3[0])) == 1 or abs(int(t1[0]) - int(t3[0])) == 2)) or (t3[1] == t2[1] and (abs(int(t3[0]) - int(t2[0])) == 1 or abs(int(t3[0]) - int(t2[0])) == 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
#include <bits/stdc++.h> using namespace std; const long long MX5 = 3 * 1e5 + 3; const long long MX6 = 1 * 1e6 + 37; const long long INF = 8e18; const long long MOD = 1e9 + 7; const long long MOD2 = 998244353; long long power(long long a, long long b, long long md) { return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md)); } long long bmm(long long a, long long b) { return (a % b == 0 ? b : bmm(b, a % b)); } long long A[MX5]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); string a, b, c; cin >> a >> b >> c; int a1 = a[0] - '0'; int a2 = b[0] - '0'; int a3 = c[0] - '0'; if (a == b && b == c) { cout << 0; return 0; } if (a[1] == b[1]) { if (b[1] == c[1]) { if (a1 == a2 && a2 == a3) { cout << 0; return 0; } if (min({a1, a2, a3}) + 2 == max({a1, a2, a3}) && a1 != a2 && a2 != a3 && a3 != a1) { cout << 0; return 0; } if (a1 == a2 || a2 == a3 || a1 == a3) { cout << 1; return 0; } if (min({abs(a1 - a2), abs(a1 - a3), abs(a2 - a3)}) == 1 || min({abs(a1 - a2), abs(a1 - a3), abs(a2 - a3)}) == 2) { cout << 1; return 0; } cout << 2; return 0; } else { if (a1 == a2) { cout << 1; return 0; } if (abs(a1 - a2) == 1 || abs(a1 - a2) == 2) { cout << 1; return 0; } cout << 2; return 0; } } if (a[1] == c[1]) { if (a1 == a3) { cout << 1; return 0; } if (abs(a1 - a3) == 1 || abs(a1 - a3) == 2) { cout << 1; return 0; } cout << 2; return 0; } else if (b[1] == c[1]) { if (a3 == a2) { cout << 1; return 0; } if (abs(a3 - a2) == 1 || abs(a3 - a2) == 2) { cout << 1; return 0; } cout << 2; return 0; } else { cout << 2; } return 0; }
CPP
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, …, 9m, 1p, 2p, …, 9p, 1s, 2s, …, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] β€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] β€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings β€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer β€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
ms = [i for i in input().split()] m1, m2, m3 = [i for i in sorted(ms, reverse=True)] if m1 == m2 == m3 or (m1[1] == m2[1] == m3[1] and int(m1[0]) == int(m2[0]) + 1 == int(m3[0]) + 2): print(0) elif (m1 == m2 or m2 == m3 or m1 == m3) \ or (m1[1] == m2[1] and (int(m1[0]) == int(m2[0]) + 1 or int(m1[0]) == int(m2[0]) + 2) or m1[1] == m3[1] and (int(m1[0]) == int(m3[0]) + 1 or int(m1[0]) == int(m3[0]) + 2) or m3[1] == m2[1] and (int(m2[0]) == int(m3[0]) + 1 or int(m2[0]) == int(m3[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
################# # July 17th 2019. ################# ############################################################## # Class Definition. class Mahjong: # Method to determine solution. def requiredTileCount(self): # Finding Costs and return minimum tiles. mahjong.costOfMentsu();mahjong.costOfKoutsu() return min(self.costM,self.costK) # Method to determine cost of pursuing mentsu. def costOfMentsu(self): cost = 3 for suite in ['m','p','s']: for digit in range(1,10): cost = min(cost,3-self.tiles[suite][digit]) self.costM = cost # Method to determine cost of pursuing koutsu. def costOfKoutsu(self): cost = 3 for suite in ['m','p','s']: for index in range(1,8): target = self.tiles[suite][index:index+3] cost = min(cost,self.count_zeros(target)) self.costK = cost # Method to count number of zeroes in a list. def count_zeros(self,listy): count = 0 for i in range(len(listy)): if listy[i] == 0: count+=1 return count # Constructor. def __init__(self,hand): # Getting Hand and setting up tile dictionary. self.tiles = {} for suite in ['m','p','s']:self.tiles[suite] = [0]*10 # Loading Hand into dictionary. for index in [0,1,2]: value,key = list(hand.pop(0)) # Adding to tiles. self.tiles[key][int(value)]+=1 # For retaining final costs. self.costM,self.costK = 3,3 ############################################################## # Making Mahjong instance. mahjong = Mahjong(list(input().split(' '))) print(mahjong.requiredTileCount()) ############################################################## ######################################## # Programming-Credits atifcppprogrammer. ########################################
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 = list(input().split(" ")) d={} d["m"]=[] d["p"]=[] d["s"]=[] q=[] for i in l : if i[1]=="m": d["m"].append(int(i[0])) elif i[1]=="p": d["p"].append(int(i[0])) else: d["s"].append(int(i[0])) ma=0 e="" for i in d: if len(d[i])>=ma: ma=len(d[i]) e=i if len(d[e])==1: print(2) elif len(d[e])==2: if abs(d[e][0]-d[e][1])==1 or abs(d[e][0]-d[e][1])==0 or abs(d[e][0]-d[e][1])==2: print(1) else: print(2) else: d[e].sort() f=[] f.append(d[e][0]-d[e][1]) f.append(d[e][1]-d[e][2]) f.append(d[e][0]-d[e][2]) if f.count(0)==3 or (f.count(-1)==2 and f.count(-2)==1): print(0) elif f.count(0)==1 or f.count(-1)==1 or f.count(-2)>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
a=list(map(str,input().split())) p=[0]*9 m=[0]*9 s=[0]*9 p1=[0]*9 m1=[0]*9 s1=[0]*9 p2=[0]*9 m2=[0]*9 s2=[0]*9 for i in a: if(i[1]=="p"): u=int(i[0]) p[u-1]+=1 p2[u-1]=1 elif(i[1]=="m"): u=int(i[0]) m[u-1]+=1 m2[u-1]=1 else: u=int(i[0]) s[u-1]+=1 s2[u-1]=1 for i in range(9): if(i==0): p1[i]=p2[i]+p2[i+1]+p2[i+2] m1[i]=m2[i]+m2[i+1]+m2[i+2] s1[i]=s2[i]+s2[i+1]+s2[i+2] elif(i==8): p1[i]=p2[i]+p2[i-1]+p2[i-2] m1[i]=m2[i]+m2[i-1]+m2[i-2] s1[i]=s2[i]+s2[i-1]+s2[i-2] else: p1[i]=p2[i]+p2[i+1]+p2[i-1] m1[i]=m2[i]+m2[i+1]+m2[i-1] s1[i]=s2[i]+s2[i+1]+s2[i-1] if(p.count(3) or m.count(3) or s.count(3)or p1.count(3) or m1.count(3) or s1.count(3) >=1): print("0") elif(p.count(2) or m.count(2) or s.count(2)or p1.count(2) or m1.count(2) or s1.count(2) >=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
a = list(map(str,input().split())) a.sort() #print(a[0],a[1],a[2]) if(a[0]==a[1]==a[2]): print(0) elif(a[0][1]==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): print(0) elif(a[0]==a[1] or a[1]==a[2] or a[0]==a[2]): print(1) elif(a[0][1]==a[1][1] and abs(int(a[0][0])-int(a[1][0]))<=2): print(1) elif(a[1][1]==a[2][1] and abs(int(a[1][0])-int(a[2][0]))<=2): print(1) elif(a[0][1]==a[2][1] and abs(int(a[0][0])-int(a[2][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 java.io.*; import java.math.*; import java.nio.Buffer; import java.sql.SQLSyntaxErrorException; import java.util.*; import java.text.*; import java.util.stream.Collectors; public class Main { public static int c(int n,int m){ int count=1; for(int i=1;i<=m;i++){ count*=(n-i+1); } for(int i=2;i<=m;i++){ count=count/i; } return count; } public static void reset(){ System.out.println("R"); } public static boolean query(int x){ Scanner cin = new Scanner(System.in); System.out.printf("? %d\n",x+1); String str=cin.next(); char s[]=str.toCharArray(); if(s[0]=='Y'){ return true; } else{ return false; } } public static long dis(long x,long y,long x1,long y1){ return Math.abs(x-x1)+Math.abs(y-y1); } static final char[] VALUES = { 'S', 'E', 'T' }; static int[][][][]dp=new int[105][100][100][2]; static int []num; static int MOD = 1000000007; public static void main(String[] args) { Scanner cin = new Scanner(System.in); String a=cin.next(); String b=cin.next(); String c=cin.next(); char a1[]=a.toCharArray(); char b1[]=b.toCharArray(); char c1[]=c.toCharArray(); int num[]={a1[0]-'0',b1[0]-'0',c1[0]-'0'}; int res=2; if(a.equals(b)&&a.equals(c)){ res=0; } else if(a.equals(b)||a.equals(c)||b.equals(c)){ res=1; } if(a1[1]==b1[1]&&b1[1]==c1[1]){ Arrays.sort(num); if(num[0]+1==num[1]&&num[1]+1==num[2]){ res=0; } else if(num[1]-num[0]<=2||num[2]-num[1]<=2){ res=Math.min(res,1); } } else if(a1[1]==b1[1]){ if(Math.abs(num[1]-num[0])<=2){ res=Math.min(res,1); } } else if(a1[1]==c1[1]){ if(Math.abs(num[2]-num[0])<=2){ res=Math.min(res,1); } } else if(b1[1]==c1[1]){ if(Math.abs(num[2]-num[1])<=2){ res=Math.min(res,1); } } System.out.println(res); } public static int slove(int idx,int odd,int even,int lst){ if(odd<0||even<0){ return Integer.MAX_VALUE; } if(idx==num.length){ return 0; } if(dp[idx][odd][even][lst]!=0){ return dp[idx][odd][even][lst]; } int res=Integer.MAX_VALUE; if(num[idx]!=0){ res=slove(idx+1,odd,even,num[idx]%2); res+=num[idx]%2==lst?0:1; dp[idx][odd][even][lst]=res; } else{ res=slove(idx+1,odd-1,even,0); int r=slove(idx+1,odd,even-1,1); if(res!=Integer.MAX_VALUE)res+= lst==0?0:1; if(r!=Integer.MAX_VALUE) r+= lst==0?1:0; dp[idx][odd][even][lst]=Math.min(res, r); } return dp[idx][odd][even][lst]; } public static String compute(String x,String y){ StringBuilder result=new StringBuilder(); for(int i=0;i<x.length();i++){ char a=x.charAt(i); char b=y.charAt(i); char ch; if(a==b){ ch=a; } else{ for(int j=0;;j++){ if(VALUES[j]!=a&&VALUES[j]!=b){ ch=VALUES[j]; break; } } } result.append(ch); } return result.toString(); } }
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
m={"m":[0]*9, "s":[0]*9, "p":[0]*9} for s in input().split(): m[s[1]][int(s[0])-1]+=1 ans = 2 for c in "smp": l = m[c] if(max(l)>=2): ans = min(ans, 3-max(l)) else: for i in range(7): sm = sum(l[i:i+3]) ans = min(ans, 3-sm) 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 majong(tiles): result, flag = 2, 0 if tiles[0] == tiles[1] and tiles[1] == tiles[2]: result = 0 elif tiles[0] != tiles[1] and tiles[1] != tiles[2]: if tiles[0][1] == tiles[1][1]: if int(tiles[0][0]) >= int(tiles[1][0]) - 2: result = 1 if int(tiles[0][0]) == int(tiles[1][0]) - 1: flag = 1 if tiles[1][1] == tiles[2][1]: if int(tiles[1][0]) == int(tiles[2][0]) - 1: result = 1 if flag: result = 0 if int(tiles[1][0]) == int(tiles[2][0]) - 2: result = 1 if tiles[0][1] == tiles[2][1]: if int(tiles[0][0]) >= int(tiles[2][0]) - 2 and flag != 1: result = 1 else: result = 1 return result s = input().split(' ') print(majong(sorted(s)))
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, …, 9m, 1p, 2p, …, 9p, 1s, 2s, …, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] β€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] β€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings β€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer β€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
#include <bits/stdc++.h> using namespace std; int k, ans; int a[4]; string s1, s2, s3; map<string, int> fix; int main() { cin >> s1 >> s2 >> s3; fix[s1]++; fix[s2]++; fix[s3]++; ans = min(min((3 - fix[s2]), (3 - fix[s3])), (3 - fix[s1])); if (s1[1] == s2[1] && s1[1] == s3[1]) { a[1] = s1[0]; a[2] = s2[0]; a[3] = s3[0]; sort(a + 1, a + 3 + 1); if (a[2] - a[1] == 1 && a[3] - a[2] == 1) { cout << 0 << endl; return 0; } if (abs(int(s1[0]) - int(s2[0])) == 2 || abs(int(s1[0]) - int(s2[0])) == 1) ans = min(ans, 1); if (abs(int(s1[0]) - int(s3[0])) == 2 || abs(int(s1[0]) - int(s3[0])) == 1) ans = min(ans, 1); if (abs(int(s3[0]) - int(s2[0])) == 2 || abs(int(s3[0]) - int(s2[0])) == 1) ans = min(ans, 1); cout << ans << endl; return 0; } if (s1[1] == s2[1]) { if (abs(int(s1[0]) - int(s2[0])) == 2 || abs(int(s1[0]) - int(s2[0])) == 1) ans = min(ans, 1); cout << ans << endl; return 0; } if (s1[1] == s3[1]) { if (abs(int(s1[0]) - int(s3[0])) == 2 || abs(int(s1[0]) - int(s3[0])) == 1) ans = min(ans, 1); cout << ans << endl; return 0; } if (s2[1] == s3[1]) { if (abs(int(s2[0]) - int(s3[0])) == 2 || abs(int(s2[0]) - int(s3[0])) == 1) ans = min(ans, 1); cout << ans << endl; return 0; } cout << ans << 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
#include <bits/stdc++.h> const long long INF = (1LL << 60) - 1; using namespace std; long long power(long long x, long long y) { long long res = 1; x = x % 1000000007; while (y > 0) { if (y & 1) res = (res * x) % 1000000007; y = y >> 1; x = (x * x) % 1000000007; } return res; } long long BINARY_SEARCH(long long dp[], long long n, long long key) { long long s = 1; long long e = n; while (s <= e) { long long mid = (s + e) / 2; if (dp[mid] == key) return mid; else if (dp[mid] > key) e = mid - 1; else s = mid + 1; } return -1; } string CONVERT_TO_BINARY(long long s) { string res = ""; while (s != 0) { res += (char)('0' + s % 2); s /= 2; } reverse(res.begin(), res.end()); return res; } bool PALIN(string s) { long long i = 0; long long j = s.length() - 1; while (i <= j) { if (s[i] != s[j]) return false; j--, i++; } return true; } long long STOI(string s) { long long num = 0; long long po = 1; for (long long i = s.length() - 1; i >= 0; i--) { num += po * (s[i] - '0'); po *= 10; } return num; } long long modInverse(long long a, long long m) { return power(a, m - 2); } int findLongestSub(string bin) { int n = bin.length(), i; int sum = 0; unordered_map<int, int> prevSum; int maxlen = 0; int currlen; for (i = 0; i < n; i++) { if (bin[i] == '1') sum++; else sum--; if (sum > 0) { maxlen = i + 1; } else if (sum <= 0) { if (prevSum.find(sum - 1) != prevSum.end()) { currlen = i - prevSum[sum - 1]; maxlen = max(maxlen, currlen); } } if (prevSum.find(sum) == prevSum.end()) prevSum[sum] = i; } return maxlen; } vector<long long> prefix_KMP(string &s) { vector<long long> pi; pi[0] = 0; for (long long i = 1; i <= s.length() - 1; i++) { long long j = pi[i - 1]; while (j > 0 && s[i] != s[j]) { j = pi[j - 1]; } if (s[i] == s[j]) { j++; } pi[i] = j; } return pi; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); string s[3]; vector<pair<long long, char>> v; map<char, vector<long long>> vis; for (long long i = 0; i < 3; i++) { cin >> s[i]; vis[s[i][1]].push_back(s[i][0] - '0'); v.push_back({s[i][0] - '0', s[i][1]}); } long long ans = INT_MAX; for (auto i : vis) { map<long long, long long> cnt; for (auto j : i.second) { cnt[j]++; } for (auto j : cnt) { ans = min(3 - j.second, ans); } if (ans == 0) { cout << ans; return 0; } long long prev = -1; long long chk = 0; for (auto j : cnt) { if (prev != -1) { if (j.first - 1 == prev) { chk++; } } prev = j.first; } ans = min(2 - chk, ans); if (ans == 0) { cout << ans; return 0; } prev = -1; chk = 0; for (auto j : cnt) { if (prev != -1) { if (j.first - 2 == prev) { chk++; cout << 1; return 0; } } prev = j.first; } ans = min(2 - chk, ans); } cout << ans; }
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
tiles = [tile for tile in input().split()] tiles = sorted(tiles) num0 = int(tiles[0][0]) suit0 = tiles[0][1] num1 = int(tiles[1][0]) suit1 = tiles[1][1] num2 = int(tiles[2][0]) suit2 = tiles[2][1] if suit0 == suit1 == suit2: if num0 == num1 == num2 or (abs(num0 - num1) == 1 and abs(num1 - num2) == 1 and abs(num0 - num2) == 2): print(0) elif abs(num0 - num1) > 2 and abs(num1 - num2) > 2 and abs(num0 - num2) > 2: print(2) else: print(1) elif suit1 == suit2: if num1 == num2: print(1) elif abs(num1 - num2) > 2: print(2) else: print(1) elif suit1 == suit0: if num1 == num0: print(1) elif abs(num1 - num0) > 2: print(2) else: print(1) elif suit2 == suit0: if num0 == num2: print(1) elif abs(num0 - num2) > 2: print(2) else: 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 main() { ios_base::sync_with_stdio(false); map<string, int> mp; string s1, s2, s3; cin >> s1 >> s2 >> s3; mp[s1]++; mp[s2]++; mp[s3]++; int ans = 3; for (char c = '1'; c <= '9'; c++) { string x; x += c; string a = x + 'm'; ans = min(ans, 3 - mp[a]); a = x + 'p'; ans = min(ans, 3 - mp[a]); a = x + 's'; ans = min(ans, 3 - mp[a]); } for (int i = 1; i <= 7; i++) { string c; c = i + '0'; int qn = 0; string s = c + 'p'; qn += (mp[s] != 0); c = (i + 1) + '0'; s = c + 'p'; qn += (mp[s] != 0); c = (i + 2) + '0'; s = c + 'p'; qn += (mp[s] != 0); ans = min(ans, 3 - qn); c = i + '0'; qn = 0; s = c + 'm'; qn += (mp[s] != 0); c = (i + 1) + '0'; s = c + 'm'; qn += (mp[s] != 0); c = (i + 2) + '0'; s = c + 'm'; qn += (mp[s] != 0); ans = min(ans, 3 - qn); c = i + '0'; qn = 0; s = c + 's'; qn += (mp[s] != 0); c = (i + 1) + '0'; s = c + 's'; qn += (mp[s] != 0); c = (i + 2) + '0'; s = c + 's'; qn += (mp[s] != 0); ans = min(ans, 3 - qn); } cout << ans << 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
M = 10**9 + 7 R = lambda: map(int, input().split()) L = [[0 for j in range(9)] for i in range(3)] #print(L) a = input().split() def f(p): if p[1] == 'm': L[0][int(p[0])-1] += 1 elif p[1] == 'p': L[1][int(p[0])-1] += 1 elif p[1] == 's': L[2][int(p[0])-1] += 1 for i in range(3): f(a[i]) p = sum(L[0]) q = sum(L[1]) r = sum(L[2]) m = max([p,q,r]) #print(L) '''if m == 1: print(2) elif m == 2: for i in range(3): for j in range(8): if L[i][j] == 1 and L[i][j+1] == 1: print(1) quit() print(2) elif m == 3:''' if len(set(a)) == 1: print(0) quit() elif len(set(a)) == 2: print(1) quit() k = 0 for i in range(3): for j in range(7): k = max(k,L[i][j]+L[i][j+1]+L[i][j+2]) k = max(k,L[i][7]+L[i][8]) if k == 3: print(0) elif k == 2: print(1) elif k == 1: print(2)
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, …, 9m, 1p, 2p, …, 9p, 1s, 2s, …, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] β€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] β€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings β€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer β€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
def mode(List): counter = 0 num = List[0] for i in List: curr_frequency = List.count(i) if (curr_frequency > counter): counter = curr_frequency num = i return num a,b,c = map(str, input().split()) a=list(a) b=list(b) c=list(c) numbers=[int(a[0]),int(b[0]),int(c[0])] letters=[a[1],b[1],c[1]] m = letters.count(mode(letters)) commonLetter = mode(letters) n = numbers.count(mode(numbers)) if m == 2: l=[] for i in range(3): if letters[i] == commonLetter: l.append(numbers[i]) l.sort() if l[1]-l[0]<3: print(1) else: print(2) elif m == 3: if n == 3: print(0) elif n == 2: print(1) else: numbers.sort() ans=2 if numbers[0] + 1 == numbers[1]: ans-=1 if numbers[1] + 1 == numbers[2]: ans-=1 if numbers[1] - numbers[0] == 2: ans = 1 if numbers[2] - numbers[1] == 2: ans = 1 print(ans) 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
o=input().split() if o[0]==o[1]==o[2]: print(0) exit() pch=int(o[0][0]) vch=int(o[1][0]) tch=int(o[2][0]) l=[pch,vch,tch] l.sort() if l[0]+2==l[1]+1==l[2] and o[0][1]==o[1][1]==o[2][1]: print(0) exit() if o[0]==o[1] or o[0]==o[2] or o[1]==o[2]: print(1) exit() if pch+1==vch and o[0][1]==o[1][1]: print(1) exit() if pch+2==vch and o[0][1]==o[1][1]: print(1) exit() if pch+1==tch and o[0][1]==o[2][1]: print(1) exit() if pch+2==tch and o[0][1]==o[2][1]: print(1) exit() if vch+1==tch and o[1][1]==o[2][1]: print(1) exit() if vch+2==tch and o[1][1]==o[2][1]: print(1) exit() if pch==vch+1 and o[0][1]==o[1][1]: print(1) exit() if pch==vch+2 and o[0][1]==o[1][1]: print(1) exit() if pch==tch+1 and o[0][1]==o[2][1]: print(1) exit() if pch==tch+2 and o[0][1]==o[2][1]: print(1) exit() if vch==tch+1 and o[1][1]==o[2][1]: print(1) exit() if vch==tch+2 and o[1][1]==o[2][1]: 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
s = list(input().split()) M=[] P=[] S=[] for i in s: if i[1]=='m': M.append(int(i[0])) elif i[1]=='s': S.append(int(i[0])) elif i[1]=='p': P.append(int(i[0])) x = True for i in [M, P, S]: if len(i)==3: i.sort() if (i[0]==i[1] and i[1]==i[2]) or (i[0]+1 ==i[1] and i[1]+1==i[2]): x = False print(0) if x: for i in [M, P, S]: if len(i)==3: i.sort() if( i[0]==i[1] or i[1]==i[2]) or (i[0]+1 == i[1] or i[1]+1==i[2]) or i[0]+2==i[1]or i[1]+2 == i[2]: x = False print(1) elif len(i) ==2: i.sort() if i[0]+1 == i[1] or i[0]==i[1] or i[0]+2==i[1]: x=False print(1) if x: 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 Problems { public static void main(String [] args) { Scanner in = new Scanner(System.in); String a = in.next(); String b = in.next(); String c = in.next(); int a1 = Integer.parseInt(a.substring(0,1)); a1 = a1 * 100 + a.charAt(1)-'a'; int b1 = Integer.parseInt(b.substring(0,1)); b1 = b1 * 100 + b.charAt(1)-'a'; int c1 = Integer.parseInt(c.substring(0,1)); c1 = c1 * 100 + c.charAt(1) - 'a'; problemB(a1,b1,c1); } public static void problemB(int a, int b, int c){ int arr [] = {a,b,c}; Arrays.sort(arr); a = arr[0]; b = arr[1]; c = arr[2]; int seqF = 0; int first=0,second=0; int keyNum = 0; if(b/100 - a/100 == 1 && c/100 - a/100 == 2 ) seqF = 2; else if(b/100 - a/100 == 1 || c/100 - a/100 == 2 || c/100 - b/100 == 1 || b/100 - a/100 == 2 || c/100 - b/100 == 2 || c/100 - a/100 == 1 || c/100 - b/100 == 0 || c/100 - a/100 == 0 || b/100 - a/100 ==0) seqF = 1; int sumChar = a%100 + b%100 + c%100; if(a==b && b==c){ System.out.println("0"); return ; } else if(sumChar == 36 || (sumChar == 45 && c%100 ==15 && b%100 == 15 ) || sumChar == 54){ if(seqF == 2){ System.out.println("0"); return ; } if(seqF == 1){ System.out.println("1"); return ; } System.out.println("2"); return ; } else if (sumChar == 45) { System.out.println("2"); return ; } if(sumChar == 42) { keyNum = 12; for(int g:arr){ if(g%100 == 15) keyNum = 15; } } if(sumChar == 48) { keyNum = 18; for(int g:arr){ if(g%100 == 15) keyNum = 15; } } if(sumChar == 39) { keyNum=12; } if(sumChar == 51) { keyNum=18; } for(int i=0; i<3; i++){ if(arr[i]%100 == keyNum){ first =arr[i]/100; break; } } for(int i=2; i>=0; i--){ if(arr[i]%100 == keyNum) { second =arr[i]/100; break; } } if(second - first == 1 || second - first == 2 || second == first) System.out.println("1"); else System.out.println("2"); return; } }
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 s; pair<int, char> arr[3]; cin >> s; arr[0].first = s[0] - '0'; arr[0].second = s[1]; cin >> s; arr[1].first = s[0] - '0'; arr[1].second = s[1]; cin >> s; arr[2].first = s[0] - '0'; arr[2].second = s[1]; if (arr[0].first == arr[1].first && arr[1].first == arr[2].first && arr[0].second == arr[1].second && arr[1].second == arr[2].second) { cout << 0; return 0; } sort(arr, arr + 3); if (arr[0].second == arr[1].second && arr[1].second == arr[2].second && arr[0].first + 1 == arr[1].first && arr[1].first + 1 == arr[2].first) { cout << 0; return 0; } if (arr[0].second == arr[1].second) { if (arr[1].first - arr[0].first <= 2) { cout << 1; return 0; } } if (arr[0].second == arr[2].second) { if (arr[2].first - arr[0].first <= 2) { cout << 1; return 0; } } if (arr[2].second == arr[1].second) { if (arr[2].first - arr[1].first <= 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
l = list(input().split()) l.sort() a,b = zip(*l) a = list(map(int,a)) # print(a,b) x,y,z = len(set(a)),len(set(b)),len(set(l)) # print(y,a,x,b,a[1]-a[0],a[2]-a[1]) if(x==1 and y==1): print(0) elif(y==1 and (a[1]-a[0])==(a[2]-a[1])==1): print(0) elif((a[1]-a[0]<=2 and b[0]==b[1]) or (a[2]-a[1]<=2 and b[1]==b[2]) or (a[2]-a[0]<=2 and b[0]==b[2]) or z==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
# so basically what we want to do is get some ice, then we get salt and we salt # the ice. it becomes salty ice, on top of which you add lovely flavors like # vanilla and chocolate sauce to add to the taste. from that point, you got some # of that great ice cream. but suppose you want toppings; what about sprinkles # or bits of fruit such as strawberry mixed in? i got you. add them. once you do, # you got a great ice cream to throw on your friends' faces so they hate you # forever. yay. # men, cow, shun, man, pin, shoe ... what even is this problem? tup = lambda s: (int(s[0]), s[1]) mlist = [] plist = [] slist = [] ilist = input().split() # this is the point when you realize you have no friends. :( for i in ilist: if i[1] == "m": mlist.append(int(i[0])) if i[1] == "p": plist.append(int(i[0])) if i[1] == "s": slist.append(int(i[0])) mlist.sort() plist.sort() slist.sort() mdiff = [] pdiff = [] sdiff = [] for i in range(len(mlist) - 1): mdiff.append(mlist[i+1] - mlist[i]) for i in range(len(plist) - 1): pdiff.append(plist[i+1] - plist[i]) for i in range(len(slist) - 1): sdiff.append(slist[i+1] - slist[i]) mi0 = False mi1 = False mi2 = False consec0 = False consec1 = False for i in range(len(mdiff)): if mdiff[i] == 0: if (not isinstance(mi0, bool)) & (mi0 == i-1): consec0 = True break mi0 = i if mdiff[i] == 1: if (not isinstance(mi1, bool)) & (mi1 == i-1): consec1 = True break mi1 = i if mdiff[i] == 2: mi2 = i pi0 = False pi1 = False pi2 = False for i in range(len(pdiff)): if pdiff[i] == 0: if (not isinstance(pi0, bool)) & (pi0 == i-1): consec0 = True break pi0 = i if pdiff[i] == 1: if (not isinstance(pi1, bool)) & (pi1 == i-1): consec1 = True break pi1 = i if pdiff[i] == 2: pi2 = i si0 = False si1 = False si2 = False for i in range(len(sdiff)): if sdiff[i] == 0: if (not isinstance(si0, bool)) & (si0 == i-1): consec0 = True break si0 = i if sdiff[i] == 1: if (not isinstance(si1, bool)) & (si1 == i-1): consec1 = True break si1 = i if sdiff[i] == 2: si2 = i if consec0: print(0) elif not isinstance(mi0, bool): print(1) elif not isinstance(pi0, bool): print(1) elif not isinstance(si0, bool): print(1) elif consec1: print(0) elif not isinstance(mi1, bool): print(1) elif not isinstance(pi1, bool): print(1) elif not isinstance(si1, bool): print(1) elif not isinstance(mi2, bool): print(1) elif not isinstance(pi2, bool): print(1) elif not isinstance(si2, bool): 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 = raw_input().split() s.sort() dic = {} for i in s: if i[1] in dic: dic[i[1]].append(int(i[0])) else: dic[i[1]] = [int(i[0])] ans = 3 for i in dic: if len(dic[i]) == 3: if len(set(dic[i])) == 1: ans = min(ans, 0) elif len(set(dic[i])) == 3 and dic[i][0] + 1 == dic[i][1] and dic[i][1] + 1 == dic[i][2]: ans = min(ans, 0) elif len(set(dic[i])) == 2: ans = min(ans, 1) elif len(set(dic[i])) == 3 and (dic[i][1] in [dic[i][0], dic[i][0] + 1, dic[i][0] + 2]) or (dic[i][2] in [dic[i][1], dic[i][1] + 1, dic[i][1] + 2]): ans = min(ans, 1) else: ans = min(ans, 2) elif len(dic[i]) == 2: if len(set(dic[i])) == 1: ans = min(ans, 1) elif len(set(dic[i])) == 2 and (dic[i][1] in [dic[i][0], dic[i][0] + 1, dic[i][0] + 2]): ans = min(ans, 1) else: ans = min(ans, 2) else: ans = min(ans, 2) 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
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; import java.util.StringTokenizer; public class Main { // A B C D 1 3 2 0 static int x; static ArrayList<Integer> m = new ArrayList<Integer>(); static ArrayList<Integer> s = new ArrayList<Integer>(); static ArrayList<Integer> p = new ArrayList<Integer>(); static int func(ArrayList<Integer> list) { int size = list.size(); if(size==3) { if(list.get(0)==list.get(1) && list.get(1)==list.get(2)) return 0; else if(list.get(0)+list.get(2)==2*list.get(1) && Math.abs(list.get(0)-list.get(1))==1) return 0; else if(list.get(0)==list.get(1) || list.get(1)==list.get(2)) return 1; else if(Math.abs(list.get(0)-list.get(1))==1 || Math.abs(list.get(0)-list.get(1))==2) return 1; else if(Math.abs(list.get(2)-list.get(1))==1 || Math.abs(list.get(2)-list.get(1))==2) return 1; else return 2; }else if(size==2) { if(list.get(0)==list.get(1)) return 1; else if(Math.abs(list.get(0)-list.get(1))==1 || Math.abs(list.get(0)-list.get(1))==2) return 1; else return 2; }else if(size==1) { return 2; } return 3; } public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); for (int i = 0; i < 3; i++) { char[] tmp = st.nextToken().toCharArray(); switch (tmp[1]) { case 'm': m.add(tmp[0]-'0'); break; case 's': s.add(tmp[0]-'0'); break; case 'p': p.add(tmp[0]-'0'); break; } } Collections.sort(m); Collections.sort(s); Collections.sort(p); int ans = 3; ans = Math.min(ans, func(m)); ans = Math.min(ans, func(s)); ans = Math.min(ans, func(p)); System.out.println(ans); br.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 javafx.util.Pair; import java.io.*; import java.math.*; import java.security.Key; import java.util.*; @SuppressWarnings("Duplicates") // author @mdazmat9 // swing +socket java(udemy) public class codeforces{ static Scanner sc = new Scanner(System.in); static PrintWriter out = new PrintWriter(System.out); public static void main(String[] args) throws IOException { int test = 1; // test=sc.nextInt(); for (int ind = 0; ind < test; ind++) { String a=sc.next(); String b=sc.next(); String c=sc.next(); HashSet<Character> set=new HashSet<>(); set.add(a.charAt(1));set.add(b.charAt(1));set.add(c.charAt(1)); if(a.equals(b) && b.equals(c)){ out.println(0); } else if(a.equals(b) || b.equals(c) || c.equals(a)) { out.println(1); } else if(set.size()==3){ out.println(2); } else { HashSet<String> stet=new HashSet<>();stet.add(a);stet.add(b);stet.add(c); int ans=2; int temp=2; String first=a; String first_inc=(Integer.parseInt(a.charAt(0)+"")+1)+""+a.charAt(1); if(stet.contains(first_inc))temp--; String first_inc_inc=(Integer.parseInt(a.charAt(0)+"")+2)+""+a.charAt(1); if(stet.contains(first_inc_inc))temp--; ans=Math.min(ans,temp); temp=2; first=b; first_inc=(Integer.parseInt(b.charAt(0)+"")+1)+""+b.charAt(1); if(stet.contains(first_inc))temp--; first_inc_inc=(Integer.parseInt(b.charAt(0)+"")+2)+""+b.charAt(1); if(stet.contains(first_inc_inc))temp--; ans=Math.min(ans,temp); temp=2; first=c; first_inc=(Integer.parseInt(c.charAt(0)+"")+1)+""+c.charAt(1); if(stet.contains(first_inc))temp--; first_inc_inc=(Integer.parseInt(c.charAt(0)+"")+2)+""+c.charAt(1); if(stet.contains(first_inc_inc))temp--; ans=Math.min(ans,temp); out.println(ans); } } out.flush(); } static long[] longarray(int n){ long [] a=new long[n];for(int i=0;i<n;i++)a[i]=sc.nextLong();return a; } static int[] intarray(int n){ int [] a=new int[n];for(int i=0;i<n;i++)a[i]=sc.nextInt();return a; } static ArrayList<Integer> intlist(int n){ArrayList<Integer> list=new ArrayList<>();for(int i=0;i<n;i++)list.add(sc.nextInt());return list; } static ArrayList<Long> longlist(int n){ArrayList<Long> list=new ArrayList<>();for(int i=0;i<n;i++)list.add(sc.nextLong());return list; } static int[][] read2darray(int n,int m){ int [][] a=new int[n][m];for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ a[i][j]=sc.nextInt(); } }return a; } public static double logb( double a, double b ) {return Math.log(a) / Math.log(b); } static long fast_pow(long a, long b,long abs) { if(b == 0) return 1L; long val = fast_pow(a, b / 2,abs); if(b % 2 == 0) return val * val % abs; else return val * val % abs * a % abs; } static long abs = (long)1e9 + 7; static void shuffle(int[] a) { int n = a.length;for(int i = 0; i < n; i++) { int r = i + (int) (Math.random() * (n - i));int tmp = a[i];a[i] = a[r];a[r] = tmp; } } static long gcd(long a , long b) { if(b == 0) return a; return gcd(b , a % b); } } class Scanner { public BufferedReader reader; public StringTokenizer st; public Scanner(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream)); st = null; } public String next() { while (st == null || !st.hasMoreTokens()) { try { String line = reader.readLine(); if (line == null) return null; st = new StringTokenizer(line); } catch (Exception e) { throw (new RuntimeException()); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } } class OutputWriter { BufferedWriter writer; public OutputWriter(OutputStream stream) { writer = new BufferedWriter(new OutputStreamWriter(stream)); } public void print(int i) throws IOException { writer.write(i); } public void print(String s) throws IOException { writer.write(s); } public void print(char[] c) throws IOException { writer.write(c); } public void close() throws IOException { writer.close(); } }
JAVA
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, …, 9m, 1p, 2p, …, 9p, 1s, 2s, …, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] β€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] β€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings β€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer β€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
s=input().split(" ") s1=[] p1=[] m1=[] for i in s: if i[1]=="m": m1.append(int(i[0])) elif i[1]=="p": p1.append(int(i[0])) else: s1.append(int(i[0])) s1=sorted(s1) p1=sorted(p1) m1=sorted(m1) if len(m1)==len(s1)==len(p1)==1: print(2) else: if len(m1)>=2: if len(m1)>2 and (abs(m1[0]-m1[1])<=1 or abs(m1[1]-m1[2])<=1): if abs(m1[0]-m1[1])==abs(m1[2]-m1[1]): print(0) else: print(1) elif abs(m1[0]-m1[1])<=1 and len(m1)==2: print(1) elif abs(m1[0]-m1[1])==2: print(1) else: print(2) elif len(s1)>=2: if len(s1)>2 and (abs(s1[0]-s1[1])<=1 or abs(s1[1]-s1[2])<=1): if abs(s1[0]-s1[1])==abs(s1[2]-s1[1]): print(0) else: print(1) elif abs(s1[0]-s1[1])<=1 and len(s1)==2: print(1) elif abs(s1[0]-s1[1])==2: print(1) else: print(2) else: if len(p1)>2 and (abs(p1[0]-p1[1])<=1 or abs(p1[1]-p1[2])<=1): if abs(p1[0]-p1[1])==abs(p1[2]-p1[1]): print(0) else: print(1) elif abs(p1[0]-p1[1])<=1 and len(p1)==2: print(1) elif abs(p1[0]-p1[1])==2: print(1) else: print(2)
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, …, 9m, 1p, 2p, …, 9p, 1s, 2s, …, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] β€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] β€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings β€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer β€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
import sys def f(a, b): r = a[0] == b[0] and a[1] + 1 == b[1] #print "{} == {} and {} + 1 == {}, {}".format(a[0], b[0], a[1], b[1], r) return r def check(a): if len(set(a)) == 1: return True b = a r = f(b[0], b[1]) and f(b[1], b[2]) return r t = 1 if len(sys.argv) > 1: t = int(raw_input()) for _ in xrange(t): a = map(list, raw_input().split()) a = map(lambda x: (x[1], int(x[0])), a) a.sort() #print "checking {}".format(a) if check(a): print 0 continue is_one = False for i in "pms": for j in xrange(1, 10): b = sorted(a + [(i, j)]) is_one = check(b[:-1]) or check(b[1:]) if is_one: break if is_one: break if is_one: print 1 continue 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
suit=list(map(str,input().split())) suit=sorted(suit) num=[int(suit[0][0]),int(suit[1][0]),int(suit[2][0])] if suit[0]==suit[1] and suit[0]==suit[2]: print(0) elif suit[0]==suit[1] or suit[1]==suit[2]: print(1) elif suit[0][1]==suit[1][1] and suit[0][1]==suit[2][1]: if num[0]==num[1]-1 and num[0]==num[2]-2: print(0) elif num[2]-num[1]<=2 or num[1]-num[0]<=2: print(1) else: print(2) elif suit[0][1] == suit[1][1]: if num[1]-num[0]<=2: print(1) else: print(2) elif suit[0][1] == suit[2][1]: if num[2]-num[0]<=2: print(1) else: print(2) elif suit[2][1] == suit[1][1]: if num[2]-num[1]<=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=sorted(input().split()) r=len({*a})-1 a=sorted(a,key=lambda x:(x[1],x[0])) v,s=[*zip(*a)] c=1 for i in range(1,3): if s[i]==s[i-1] and int(v[i-1])+1==int(v[i]): c+=1 r=min(r,3-c) elif s[i]==s[i-1] and int(v[i-1])+2==int(v[i]): r=min(r,1) else:c=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
hand = input().split() # Analyse hand m, p, s = 9 * [False], 9 * [False], 9 * [False] for h in hand: if h[1] == 'm': m[int(h[0]) - 1] = True if h[1] == 'p': p[int(h[0]) - 1] = True if h[1] == 's': s[int(h[0]) - 1] = True # Win in zero, by koutsu if hand[0] == hand[1] and hand[0] == hand[2]: print(0) quit() # Win in zero, by shuntsu for i in range(9): if i > 0 and i + 1 < 9: if m[i - 1] and m[i] and m[i + 1]: print(0) quit() if p[i - 1] and p[i] and p[i + 1]: print(0) quit() if s[i - 1] and s[i] and s[i + 1]: print(0) quit() # Win in one, by koutsu if hand[0] == hand[1] or hand[0] == hand[2] or hand[1] == hand[2]: print(1) quit() # Win in one, by shuntsu for i in range(1,8): cnt = 0 cnt += 1 if m[i - 1] else 0 cnt += 1 if m[i + 0] else 0 cnt += 1 if m[i + 1] else 0 if cnt == 2: print(1) quit() cnt = 0 cnt += 1 if p[i - 1] else 0 cnt += 1 if p[i + 0] else 0 cnt += 1 if p[i + 1] else 0 if cnt == 2: print(1) quit() cnt = 0 cnt += 1 if s[i - 1] else 0 cnt += 1 if s[i + 0] else 0 cnt += 1 if s[i + 1] else 0 if cnt == 2: print(1) quit() # Win in two print(2) quit()
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 = [i for i in input().split()] m_dict = {'m':[],'p':[],'s':[]} for word in a: m_dict[word[1]].append(int(word[0])) val = 2 for i in ['m','p','s']: temp = m_dict[i] if len(temp)==2: if temp[0] == temp[1] or abs(temp[0]-temp[1])<=2: val = 1 break if len(temp) == 3: temp = sorted(temp) if temp[0] == temp[1] and temp[1] == temp[2]: val = 0 break elif temp[1] == temp[0] + 1 and temp[2] == temp[1] + 1: val = 0 break elif temp[1] == temp[0] or temp[1] == temp[2]: val = 1 break elif temp[1] - temp[0] <= 2 or temp[2] - temp[1] <= 2: val = 1 break print(val)
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
ans=2 x=input().split() for i in ["m","s","p"]: c=[int(j[0]) for j in x if j[1]==i] c.sort() if len(c)<2: continue if len(c)==3: if c[0]==c[1] and c[1]==c[2]: ans=0 break if c[0]+1==c[1] and c[1]+1==c[2]: ans=0 break if c[0]==c[1] or c[0]+1==c[1] or c[0]+2==c[1]: ans=1 continue if c[1]==c[2] or c[1]+1==c[2] or c[1]+2==c[2]: ans=1 continue if c[0]==c[1] or c[0]+1==c[1] or c[0]+2==c[1]: 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
#include <bits/stdc++.h> using namespace std; long long modInverse(long long a, long long m); long long gcd(long long a, long long b); long long power(long long x, unsigned long long y, unsigned long long m); long long logint(long long x, long long y); long long gcd(long long a, long long b) { if (a == 0) return b; return gcd(b % a, a); } long long power(long long x, unsigned long long y, unsigned long long m) { if (y == 0) return 1; long long p = power(x, y / 2, m) % m; p = (p * p) % m; return (y % 2 == 0) ? p : (x * p) % m; } long long modInverse(long long a, long long m) { long long m0 = m; long long y = 0, x = 1; if (m == 1) return 0; while (a > 1) { long long q = a / m; long long t = m; m = a % m, a = t; t = y; y = x - q * y; x = t; } if (x < 0) x += m0; return x; } void pairsort(long long a[], long long b[], long long n) { pair<long long, long long> pairt[n]; for (long long i = 0; i < n; i++) { pairt[i].first = a[i]; pairt[i].second = b[i]; } sort(pairt, pairt + n); for (long long i = 0; i < n; i++) { a[i] = pairt[i].first; b[i] = pairt[i].second; } } long long logint(long long x, long long y) { long long ans = 0; long long a = 1; for (long long i = 0; i < x; i++) { if (x <= a) { return ans; } ans++; a *= y; } return -1; } const int MAX = 1e4 + 5; long long ar[150001]; vector<long long> ans[150001]; long long fin(long long x) { if (x == ar[x]) { return x; } return ar[x] = fin(ar[x]); } void uni(long long x, long long y) { x = fin(x); y = fin(y); if (ans[x].size() > ans[y].size()) { for (long long i = 0; i < ans[y].size(); i++) { ans[x].push_back(ans[y][i]); ar[ans[y][i]] = x; } } else { for (long long i = 0; i < ans[x].size(); i++) { ans[y].push_back(ans[x][i]); ar[ans[x][i]] = y; } } } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); string ar[3]; for (long long i = 0; i < 3; i++) { cin >> ar[i]; } sort(ar, ar + 3); long long k = ar[0][0] - '0'; long long l = ar[1][0] - '0'; long long m = ar[2][0] - '0'; if (ar[0][1] == ar[1][1] && ar[0][1] == ar[2][1]) { if (l - k == 1 && m - l == 1) { cout << '0'; } else if (l == k && l == m) { cout << '0'; } else { if (min(m - l, l - k) <= 2) { cout << '1'; } else { cout << '2'; } } } else if (ar[0][1] == ar[1][1]) { if (l - k <= 2) { cout << '1'; } else { cout << '2'; } } else if (ar[0][1] == ar[2][1]) { if (m - k <= 2) { cout << '1'; } else { cout << '2'; } } else if (ar[1][1] == ar[2][1]) { if (m - l <= 2) { cout << '1'; } else { cout << '2'; } } else { cout << '2'; } }
CPP
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, …, 9m, 1p, 2p, …, 9p, 1s, 2s, …, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] β€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] β€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings β€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer β€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
p = input().split() p = set(p) ans = 2 lol = [0] * 3 for i1 in p: for i2 in p: if i1[1] == i2[1] and 1 <= int(i1[0]) - int(i2[0]) <= 2: if int(i1[0]) - int(i2[0]) == 1: lol[1] += 1 else: lol[2] = 1 ans -= max(lol) ans = min(ans, len(p) - 1) print(max(0, 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.util.Scanner; public class TaskB { public static void main(String[] args) { Scanner s = new Scanner(System.in); int[][] cards = new int[3][9]; for(int i=0;i<3;i++) { char[] c = s.next().toCharArray(); int a = Character.getNumericValue(c[0]) - 1; if(c[1] == 'm') { cards[0][a]++; } else if(c[1] == 'p') { cards[1][a]++; } else { cards[2][a]++; } } //print(cards); int sh = 0; int ko = 0; for(int i=0;i<3;i++) { for(int y=0;y<9;y++) { if(cards[i][y] > sh) { sh = cards[i][y]; } } } sh = 3-sh; for(int i=0;i<3;i++) { int con = 0; int maxcon = 0; for(int x=0;x<7;x++) { con = 0; if(cards[i][x] >= 1) { con++; } if(cards[i][x+1] >= 1) { con++; } if(cards[i][x+2] >= 1) { con++; } maxcon = Math.max(con, maxcon); } ko = Math.max(ko, maxcon); } //System.out.println("ko: " + ko); ko = 3-ko; System.out.println((int) Math.min(ko, sh)); } public static void print(int[][] arr) { for(int i=0;i<arr.length;i++) { for(int k=0;k<arr[i].length;k++) { System.out.print(arr[i][k] + " "); } System.out.println(); } } }
JAVA
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, …, 9m, 1p, 2p, …, 9p, 1s, 2s, …, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] β€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] β€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings β€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer β€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
b=list(input().split()) a=b[0] c=b[1] d=b[2] p=[int(a[0]),int(c[0]),int(d[0])] p.sort() if a[1]==c[1]: if a[1]==d[1]: k=p[1]-p[0] q=p[2]-p[1] if k==0 and q==0: print(0) elif k==0 or q==0: print(1) elif k==1 and q==1: print(0) elif k==1 or q==1: print(1) elif k==2 or q==2: print(1) else: print(2) else: if int(a[0])==int(c[0]): print(1) elif abs(int(a[0])-int(c[0]))<=2: print(1) else: print(2) else: if c[1]==d[1]: if int(c[0]) == int(d[0]): print(1) elif abs(int(c[0]) - int(d[0]))<= 2: print(1) else: print(2) elif a[1]==d[1]: if int(a[0]) == int(d[0]): print(1) elif abs(int(a[0]) - int(d[0]))<= 2: print(1) else: print(2) else: print(2)
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, …, 9m, 1p, 2p, …, 9p, 1s, 2s, …, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] β€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] β€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings β€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer β€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
a = input().split() res = 2 for i in range(1, 10): for j in "smp": 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
first_list = raw_input().split() data_dic = {} for item in first_list: digit = int(item[0]) letter = item[1] if letter not in data_dic: data_dic.update({letter: [digit]}) else: data_dic[letter].append(digit) koutsu = False shuntsu = False koutsu_action = 100 shuntsu_action = 100 for j in data_dic: for i in data_dic[j]: if data_dic[j].count(i) >= 3: koutsu = True else: koutsu_action = min(koutsu_action, 3 - data_dic[j].count(i)) if i + 1 in data_dic[j] and i - 1 in data_dic[j]: shuntsu = True elif i + 1 in data_dic[j] or i - 1 in data_dic[j]: shuntsu_action = min(shuntsu_action, 1) elif i - 2 in data_dic[j] or i + 2 in data_dic[j]: shuntsu_action = min(shuntsu_action, 1) else: shuntsu_action = min(shuntsu_action, 2) if shuntsu or koutsu: print(0) else: print(min(shuntsu_action, koutsu_action))
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
import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.Scanner; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.IntStream; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String[] tiles = new String[3]; for (int i = 0; i < tiles.length; i++) { tiles[i] = sc.next(); } System.out.println(solve(tiles)); sc.close(); } static int solve(String[] tiles) { Map<String, Integer> tileToCount = new HashMap<>(); for (String tile : tiles) { tileToCount.put(tile, tileToCount.getOrDefault(tile, 0) + 1); } int result = 3 - tileToCount.values().stream().mapToInt(x -> x).max().getAsInt(); Set<String> tileSet = Arrays.stream(tiles).collect(Collectors.toSet()); for (char suit : new char[] { 'm', 'p', 's' }) { for (int digit = 1; digit <= 7; digit++) { result = Math.min(result, computeDrawNum(tileSet, suit, digit)); } } return result; } static int computeDrawNum(Set<String> tileSet, char suit, int digit) { return (int) IntStream.range(0, 3).filter(i -> !tileSet.contains(String.format("%d%c", digit + i, suit))) .count(); } }
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 R573B { public static void main(String[] args){ JS scan = new JS(); int[][] got = new int[14][3]; int[] aarrr = new int[1000]; aarrr['m'] = 0; aarrr['p'] = 1; aarrr['s'] = 2; for(int i = 0; i < 3; i++) { String s = scan.next(); int a = s.charAt(0)-'0'; int b = aarrr[s.charAt(1)]; got[a][b]++; } int ans = 3; for(int j = 0; j < 3; j++) { for(int i = 0; i < 10; i++) { int same = got[i][j]; ans = Math.min(ans, 3-same); int comb = 0; if(got[i][j] > 0) comb++; if(got[i+1][j] > 0) comb++; if(got[i+2][j] > 0) comb++; ans = Math.min(ans, 3-comb); } } System.out.println(ans); } static class JS{ public int BS = 1<<16; public char NC = (char)0; byte[] buf = new byte[BS]; int bId = 0, size = 0; char c = NC; double num = 1; BufferedInputStream in; public JS() { in = new BufferedInputStream(System.in, BS); } public JS(String s) throws FileNotFoundException { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } public char nextChar(){ while(bId==size) { try { size = in.read(buf); }catch(Exception e) { return NC; } if(size==-1)return NC; bId=0; } return (char)buf[bId++]; } public int nextInt() { return (int)nextLong(); } public long nextLong() { num=1; boolean neg = false; if(c==NC)c=nextChar(); for(;(c<'0' || c>'9'); c = nextChar()) { if(c=='-')neg=true; } long res = 0; for(; c>='0' && c <='9'; c=nextChar()) { res = (res<<3)+(res<<1)+c-'0'; num*=10; } return neg?-res:res; } public double nextDouble() { double cur = nextLong(); return c!='.' ? cur:cur+nextLong()/num; } public String next() { StringBuilder res = new StringBuilder(); while(c<=32)c=nextChar(); while(c>32) { res.append(c); c=nextChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while(c<=32)c=nextChar(); while(c!='\n') { res.append(c); c=nextChar(); } return res.toString(); } public boolean hasNext() { if(c>32)return true; while(true) { c=nextChar(); if(c==NC)return false; else if(c>32)return true; } } } }
JAVA
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, …, 9m, 1p, 2p, …, 9p, 1s, 2s, …, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] β€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] β€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings β€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer β€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
#include <bits/stdc++.h> using namespace std; template <class T> inline bool read(T &x) { int c = getchar(); int sgn = 1; while (~c && c<'0' | c> '9') { if (c == '-') sgn = -1; c = getchar(); } for (x = 0; ~c && '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0'; x *= sgn; return ~c; } const long long N = 5005; const long long MOD = 1e9 + 7; long long ara[N]; int main() { string s, s2, s3; cin >> s >> s2 >> s3; reverse(s.begin(), s.end()); reverse(s2.begin(), s2.end()); reverse(s3.begin(), s3.end()); ara[0] = s[1] - '0'; ara[1] = s2[1] - '0'; ara[2] = s3[1] - '0'; sort(ara, ara + 3); if (s == s2 && s2 == s3) return cout << 0, 0; if (s[0] == s2[0] && s[0] == s3[0]) { if (ara[1] - ara[0] == 1 && ara[2] - ara[1] == 1) return cout << 0, 0; } if (s[0] == s2[0]) { if (s == s2) return cout << 1, 0; long long x = s[1] - '0'; long long y = s2[1] - '0'; if (abs(x - y) <= 2) return cout << 1, 0; } if (s[0] == s3[0]) { if (s == s3) return cout << 1, 0; long long x = s[1] - '0'; long long y = s3[1] - '0'; if (abs(x - y) <= 2) return cout << 1, 0; } if (s2[0] == s3[0]) { if (s2 == s3) return cout << 1, 0; long long x = s2[1] - '0'; long long y = s3[1] - '0'; if (abs(x - y) <= 2) return cout << 1, 0; } cout << 2 << endl; }
CPP
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, …, 9m, 1p, 2p, …, 9p, 1s, 2s, …, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] β€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] β€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings β€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer β€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
a, b, c = input().split() a = a[::-1] b = b[::-1] c = c[::-1] a1 = int(a[1]) b1 = int(b[1]) c1 = int(c[1]) k = [a1, b1, c1] k.sort() if a == b == c: print(0) elif a == b or b == c or a == c: print(1) elif a[0] == b[0] == c[0] and k[0] == k[1] - 1 == k[2] - 2: print(0) elif (a[0] == b[0] and abs(a1 - b1) <= 2) or (a[0] == c[0] and abs(a1 - c1) <= 2) or (c[0] == b[0] and abs(c1 - b1) <= 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
def main(): nums = [] chars = [] for elm in input().split(" "): num, char = list(elm) num = int(num) nums.append(num) chars.append(char) set_char = list(set(chars)) for i, char in enumerate(set_char): tmp_count = chars.count(char) #print("tmp_count", tmp_count) if i == 0: max_i = 0 max_count = tmp_count max_char = char else: if tmp_count > max_count: max_count = tmp_count max_i = i max_char = char if max_count == 1: #print("flag", set_char) return 2 # max_count = 2 or 3 sub_nums = sorted([nums[i] for i in range(3) if chars[i] == max_char]) diff1 = sub_nums[1] - sub_nums[0] if max_count == 3: diff2 = sub_nums[2] - sub_nums[1] if (diff1 == 0 and diff2 == 0) or (diff1 == 1 and diff2 == 1): return 0 elif diff1 == 1 or diff2 == 1 or diff1 == 0 or diff2 == 0 or diff1 == 2 or diff2 == 2: return 1 else: return 2 else: if diff1 == 1 or diff1 == 0 or diff1 == 2: return 1 else: return 2 out = main() print(out)
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
inp = list(map(str, input().split())) inp.sort() slist = [] mlist = [] plist = [] ret = [] for i in inp: if i[1] == 's': slist.append(i) elif i[1] == 'm': mlist.append(i) elif i[1] == 'p': plist.append(i) if len(slist) > 0: likes = 0 sequence = 0 middle = 0 for s in range(len(slist) - 1): if int(slist[s][0]) == int(slist[s + 1][0]): likes += 1 elif int(slist[s][0]) + 1 == int(slist[s + 1][0]): sequence += 1 elif int(slist[s][0]) + 2 == int(slist[s + 1][0]): middle += 1 break ret.append(2 - likes) ret.append(2 - sequence) ret.append(2 - middle) if len(plist) > 0: likes = 0 sequence = 0 middle = 0 for p in range(len(plist) - 1): if int(plist[p][0]) == int(plist[p + 1][0]): likes += 1 elif int(plist[p][0]) + 1 == int(plist[p + 1][0]): sequence += 1 elif int(plist[p][0]) + 2 == int(plist[p + 1][0]): middle += 1 break ret.append(2 - likes) ret.append(2 - sequence) ret.append(2 - middle) if len(mlist) > 0: likes = 0 sequence = 0 middle = 0 for m in range(len(mlist) - 1): if int(mlist[m][0]) == int(mlist[m + 1][0]): likes += 1 elif int(mlist[m][0]) + 1 == int(mlist[m + 1][0]): sequence += 1 elif int(mlist[m][0]) + 2 == int(mlist[m + 1][0]): middle += 1 break ret.append(2 - likes) ret.append(2 - sequence) ret.append(2 - middle) print(min(ret))
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 a[3], i; int main() { string s; for (i = 0; i < 3; i++) { cin >> s; a[i] = (s[0] - '0') + (s[1] - 'a') * 100; } sort(a, a + 3); int t1 = a[1] - a[0]; int t2 = a[2] - a[1]; if (t1 == t2 && (t1 == 0 || t1 == 1)) cout << "0"; else if (t1 == 1 || t1 == 0 || t1 == 2 || t2 == 0 || t2 == 1 || t2 == 2) cout << "1"; else cout << "2"; }
CPP
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, …, 9m, 1p, 2p, …, 9p, 1s, 2s, …, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] β€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] β€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings β€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer β€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
import java.util.*; import java.io.*; import static java.lang.Math.*; public class Main implements Runnable { boolean multiple = false; @SuppressWarnings("Duplicates") void solve() throws Exception { String[] tiles = (new Scanner(System.in)).nextLine().split(" "); int[] s = new int[9], m = new int[9], p = new int[9]; for (String tile : tiles) { if (tile.charAt(1) == 's') s[tile.charAt(0) - '1']++; if (tile.charAt(1) == 'm') m[tile.charAt(0) - '1']++; if (tile.charAt(1) == 'p') p[tile.charAt(0) - '1']++; } // print(s); int min = 3; for (int i = 0; i < 9 - 2; i++) { int cnt = ((s[i] > 0) ? 1 : 0) + ((s[i + 1] > 0) ? 1 : 0) + ((s[i + 2] > 0) ? 1 : 0); min = min(min, 3 - cnt); cnt = ((m[i] > 0) ? 1 : 0) + ((m[i + 1] > 0) ? 1 : 0) + ((m[i + 2] > 0) ? 1 : 0); min = min(min, 3 - cnt); cnt = ((p[i] > 0) ? 1 : 0) + ((p[i + 1] > 0) ? 1 : 0) + ((p[i + 2] > 0) ? 1 : 0); min = min(min, 3 - cnt); } for (int i = 0; i < 9; i++) { min = min(min, 3 - s[i]); min = min(min, 3 - m[i]); min = min(min, 3 - p[i]); } System.out.println(max(min, 0)); } long inv(long a, long b) { return 1 < a ? b - inv(b % a, a) * b / a : 1; } long gcd(long a, long b) { return a == 0 ? b : gcd(b % a, a); } long lcm(long a, long b) { return (a * b) / gcd(a , b); } class SegNode { int max; int L, R; SegNode left = null, right = null; int query(int queryL, int queryR) { if (queryL == L && queryR == R) return max; int leftAns = Integer.MIN_VALUE, rightAns = Integer.MIN_VALUE; if (left != null && queryL <= left.R) leftAns = left.query(queryL, min(queryR, left.R)); if (right != null && queryR >= right.L) rightAns = right.query(max(queryL, right.L), queryR); return max(leftAns, rightAns); } SegNode(int[] arr, int l, int r) { L = l; R = r; max = arr[l]; if (l == r) return; int mid = (l + r) / 2; left = new SegNode(arr, l, mid); right = new SegNode(arr, mid + 1, r); max = max(left.max, right.max); } } class Node implements Comparable<Node> { Node() { } @Override public int compareTo(Node o) { return 0; } } void print(int[] arr) { for (int i = 0; i < arr.length; i++) System.out.print(arr[i] + " "); System.out.println(); } @Override public void run() { try { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); sc = new FastScanner(in); if (multiple) { int q = sc.nextInt(); for (int i = 0; i < q; i++) solve(); } else solve(); } catch (Throwable uncaught) { Main.uncaught = uncaught; } finally { out.close(); } } public static void main(String[] args) throws Throwable { Thread thread = new Thread(null, new Main(), "", (1 << 26)); thread.start(); thread.join(); if (Main.uncaught != null) { throw Main.uncaught; } } static Throwable uncaught; BufferedReader in; FastScanner sc; PrintWriter out; } class FastScanner { BufferedReader in; StringTokenizer st; public FastScanner(BufferedReader in) { this.in = in; } public String nextToken() throws Exception { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(in.readLine()); } return st.nextToken(); } public int nextInt() throws Exception { return Integer.parseInt(nextToken()); } public long nextLong() throws Exception { return Long.parseLong(nextToken()); } public double nextDouble() throws Exception { return Double.parseDouble(nextToken()); } }
JAVA
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, …, 9m, 1p, 2p, …, 9p, 1s, 2s, …, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] β€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] β€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings β€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer β€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
a, b, c = input().split() numbers = [int(a[0]), int(b[0]), int(c[0])] letters = [a[1], b[1], c[1]] if (a == b == c): print(0) else: order = sorted(numbers) flag = 0 for i in range(2): diff = order[i + 1] - order[i] if (diff != 1): flag = 1 break if(flag == 0 and letters[0] == letters[1] == letters[2]): print(0) else: #print(letters) p = letters.count("p") m = letters.count("m") s = letters.count("s") #print(m, p, s) if(a == b or b == c or a == c):#2 similar print(1) elif(p == 1 and m == 1 and s == 1): print(2) else: if (m == 3 or p == 3 or s == 3): order = sorted(numbers) diff = [] for i in range(2): diff.append(order[i + 1] - order[i]) if(1 in diff or 2 in diff): print(1) else: print(2) else: #1, 2 if (letters[0] == letters[1]): twos = [numbers[0], numbers[1]] elif(letters[0] == letters[2]): twos = [numbers[0], numbers[2]] else: twos = [numbers[1], numbers[2]] if (abs(twos[1] - twos[0]) == 1 or abs(twos[1] - twos[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 java.util.Arrays; import java.util.Scanner; public class Code1 { public static void main(String[] args) { Scanner scanner=new Scanner(System.in); String a,b,c; int a1[]=new int[3];int t=0; a=scanner.next(); b=scanner.next();c=scanner.next();scanner.close(); a1[0]=a.charAt(0)-'0';a1[1]=b.charAt(0)-'0';a1[2]=c.charAt(0)-'0'; Arrays.sort(a1); if(a1[1]-a1[0]==1 && a1[2]-a1[1]==1)t=1; if(a.equals(b) && a.equals(c)){System.out.println("0");System.exit(0);;} if((a.charAt(1)==b.charAt(1) && b.charAt(1)==c.charAt(1)) && (t==1)){System.out.println("0");System.exit(0);;} if(a.equals(b) || (a.charAt(1)==b.charAt(1) && Math.abs(a.charAt(0)-b.charAt(0))<=2)){System.out.println("1");System.exit(0);;} else if(b.equals(c)|| (c.charAt(1)==b.charAt(1) && Math.abs(c.charAt(0)-b.charAt(0))<=2)){System.out.println("1");System.exit(0);;} else if(a.equals(c) || (a.charAt(1)==c.charAt(1) && Math.abs(a.charAt(0)-c.charAt(0))<=2)){System.out.println("1");System.exit(0);;} 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
tiles = input().split() s = [] m = [] p = [] for i in tiles: if i[1] == 's': s.append(int(i[0])) elif i[1] == 'p': p.append(int(i[0])) else: m.append(int(i[0])) s.sort() m.sort() p.sort() num_s = len(s) num_p = len(p) num_m = len(m) if num_s == 3: if len(set(s)) == 1: print(0) elif len(set(s)) == 2: print(1) else: if s[0] == s[1] - 1: if s[1] == s[2] - 1: print(0) else: print(1) elif s[0] < s[1] - 2: if s[1] == s[2] - 1 or s[1] == s[2] - 2: print(1) else: print(2) else: print(1) elif num_m == 3: if len(set(m)) == 1: print(0) elif len(set(m)) == 2: print(1) else: if m[0] == m[1] - 1: if m[1] == m[2] - 1: print(0) else: print(1) elif m[0] < m[1] - 2: if m[1] == m[2] - 1 or m[1] == m[2] - 2: print(1) else: print(2) else: print(1) elif num_p == 3: if len(set(p)) == 1: print(0) elif len(set(p)) == 2: print(1) else: if p[0] == p[1] - 1: if p[1] == p[2] - 1: print(0) else: print(1) elif p[0] < p[1] - 2: if p[1] == p[2] - 1 or p[1] == p[2] - 2: print(1) else: print(2) else: print(1) elif num_s == 2: if len(set(s)) == 1: print(1) else: if s[0] == s[1] - 1 or s[0] == s[1] - 2: print(1) else: print(2) elif num_m == 2: if len(set(m)) == 1: print(1) else: if m[0] == m[1] - 1 or m[0] == m[1] - 2: print(1) else: print(2) elif num_p == 2: if len(set(p)) == 1: print(1) else: if p[0] == p[1] - 1 or p[0] == p[1] - 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
def same(nums): curr = nums[0] for i in nums: if i != curr: return False return True def increasing(nums): for i in range(1,len(nums)): if nums[i]-nums[i-1] != 1: return False return True def main(): cards = list(map(str,input().split())) letters = {} #print(cards) for i in cards: if i[1] not in letters.keys(): letters[i[1]] = [int(i[0])] else: letters[i[1]].append(int(i[0])) for i in letters.keys(): letters[i].sort() if len(letters) == 1: for i in letters.keys(): if same(letters[i]): print(0) return if increasing(letters[i]): print(0) return if (letters[i][0] == letters[i][1]) or (letters[i][1] == letters[i][2]): print(1) return diff1 = letters[i][1]-letters[i][0] diff2 = letters[i][2]-letters[i][1] if diff1 == 1 or diff2 == 1 or diff1 == 2 or diff2 == 2: print(1) return print(2) elif len(letters) == 2: for i in letters.keys(): if len(letters[i]) == 2: if letters[i][0] == letters[i][1]: print(1) return diff1 = letters[i][1]-letters[i][0] if diff1 == 1 or diff1 == 2: print(1) return print(2) else: print(2) main()
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, …, 9m, 1p, 2p, …, 9p, 1s, 2s, …, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] β€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] β€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings β€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer β€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
import java.util.*; public class Solution { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int s[] = new int[10]; int m[] = new int[10]; int p[] = new int[10]; for (int i = 0; i < 3; i++) { String string = scanner.next(); if (string.charAt(1) == 'm') m[(int) string.charAt(0) - 48]++; if (string.charAt(1) == 'p') p[(int) string.charAt(0) - 48]++; if (string.charAt(1) == 's') s[(int) string.charAt(0) - 48]++; } for (int i = 0; i < 10; i++) { if (s[i] == 3 || m[i] == 3 || p[i] == 3) { System.out.println(0); return; } } for (int i = 2; i < 10; i++) { if ((s[i] == s[i - 1] && s[i - 1] == s[i - 2] && s[i - 2] == 1) || (m[i] == m[i - 1] && m[i - 1] == m[i - 2] && m[i - 2] == 1) || (p[i] == p[i - 1] && p[i - 1] == p[i - 2] && p[i - 2] == 1)) { System.out.println(0); return; } } for (int i = 0; i < 10; i++) { if (s[i] == 2 || m[i] == 2 || p[i] == 2) { System.out.println(1); return; } } for (int i = 1; i < 10; i++) { if ((s[i] == s[i - 1] && s[i - 1] == 1) || (m[i] == m[i - 1] && m[i - 1] == 1) || (p[i] == p[i - 1] && p[i - 1] == 1)) { System.out.println(1); return; } } for (int i = 2; i < 10; i++) { if ((s[i] == s[i - 2] && s[i - 2] == 1) || (m[i] == m[i - 2] && m[i - 2] == 1) || (p[i] == p[i - 2] && p[i - 2] == 1)) { System.out.println(1); return; } } 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.*; public class Main { public static void main(String[] args) { Scanner sc =new Scanner(System.in); List<Integer> m = new ArrayList<Integer>(); List<Integer> p = new ArrayList<Integer>(); List<Integer> s = new ArrayList<Integer>(); for(int i = 0; i < 3; i++) { String input = sc.next(); char ch = input.charAt(1); int num = input.charAt(0)-'0'; if(ch == 'm') m.add(num); else if(ch == 'p') p.add(num); else s.add(num); } int size = Math.max(m.size(), Math.max(p.size(), s.size())); if(size == 1) System.out.println(2); else { int[] number = new int[size]; if(m.size() == size) { int i = 0; for(Integer integer : m) { number[i] = integer; i++; } } else if(p.size() == size) { int i = 0; for(Integer integer : p) { number[i] = integer; i++; } } else if(s.size() == size) { int i = 0; for(Integer integer : s) { number[i] = integer; i++; } } if(size == 2) { if(Math.abs(number[1]-number[0]) <= 2) System.out.println(1); else System.out.println(2); } else { Arrays.sort(number); if(number[2] - number[0] < 3) { if((number[2] == number[1] && number[1] == number[0])|| number[2] - number[1] == number[1] - number[0]) System.out.println(0); else System.out.println(1); } else { if(number[1] - number[0] < 3 || number[2] - number[1] < 3) 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; long long int arr[10] = {0}; long long int brr[10] = {0}; long long int crr[10] = {0}; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); string s1, s2, s3; cin >> s1 >> s2 >> s3; if (s1[1] == 'm') arr[int(s1[0]) - 48]++; else if (s1[1] == 'p') brr[int(s1[0]) - 48]++; else if (s1[1] == 's') crr[int(s1[0]) - 48]++; if (s2[1] == 'm') arr[int(s2[0]) - 48]++; else if (s2[1] == 'p') brr[int(s2[0]) - 48]++; else if (s2[1] == 's') crr[int(s2[0]) - 48]++; if (s3[1] == 'm') arr[int(s3[0]) - 48]++; else if (s3[1] == 'p') brr[int(s3[0]) - 48]++; else if (s3[1] == 's') crr[int(s3[0]) - 48]++; for (int i = 0; i < 10; i++) { if (arr[i] == 3 || brr[i] == 3 || crr[i] == 3) { cout << "0"; exit(0); } } for (int i = 0; i < 8; i++) { if ((arr[i] != 0 && arr[i + 1] != 0 && arr[i + 2] != 0) || (brr[i] != 0 && brr[i + 1] != 0 && brr[i + 2] != 0) || (crr[i] != 0 && crr[i + 1] != 0 && crr[i + 2] != 0)) { cout << "0"; exit(0); } } for (int i = 0; i < 10; i++) { if (arr[i] == 2 || brr[i] == 2 || crr[i] == 2) { cout << "1"; exit(0); } } for (int i = 0; i < 9; i++) { if ((arr[i] != 0 && arr[i + 1] != 0) || (brr[i] != 0 && brr[i + 1] != 0) || (crr[i] != 0 && crr[i + 1] != 0)) { cout << "1"; exit(0); } } for (int i = 0; i < 8; i++) { if ((arr[i] != 0 && arr[i + 2] != 0) || (brr[i] != 0 && brr[i + 2] != 0) || (crr[i] != 0 && crr[i + 2] != 0)) { cout << "1"; 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
#include <bits/stdc++.h> using namespace std; template <typename T> void pr(vector<T> &v) { for (int i = 0; i < (int)(v).size(); i++) cout << v[i] << " "; cout << '\n'; ; } template <typename T> void pr(vector<vector<T>> &v) { for (int i = 0; i < (int)(v).size(); i++) { pr(v[i]); } } template <typename T> void re(T &x) { cin >> x; } template <typename T> void re(vector<T> &a) { for (int i = 0; i < (int)(a).size(); i++) re(a[i]); } template <class Arg, class... Args> void re(Arg &first, Args &...rest) { re(first); re(rest...); } template <typename T> void pr(T x) { cout << x << '\n'; ; } template <class Arg, class... Args> void pr(const Arg &first, const Args &...rest) { cout << first << " "; pr(rest...); cout << '\n'; ; } void ps() { cout << '\n'; ; } template <class T, class... Ts> void ps(const T &t, const Ts &...ts) { cout << t; if (sizeof...(ts)) cout << " "; ps(ts...); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); vector<string> s(3); re(s); set<string> x; int mn = INT_MAX; for (int i = 0; i < 3; i++) { x.insert(s[i]); } mn = min(mn, (int)(x).size() - 1); int num_k = 0; for (int i = 0; i < 3; i++) { for (int j = i + 1; j < 3; j++) { if (s[i][1] == s[j][1] && abs(s[i][0] - s[j][0]) == 1) { num_k++; } } } if (num_k == 2 && (int)(x).size() == 3) { mn = min(0, mn); } else if (num_k == 1) { mn = min(1, mn); } int num_k2 = 0; for (int i = 0; i < 3; i++) { for (int j = i + 1; j < 3; j++) { if (s[i][1] == s[j][1] && abs(s[i][0] - s[j][0]) == 2) { num_k2++; } } } if (num_k2 >= 1) { mn = min(1, mn); } pr(mn); }
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
tiles = input().split() tile0s = tiles[0][1] tile1s = tiles[1][1] tile2s = tiles[2][1] tile0v = int(tiles[0][0]) tile1v = int(tiles[1][0]) tile2v = int(tiles[2][0]) tvals = sorted ([tile0v, tile1v, tile2v]) if tiles[0] == tiles[1] and tiles[0] == tiles[2]: print (0) elif tile0s == tile1s and tile1s == tile2s and tvals[1] == tvals[0] +1 and tvals[2] == tvals[1] +1: print(0) elif tiles[0] == tiles[1] or tiles[0] == tiles[2] or tiles[1] == tiles[2]: print(1) elif ((tile0s == tile1s and abs(tile0v - tile1v) <=2) or (tile0s == tile2s and abs(tile0v - tile2v) <=2) or (tile2s == tile1s and abs(tile2v - tile1v) <=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 input = sys.stdin.readline a,b,c=input().split() s=[] p=[] m=[] if a[1]=='p': p.append(int(a[0])) elif a[1]=='s': s.append(int(a[0])) else: m.append(int(a[0])) if b[1]=='p': p.append(int(b[0])) elif b[1]=='s': s.append(int(b[0])) else: m.append(int(b[0])) if c[1]=='p': p.append(int(c[0])) elif c[1]=='s': s.append(int(c[0])) else: m.append(int(c[0])) s.sort() p.sort() m.sort() cur=2 if len(s)==3: if s[0]==s[1] and s[1]==s[2]: cur=0 elif s[0]==s[1] or s[1]==s[2]: cur=1 else: if s[0]+1==s[1] and s[1]+1==s[2]: cur=0 elif s[0]+1==s[1] or s[1]+1==s[2]: cur=1 elif s[0]+2==s[1] or s[1]+2==s[2]: cur=1 else: cur=2 elif len(s)==2: if s[0]==s[1]: cur=1 elif s[0]+1==s[1]: cur=1 elif s[0]+2==s[1]: cur=1 else: cur=2 else: cur=2 x=2 if len(p)==3: if p[0]==p[1] and p[1]==p[2]: x=0 elif p[0]==p[1] or p[1]==p[2]: x=1 else: if p[0]+1==p[1] and p[1]+1==p[2]: x=0 elif p[0]+1==p[1] or p[1]+1==p[2]: x=1 elif p[0]+2==p[1] or p[1]+2==p[2]: x=1 else: x=2 elif len(p)==2: if p[0]==p[1]: x=1 elif p[0]+1==p[1]: x=1 elif p[0]+2==p[1]: x=1 else: x=2 else: x=2 y=2 if len(m)==3: if m[0]==m[1] and m[1]==m[2]: y=0 elif m[0]==m[1] or m[1]==m[2]: y=1 else: if m[0]+1==m[1] and m[1]+1==m[2]: y=0 elif m[0]+1==m[1] or m[1]+1==m[2]: y=1 elif m[0]+2==m[1] or m[1]+2==m[2]: y=1 else: y=2 elif len(m)==2: if m[0]==m[1]: y=1 elif m[0]+1==m[1]: y=1 elif m[0]+2==m[1]: y=1 else: y=2 else: y=2 print(min(cur,x,y))
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
var tiles = readline().split(" ").map(function(x) { return (x) }); tiles.sort(); var first = tiles[0][1]; var second = tiles[1][1]; var third = tiles[2][1]; var firstNo = tiles[0][0]; var secondNo = tiles[1][0]; var thirdNo = tiles[2][0]; if (first != second && first != third && second != third){ print (2); } else if (first == second && first == third && second == third){ if ((firstNo == secondNo && firstNo == thirdNo && secondNo == thirdNo) || (secondNo - firstNo == 1 && thirdNo - secondNo == 1)){ print(0); } else if ((secondNo - firstNo > 2 && secondNo != thirdNo) && (thirdNo - secondNo > 2 && firstNo != secondNo)){ print(2); } else { print(1); } } else if (first == second){ if(secondNo - firstNo < 3){ print(1); } else { print(2); } } else if (second == third){ if(thirdNo - secondNo < 3){ print(1); } else { print(2); } } else if (first == third){ if(thirdNo - firstNo < 3){ print(1); } else { print(2); } }
JAVA
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, …, 9m, 1p, 2p, …, 9p, 1s, 2s, …, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] β€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] β€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings β€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer β€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
a=[[0 for i in range(10)] for j in range(3)] s=input().split() m1=0 for i in s: k=int(i[0]) if i[1]=='m': a[0][k]+=1 m1=max(m1,a[0][k]) elif i[1]=='p': a[1][k]+=1 m1=max(m1,a[1][k]) elif i[1]=='s': a[2][k]+=1 m1=max(m1,a[2][k]) m2=0 for i in range(3): for j in range(1,8): if a[i][j]>0: a[i][j]=1 if a[i][j+1]>0: a[i][j+1]=1 if a[i][j+2]>0: a[i][j+2]=1 m2=max(a[i][j]+a[i][j+1]+a[i][j+2],m2) print(min(3-m1,3-m2))
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() l=sorted(l) # print(l) if(l[0]==l[1]==l[2]): print(0) elif(l[0][1]==l[1][1]==l[2][1]): if(int(l[0][0])+1==int(l[1][0]) and int(l[0][0])+2==int(l[2][0])): print(0) elif(int(l[1][0])-int(l[0][0])<=2): print(1) elif(int(l[2][0])-int(l[0][0])<=2): print(1) elif(int(l[2][0])-int(l[1][0])<=2): print(1) else: print(2) elif(l[0][1]==l[1][1]): if(int(l[1][0])-int(l[0][0])<=2): print(1) else: print(2) elif(l[0][1]==l[2][1]): if(int(l[2][0])-int(l[0][0])<=2): print(1) else: print(2) elif(l[1][1]==l[2][1]): if(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
arr = input().split(" ") arr = set(arr) ans = 2 tmp = [0]*3 for i in arr: for j in arr: if i[1] == j[1] and 1 <= int(i[0]) - int(j[0]) <= 2: if int(i[0]) - int(j[0]) == 1: tmp[1] += 1 else: tmp[2] = 1 ans -= max(tmp) ans = min(ans, len(arr) - 1) print(max(0, ans))
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, …, 9m, 1p, 2p, …, 9p, 1s, 2s, …, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] β€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] β€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings β€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer β€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
import sys def splitTiles(a): return [list(filter(lambda x: x[1] == 's', a)), list(filter(lambda x: x[1] == 'p', a)), list(filter(lambda x: x[1] == 'm', a))] def missingElements(a): if len(a) == 0: return 2 return min(map(lambda i: 2 - (1 if (i[0]+1, i[1]) in a else 0) - (1 if (i[0]+2, i[1]) in a else 0), a)) tiles = list(map(lambda x: (int(x[0]), x[1]), sys.stdin.readline().strip().split())) if tiles[0] == tiles[1] and tiles[1] == tiles[2]: print("0") exit() if tiles[0] == tiles[1] or tiles[1] == tiles[2] or tiles[0] == tiles[2]: print("1") exit() print(min(map(missingElements, splitTiles(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
import java.util.*; public class test { public static void main(String[] args) { Scanner s = new Scanner(System.in); String[] str=new String[3]; StringBuilder[] sb=new StringBuilder[3]; str[0]=s.next(); sb[0] = new StringBuilder(str[0]); sb[0]=sb[0].reverse(); str[0]=sb[0].toString(); str[1]=s.next(); sb[1] = new StringBuilder(str[1]); sb[1]=sb[1].reverse(); str[1]=sb[1].toString(); str[2]=s.next(); sb[2] = new StringBuilder(str[2]); sb[2]=sb[2].reverse(); str[2]=sb[2].toString(); Arrays.sort(str); if(str[0].charAt(0)==str[1].charAt(0) && str[1].charAt(0)==str[2].charAt(0)) { if(str[0].charAt(1)-str[1].charAt(1)==0) { if(str[1].charAt(1)-str[2].charAt(1)==0) { System.out.println("0"); System.exit(0); } System.out.println("1"); System.exit(0); } else if(str[0].charAt(1)-str[1].charAt(1)==-1) { if(str[1].charAt(1)-str[2].charAt(1)==-1) { System.out.println("0"); System.exit(0); } System.out.println("1"); System.exit(0); } else if(str[0].charAt(1)-str[1].charAt(1)==-2) { System.out.println("1"); System.exit(0); } else if(str[1].charAt(1)-str[2].charAt(1)>=-2) { System.out.println("1"); System.exit(0); } System.out.println("2"); System.exit(0); } if(str[0].charAt(0)==str[1].charAt(0)) { if(str[0].charAt(1)-str[1].charAt(1)>=-2) { System.out.println("1"); System.exit(0); } } if(str[1].charAt(0)==str[2].charAt(0)) { if(str[1].charAt(1)-str[2].charAt(1)>=-2) { System.out.println("1"); System.exit(0); } } System.out.println("2"); System.exit(0); } }
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 sys from collections import defaultdict as dc #input=sys.stdin.readline from bisect import bisect_left, bisect_right l=list(input().split()) x=[] y=dc(int) for i in range(3): y[l[i]]+=1 x.append(list(l[i])) if 3 in y.values(): print(0) elif 2 in y.values(): print(1) else: x.sort(key=lambda x:(x[1],x[0])) f=1 i=1 c=0 f1=0 while(i<3 and f): if int(x[i][0])-int(x[i-1][0])==1 and x[i][1]==x[i-1][1]: i+=1 c+=1 elif int(x[i][0])-int(x[i-1][0])==2 and x[i][1]==x[i-1][1]: f1=1 i+=1 else: i+=1 if c==2: print(0) elif f1==1: print(1) else: if c==0: print(2) else: print(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
//package codeforces; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.stream.Stream; public class Solution { public static void main(String[] args) throws IOException { try(BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) { String[] initialTiles = reader.readLine().split("\\s+"); int distinctTiles = (int) Stream.of(initialTiles).distinct().count(); if(distinctTiles == 1) { System.out.println(0); } else if(distinctTiles == 2){ System.out.println(1); } else { int[] m = new int[9], p = new int[9], s = new int[9]; for(String tile : initialTiles) { if(tile.contains("m")) { m[tile.charAt(0) - '0' - 1] += 1; } else if(tile.contains("p")) { p[tile.charAt(0) - '0' - 1] += 1; } else { s[tile.charAt(0) - '0' - 1] += 1; } } int max = Math.max(Math.max(computeMaxSuccesiveTripletSizePossible(m), computeMaxSuccesiveTripletSizePossible(p)), computeMaxSuccesiveTripletSizePossible(s)); if(max == 1) { System.out.println(2); } else if(max == 2) { System.out.println(1); } else { System.out.println(0); } } } } private static int computeMaxSuccesiveTripletSizePossible(int[] array) { int max = array[0] + array[1] + array[2]; for(int i = 1; i + 2 < array.length; i++) { max = Math.max(max, array[i] + array[i + 1] + array[i + 2]); } return max; } }
JAVA
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, …, 9m, 1p, 2p, …, 9p, 1s, 2s, …, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] β€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] β€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings β€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer β€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); string s[3]; cin >> s[0] >> s[1] >> s[2]; int ans = 2; if (s[0] == s[1] && s[1] == s[2]) return cout << 0, 0; if (s[0] == s[1] || s[1] == s[2] || s[0] == s[2]) return cout << 1, 0; if (s[0][1] == s[1][1] && s[0][1] == s[2][1]) { int a[3]; a[0] = s[0][0] - '0'; a[1] = s[1][0] - '0'; a[2] = s[2][0] - '0'; sort(a, a + 3); if (a[0] == a[1] - 1 && a[1] == a[2] - 1) return cout << 0, 0; else if (a[0] == a[1] - 1 || a[1] == a[2] - 1 || a[0] == a[1] - 2 || a[1] == a[2] - 2) return cout << 1, 0; return cout << 2, 0; } if (s[0][1] == s[1][1]) { int a[2]; a[0] = s[0][0] - '0'; a[1] = s[1][0] - '0'; sort(a, a + 2); if (a[0] == a[1] - 1 || a[0] == a[1] - 2) ans = min(ans, 1); else ans = min(ans, 2); } if (s[0][1] == s[2][1]) { int a[2]; a[0] = s[0][0] - '0'; a[1] = s[2][0] - '0'; sort(a, a + 2); if (a[0] == a[1] - 1 || a[0] == a[1] - 2) ans = min(ans, 1); else ans = min(ans, 2); } if (s[1][1] == s[2][1]) { int a[2]; a[0] = s[1][0] - '0'; a[1] = s[2][0] - '0'; sort(a, a + 2); if (a[0] == a[1] - 1 || a[0] == a[1] - 2) ans = min(ans, 1); else ans = min(ans, 2); } return cout << ans, 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() { string a[3]; cin >> a[0] >> a[1] >> a[2]; map<char, vector<long long> > m; for (auto i : a) m[i[1]].push_back(i[0]); int ok = 2; for (auto i : m) { vector<long long> r = i.second; sort(r.begin(), r.end()); if (r.size() == 1) { continue; } else if (r.size() == 2) { if (r[1] - r[0] <= 2) ok = min(ok, 1); } else { if ((r[2] - r[0] == 0) || ((r[1] == r[0] + 1) && (r[2] == r[1] + 1))) ok = 0; else if ((r[2] - r[1] <= 2) || (r[1] - r[0] <= 2)) ok = min(ok, 1); } } cout << ok << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; int t = 1; while (t--) { solve(); } 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 operator import itemgetter A = [[int(a[0]), a[1]] for a in list(map(str, input().split()))] D = {} for a in A: if not a[1] in D.keys(): D[a[1]] = [a[0]] else: D[a[1]].append(a[0]) ans = 2 for d in D.values(): if len(d) == 1: continue elif len(d) == 2: if d[0] == d[1] or abs(d[0]-d[1]) == 1 or abs(d[0]-d[1]) == 2: ans = min(ans, 1) else: d.sort() if d[0] == d[2] or (abs(d[0]-d[1]) == 1 and abs(d[2]-d[1]) == 1): ans = 0 elif d[0] == d[1] or d[1] == d[2] or abs(d[0]-d[1]) == 1 or abs(d[2]-d[1]) == 1 or abs(d[0]-d[1]) == 2 or abs(d[2]-d[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
t = input() a = t[0] + t[1] b = t[3] + t[4] c = t[6] + t[7] d = { 'm': t.count('m'), 'p': t.count('p'), 's': t.count('s') } if d['m'] == 0: d.pop('m') if d['p'] == 0: d.pop('p') if d['s'] == 0: d.pop('s') l = list() if len(d) == 1: a_n = int(a[0]) b_n = int(b[0]) c_n = int(c[0]) l = [a_n, b_n, c_n] l.sort() if a_n == b_n and a_n == c_n: print(0) elif a_n == b_n or a_n == c_n or b_n == c_n: print(1) elif l[0] == l[1] - 1 and l[1] == l[2] - 1: print(0) elif l[0] == l[1] - 1 or l[1] == l[2] - 1 or l[0] == l[2] - 1: print(1) elif l[0] == l[1] - 2 or l[1] == l[2] - 2 or l[0] == l[2] - 1: print(1) else: print(2) elif len(d) == 2: x = max(d.values()) if 'm' in d and d['m'] == x: x = 'm' elif 'p' in d and d['p'] == x: x = 'p' else: x = 's' if a[1] == x: l.append(int(a[0])) if b[1] == x: l.append(int(b[0])) if c[1] == x: l.append(int(c[0])) l.sort() if l[0] == l[1]: print(1) elif l[0] == l[1] - 2: print(1) elif l[0] == l[1] - 1: print(1) else: print(2) else: print(2)
PYTHON3
1191_B. Tokitsukaze and Mahjong
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, …, 9m, 1p, 2p, …, 9p, 1s, 2s, …, 9s. In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand. Do you know the minimum number of extra suited tiles she needs to draw so that she can win? Here are some useful definitions in this game: * A mentsu, also known as meld, is formed by a koutsu or a shuntsu; * A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; * A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: * [2m, 3p, 2s, 4m, 1s, 2s, 4s] β€” it contains no koutsu or shuntsu, so it includes no mentsu; * [4s, 3m, 3p, 4s, 5p, 4s, 5p] β€” it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; * [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] β€” it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite. Input The only line contains three strings β€” the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s. Output Print a single integer β€” the minimum number of extra suited tiles she needs to draw. Examples Input 1s 2s 3s Output 0 Input 9m 9m 9m Output 0 Input 3p 9m 2p Output 1 Note In the first example, Tokitsukaze already has a shuntsu. In the second example, Tokitsukaze already has a koutsu. In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile β€” 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
2
8
'''input 1s 3s 5s ''' arr = input().split() arr.sort() m = [] p = [] s = [] for i in range(3): if (arr[i][-1]=='s'): s.append(int(arr[i][0])) if (arr[i][-1]=='m'): m.append(int(arr[i][0])) if (arr[i][-1]=='p'): p.append(int(arr[i][0])) if (len(m)==3 and m[0]+1==m[1] and m[1]+1==m[2]): print(0) elif (len(m)==3 and m[0]==m[1] and m[1]==m[2]): print(0) elif (len(s)==3 and s[0]==s[1] and s[1]==s[2]): print(0) elif (len(p)==3 and p[0]==p[1] and p[1]==p[2]): print(0) elif (len(p)==3 and p[0]+1==p[1] and p[1]+1==p[2]): print(0) elif (len(s)==3 and s[0]+1==s[1] and s[1]+1==s[2]): print(0) elif (len(s)==3 and (s[0]==s[1] or s[1]==s[2] or s[0]+1==s[1] or s[1]+1==s[2] or s[0]+2==s[2] or s[0]+2==s[1] or s[1]+2==s[2])): print(1) elif (len(m)==3 and (m[0]==m[1] or m[1]==m[2] or m[0]+1==m[1] or m[1]+1==m[2] or m[0]+2==m[2] or m[0]+2==m[1] or m[1]+2==m[2])): print(1) elif (len(p)==3 and (p[0]==p[1] or p[1]==p[2] or p[0]+1==p[1] or p[1]+1==p[2] or p[0]+2==p[2] or p[0]+2==p[1] or p[1]+2==p[2])): print(1) elif (len(m)==2 and (m[0]==m[1] or m[0]+1==m[1] or m[0]+2==m[1])): print(1) elif (len(s)==2 and (s[0]==s[1] or s[0]+1==s[1] or s[0]+2==s[1])): print(1) elif (len(p)==2 and (p[0]==p[1] or p[0]+1==p[1] or p[0]+2==p[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
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
/* Roses are red Memes are neat All my test cases time out Lmao yeet */ import java.util.*; import java.io.*; public class B { public static void main(String args[]) throws Exception { BufferedReader infile = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(infile.readLine()); String s1 = st.nextToken(); String s2 = st.nextToken(); String s3 = st.nextToken(); HashSet<String> set = new HashSet<String>(); set.add(s1); set.add(s2); set.add(s3); if(set.size() < 3) { System.out.println(set.size()-1); return; } int res = 2; //bash all seq String[] arr = new String[3]; arr[0] = s1; arr[1] = s2; arr[2] = s3; res = Math.min(res, bash(arr)); System.out.println(res); } public static int bash(String[] arr) { int res = 3; for(int qw=0; qw < 3; qw++) { int base = Integer.parseInt(arr[qw].substring(0, 1)); char c = arr[qw].charAt(1); int temp = 0; if(base <= 7) { String x = (base+1)+""+c; String y = (base+2)+""+c; temp = has(x, arr)+has(y, arr); res = Math.min(res, temp); } if(base <= 8 && base >= 2) { String x = (base+1)+""+c; String y = (base-1)+""+c; temp = has(x, arr)+has(y, arr); res = Math.min(res, temp); } if(base >= 3) { String x = (base-1)+""+c; String y = (base-2)+""+c; temp = has(x, arr)+has(y, arr); res = Math.min(res, temp); } } return res; } public static int has(String s, String[] arr) { for(String x: arr) if(s.equals(x)) return 0; return 1; } } //save me, I'm fine
JAVA
120_B. Quiz League
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k. Input The first line contains two positive integers n and k (1 ≀ n ≀ 1000 and 1 ≀ k ≀ n) β€” the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≀ i ≀ n). The sectors are given in the clockwise order, the first sector follows after the n-th one. Output Print the single number β€” the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked. Examples Input 5 5 0 1 0 1 0 Output 2 Input 2 1 1 1 Output 1
2
8
import java.io.*; import java.util.*; import java.math.*; public class P120B { @SuppressWarnings("unchecked") public void run() throws Exception { boolean [] played = new boolean [nextInt()]; int k = nextInt() - 1; for (int i = 0; i < played.length; i++) { played[i] = (nextInt() == 0); } while (played[k]) { k = (k + 1) % played.length; } println(k + 1); } public static void main(String... args) throws Exception { br = new BufferedReader(new InputStreamReader(new FileInputStream("input.txt"))); pw = new PrintWriter(new BufferedOutputStream(new FileOutputStream("output.txt"))); new P120B().run(); br.close(); pw.close(); } static BufferedReader br; static PrintWriter pw; StringTokenizer stok; String nextToken() throws IOException { while (stok == null || !stok.hasMoreTokens()) { String s = br.readLine(); if (s == null) { return null; } stok = new StringTokenizer(s); } return stok.nextToken(); } void print(byte b) { print("" + b); } void print(int i) { print("" + i); } void print(long l) { print("" + l); } void print(double d) { print("" + d); } void print(char c) { print("" + c); } void print(Object o) { if (o instanceof int[]) { print(Arrays.toString((int [])o)); } else if (o instanceof long[]) { print(Arrays.toString((long [])o)); } else if (o instanceof char[]) { print(Arrays.toString((char [])o)); } else if (o instanceof byte[]) { print(Arrays.toString((byte [])o)); } else if (o instanceof short[]) { print(Arrays.toString((short [])o)); } else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o)); } else if (o instanceof float[]) { print(Arrays.toString((float [])o)); } else if (o instanceof double[]) { print(Arrays.toString((double [])o)); } else if (o instanceof Object[]) { print(Arrays.toString((Object [])o)); } else { print("" + o); } } void print(String s) { pw.print(s); } void println() { println(""); } void println(byte b) { println("" + b); } void println(int i) { println("" + i); } void println(long l) { println("" + l); } void println(double d) { println("" + d); } void println(char c) { println("" + c); } void println(Object o) { print(o); println(""); } void println(String s) { pw.println(s); } int nextInt() throws IOException { return Integer.parseInt(nextToken()); } long nextLong() throws IOException { return Long.parseLong(nextToken()); } double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } char nextChar() throws IOException { return (char) (br.read()); } String next() throws IOException { return nextToken(); } String nextLine() throws IOException { return br.readLine(); } int [] readInt(int size) throws IOException { int [] array = new int [size]; for (int i = 0; i < size; i++) { array[i] = nextInt(); } return array; } long [] readLong(int size) throws IOException { long [] array = new long [size]; for (int i = 0; i < size; i++) { array[i] = nextLong(); } return array; } double [] readDouble(int size) throws IOException { double [] array = new double [size]; for (int i = 0; i < size; i++) { array[i] = nextDouble(); } return array; } String [] readLines(int size) throws IOException { String [] array = new String [size]; for (int i = 0; i < size; i++) { array[i] = nextLine(); } return array; } }
JAVA
120_B. Quiz League
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k. Input The first line contains two positive integers n and k (1 ≀ n ≀ 1000 and 1 ≀ k ≀ n) β€” the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≀ i ≀ n). The sectors are given in the clockwise order, the first sector follows after the n-th one. Output Print the single number β€” the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked. Examples Input 5 5 0 1 0 1 0 Output 2 Input 2 1 1 1 Output 1
2
8
//package codeforces; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.Closeable; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.List; import java.util.Locale; import java.util.Random; import java.util.StringTokenizer; public class A implements Closeable { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); A() throws IOException { reader = new BufferedReader(new FileReader("input.txt")); writer = new PrintWriter(new FileWriter("output.txt")); } StringTokenizer stringTokenizer; String next() throws IOException { while (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) { stringTokenizer = new StringTokenizer(reader.readLine()); } return stringTokenizer.nextToken(); } int nextInt() throws IOException { return Integer.parseInt(next()); } long nextLong() throws IOException { return Long.parseLong(next()); } double nextDouble() throws IOException { return Double.parseDouble(next()); } private int MOD = 1000 * 1000 * 1000 + 7; int sum(int a, int b) { a += b; return a >= MOD ? a - MOD : a; } int product(int a, int b) { return (int) (1l * a * b % MOD); } int pow(int x, int k) { int result = 1; while (k > 0) { if (k % 2 == 1) { result = product(result, x); } x = product(x, x); k /= 2; } return result; } int inv(int x) { return pow(x, MOD - 2); } void solve() throws IOException { int n = nextInt(), k = nextInt() - 1; int[] a = new int[n]; for(int i = 0; i < n; i++) { a[i] = nextInt(); } while(a[k] == 0) { k = (k + 1) % n; } writer.println(k + 1); } public static void main(String[] args) throws IOException { try (A a = new A()) { a.solve(); } } @Override public void close() throws IOException { reader.close(); writer.close(); } }
JAVA
120_B. Quiz League
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k. Input The first line contains two positive integers n and k (1 ≀ n ≀ 1000 and 1 ≀ k ≀ n) β€” the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≀ i ≀ n). The sectors are given in the clockwise order, the first sector follows after the n-th one. Output Print the single number β€” the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked. Examples Input 5 5 0 1 0 1 0 Output 2 Input 2 1 1 1 Output 1
2
8
import java.io.*; import java.util.*; public class Main { void solve() throws IOException { int n = nextInt(); int k = nextInt() - 1; int[] xs = new int[n]; for(int i = 0; i < n; ++i) xs[i] = nextInt(); while(xs[k] == 0) k = (k + 1) % n; out.println(k + 1); } void run() throws IOException { in = new BufferedReader(new FileReader("input.txt")); out = new PrintWriter(new FileWriter("output.txt")); solve(); in.close(); out.close(); } BufferedReader in; PrintWriter out; StringTokenizer tok; String nextToken() throws IOException { while(tok == null || !tok.hasMoreTokens()) tok = new StringTokenizer(in.readLine()); return tok.nextToken(); } int nextInt() throws IOException { return Integer.parseInt(nextToken()); } long nextLong() throws IOException { return Long.parseLong(nextToken()); } double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } public static void main(String[] args) throws IOException { new Main().run(); } }
JAVA
120_B. Quiz League
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k. Input The first line contains two positive integers n and k (1 ≀ n ≀ 1000 and 1 ≀ k ≀ n) β€” the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≀ i ≀ n). The sectors are given in the clockwise order, the first sector follows after the n-th one. Output Print the single number β€” the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked. Examples Input 5 5 0 1 0 1 0 Output 2 Input 2 1 1 1 Output 1
2
8
import java.awt.Point; import java.io.*; import java.math.BigInteger; import java.util.*; import static java.lang.Math.*; public class B { final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE")!=null; BufferedReader in; PrintWriter out; StringTokenizer tok = new StringTokenizer(""); void init() throws FileNotFoundException{ in = new BufferedReader(new FileReader("input.txt")); out = new PrintWriter("output.txt"); } String readString() throws IOException{ while(!tok.hasMoreTokens()){ tok = new StringTokenizer(in.readLine()); } return tok.nextToken(); } int readInt() throws IOException{ return Integer.parseInt(readString()); } long readLong() throws IOException{ return Long.parseLong(readString()); } double readDouble() throws IOException{ return Double.parseDouble(readString()); } public static void main(String[] args){ new B().run(); } public void run(){ try{ long t1 = System.currentTimeMillis(); init(); solve(); out.close(); long t2 = System.currentTimeMillis(); System.err.println("Time = "+(t2-t1)); }catch (Exception e){ e.printStackTrace(System.err); System.exit(-1); } } void solve() throws IOException{ int n = readInt(); int k = readInt() - 1; int min = -1; for(int i = 0; i < n; i++){ int t = readInt(); if(min == -1 && t == 1) min = i; if(i >= k && t == 1){ out.println((i+1)); return; } } out.println((min+1)); } static class Utils { private Utils() {} public static void mergeSort(int[] a) { mergeSort(a, 0, a.length - 1); } private static void mergeSort(int[] a, int leftIndex, int rightIndex) { final int MAGIC_VALUE = 50; if (leftIndex < rightIndex) { if (rightIndex - leftIndex <= MAGIC_VALUE) { insertionSort(a, leftIndex, rightIndex); } else { int middleIndex = (leftIndex + rightIndex) / 2; mergeSort(a, leftIndex, middleIndex); mergeSort(a, middleIndex + 1, rightIndex); merge(a, leftIndex, middleIndex, rightIndex); } } } private static void merge(int[] a, int leftIndex, int middleIndex, int rightIndex) { int length1 = middleIndex - leftIndex + 1; int length2 = rightIndex - middleIndex; int[] leftArray = new int[length1]; int[] rightArray = new int[length2]; System.arraycopy(a, leftIndex, leftArray, 0, length1); System.arraycopy(a, middleIndex + 1, rightArray, 0, length2); for (int k = leftIndex, i = 0, j = 0; k <= rightIndex; k++) { if (i == length1) { a[k] = rightArray[j++]; } else if (j == length2) { a[k] = leftArray[i++]; } else { a[k] = leftArray[i] <= rightArray[j] ? leftArray[i++] : rightArray[j++]; } } } private static void insertionSort(int[] a, int leftIndex, int rightIndex) { for (int i = leftIndex + 1; i <= rightIndex; i++) { int current = a[i]; int j = i - 1; while (j >= leftIndex && a[j] > current) { a[j + 1] = a[j]; j--; } a[j + 1] = current; } } } boolean isPrime(int a){ for(int i = 2; i <= sqrt(a); i++) if(a % i == 0) return false; return true; } static double distance(long x1, long y1, long x2, long y2){ return Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); } static long gcd(long a, long b){ if(min(a,b) == 0) return max(a,b); return gcd(max(a, b) % min(a,b), min(a,b)); } static long lcm(long a, long b){ return a * b /gcd(a, b); } }
JAVA
120_B. Quiz League
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k. Input The first line contains two positive integers n and k (1 ≀ n ≀ 1000 and 1 ≀ k ≀ n) β€” the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≀ i ≀ n). The sectors are given in the clockwise order, the first sector follows after the n-th one. Output Print the single number β€” the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked. Examples Input 5 5 0 1 0 1 0 Output 2 Input 2 1 1 1 Output 1
2
8
/* /$$$$$ /$$$$$$ /$$ /$$ /$$$$$$ |__ $$ /$$__ $$ |$$ |$$ /$$__ $$ | $$| $$ \ $$| $$|$$| $$ \ $$ | $$| $$$$$$$$| $$ / $$/| $$$$$$$$ / $$ | $$| $$__ $$ \ $$ $$/ | $$__ $$ | $$ | $$| $$ | $$ \ $$$/ | $$ | $$ | $$$$$$/| $$ | $$ \ $/ | $$ | $$ \______/ |__/ |__/ \_/ |__/ |__/ /$$$$$$$ /$$$$$$$ /$$$$$$ /$$$$$$ /$$$$$$$ /$$$$$$ /$$ /$$ /$$ /$$ /$$$$$$$$ /$$$$$$$ | $$__ $$| $$__ $$ /$$__ $$ /$$__ $$| $$__ $$ /$$__ $$| $$$ /$$$| $$$ /$$$| $$_____/| $$__ $$ | $$ \ $$| $$ \ $$| $$ \ $$| $$ \__/| $$ \ $$| $$ \ $$| $$$$ /$$$$| $$$$ /$$$$| $$ | $$ \ $$ | $$$$$$$/| $$$$$$$/| $$ | $$| $$ /$$$$| $$$$$$$/| $$$$$$$$| $$ $$/$$ $$| $$ $$/$$ $$| $$$$$ | $$$$$$$/ | $$____/ | $$__ $$| $$ | $$| $$|_ $$| $$__ $$| $$__ $$| $$ $$$| $$| $$ $$$| $$| $$__/ | $$__ $$ | $$ | $$ \ $$| $$ | $$| $$ \ $$| $$ \ $$| $$ | $$| $$\ $ | $$| $$\ $ | $$| $$ | $$ \ $$ | $$ | $$ | $$| $$$$$$/| $$$$$$/| $$ | $$| $$ | $$| $$ \/ | $$| $$ \/ | $$| $$$$$$$$| $$ | $$ |__/ |__/ |__/ \______/ \______/ |__/ |__/|__/ |__/|__/ |__/|__/ |__/|________/|__/ |__/ */ import java.io.BufferedReader; import java.text.DecimalFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; import java.io.*; public class abc { static PrintWriter pw; 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; } /* CREATED BY ME */ int[] readArray(int n) { int[] a = new int[n+1]; for (int i = 1; i <= n; i++) a[i] = nextInt(); return a; } } public static long gcd(long a, long b) { return b == 0 ? a : gcd(b, a % b); } public static boolean isPrime(long n) { if (n == 2) return true; long i = 2; while (i * i <= n) { if (n % i == 0) return false; i++; } return true; } public static long[] remove(long n) { long res[] = new long[1000000000]; long rese = 0; int i = 0; while (n > 0) { long dig = n % 10; n = n / 10; if (dig > 0) { rese = dig; res[i++] = rese; } } return res; } static int ceil(int x, int y) { return (x % y == 0 ? x / y : (x / y + 1)); } static long ceil(long x, long y) { return (x % y == 0 ? x / y : (x / y + 1)); } static int max(int x, int y) { return Math.max(x, y); } static int min(int x, int y) { return Math.min(x, y); } static int abs(int x) { return Math.abs(x); } static long abs(long x) { return Math.abs(x); } static int log2(int N) { int result = (int) (Math.log(N) / Math.log(2)); return result; } static long max(long x, long y) { return Math.max(x, y); } static long min(long x, long y) { return Math.min(x, y); } public static class pair { int x; int y; public pair(int a, int b) { x = a; y = b; } } public static class Comp implements Comparator<pair> { public int compare(pair a, pair b) { if (a.x != b.x) { return a.x - b.x; } else { return a.y - b.y; } } } /* * public static void extract(ArrayList<Integer> ar, int k, int d) { int c = 0; * for (int i = 1; i < k; i++) { int x = 0; boolean dm = false; while (x > 0) { * long dig = x % 10; x = x / 10; if (dig == d) { dm = true; break; } } if (dm) * ar.add(i); } } */ public static void dfs(int index, boolean vis[], int a[], int b[], int n) { vis[index] = true; for (int i = 0; i < n; i++) { if (!vis[i] && (a[i] == a[index] || b[i] == b[index])) dfs(i, vis, a, b, n); } } // counts the set(1) bit of a number public static long countSetBitsUtil(long x) { if (x <= 0) return 0; return (x % 2 == 0 ? 0 : 1) + countSetBitsUtil(x / 2); } //tells whether a particular index has which bit of a number public static int getIthBitsUtil(int x, int y) { return (x & (1 << y)) != 0 ? 1 : 0; } public static void swap(long x, long y) { x = x ^ y; y = y ^ x; x = x ^ y; } public static double decimalPlaces(double sum) { DecimalFormat df = new DecimalFormat("#.00"); String angleFormated = df.format(sum); double fin = Double.parseDouble(angleFormated); return fin; } //use collections.swap for swapping static boolean isSubSequence(String str1, String str2, int m, int n) { int j = 0; for (int i = 0; i < n && j < m; i++) if (str1.charAt(j) == str2.charAt(i)) j++; return (j == m); } static long sum( long n) { long sum=0; while (n > 0) { sum+= n % 10; n = n / 10; } return sum; } static long pow(long base, long power) { if (power == 0) { return 1; } long result = pow(base, power / 2); if (power % 2 == 1) { return result * result * base; } return result * result; } public static void main(String[] args) throws Exception { Scanner sc = new Scanner(new File("input.txt")); pw = new PrintWriter(new File("output.txt")); // use arraylist as it use the concept of dynamic table(amortized analysis) // Arrays.stream(array).forEach(a -> Arrays.fill(a, 0)); /* List<Integer> l1 = new ArrayList<Integer>(); */ int t = 1; while (t-- > 0) { int n=sc.nextInt(); int k=sc.nextInt(); int arr[]=new int[n+1]; for(int i=1;i<=n;i++) arr[i]=sc.nextInt(); while(arr[k]==0) { if(k==n) k=1; else k++; } pw.println(k); } pw.flush(); } }
JAVA
120_B. Quiz League
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k. Input The first line contains two positive integers n and k (1 ≀ n ≀ 1000 and 1 ≀ k ≀ n) β€” the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≀ i ≀ n). The sectors are given in the clockwise order, the first sector follows after the n-th one. Output Print the single number β€” the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked. Examples Input 5 5 0 1 0 1 0 Output 2 Input 2 1 1 1 Output 1
2
8
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.StringTokenizer; public class QuizLeague { public static void main(String[] args) throws IOException { FileReader in = new FileReader("input.txt"); BufferedReader buff = new BufferedReader(in); PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter( "output.txt"))); StringTokenizer st = new StringTokenizer(buff.readLine()); int n = Integer.parseInt(st.nextToken()); int index = Integer.parseInt(st.nextToken()) - 1; boolean[] list = new boolean[n]; StringTokenizer st1 = new StringTokenizer(buff.readLine()); for (int i = 0; i < n; i++) { int c = Integer.parseInt(st1.nextToken()); if (c == 0) list[i] = true; else list[i] = false; } while (list[index % n]) index++; out.println((index % n) + 1); in.close(); out.close(); } }
JAVA
120_B. Quiz League
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k. Input The first line contains two positive integers n and k (1 ≀ n ≀ 1000 and 1 ≀ k ≀ n) β€” the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≀ i ≀ n). The sectors are given in the clockwise order, the first sector follows after the n-th one. Output Print the single number β€” the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked. Examples Input 5 5 0 1 0 1 0 Output 2 Input 2 1 1 1 Output 1
2
8
import java.util.*; import java.lang.*; import java.math.*; import java.io.*; import static java.lang.Math.*; import static java.util.Arrays.*; public class Main { static int INF=1<<28; // static int key=1; /*int x,y; Main(int x,int y){ this.x=x; this.y=y; }*/ //static int sum=0; public static void main(String[] args)throws Exception{ Scanner sc =new Scanner(new File("input.txt")); // Scanner sc =new Scanner(System.in); File file = new File("output.txt"); PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file))); // sc.useDelimiter("(\\s)+|[,]"); // ArrayList<Integer> lis = new ArrayList<Integer>(); while(sc.hasNext()){ int n=ni(sc),k=ni(sc),r=0; int x[]=new int[n]; for(int t=0;t<n;t++)x[t]=ni(sc); if(x[k-1]==1){r=k;} else{ for(int i=k;i<n;i++){if(x[i]==1){r=i+1; break;} } if(r==0){ for(int i=0;i<k;i++){if(x[i]==1){r=i+1;break;} } } } System.out.println(r); pw.println(r); }pw.flush(); pw.close(); } static void pr(int x){ System.out.println(x); } static void db(Object... os){ System.err.println(Arrays.deepToString(os)); } static int ni(Scanner in){ return in.nextInt(); } static void out(int[] a){ String r=""; for(int i=0;i<a.length;i++){ r+=((i==0) ?"":" ")+a[i]; } System.out.println(r); } }
JAVA