Codeforces 1191B. Tokitsukaze and Mahjong Codeforces Round #573 (Div. 2)


Problem link

There are only two types of mentsus, so you can enumerate the mentsu you want her to form, and check the difference between that and those currently in her hand.

Alternatively, you can find out that the answer is at most 2, since she can draw two extra identical tiles which are the same as one of those in her hand. You may enumerate at most 1 extra tile for her and check if it can contribute to a mentsu. If she can't, the answer will be 2.

A solution in c++


#include<bits/stdc++.h>
using namespace std;
/// Typedef
typedef long long ll;
#define sc1(a) scanf("%lld",&a)
#define sc2(a,b) scanf("%lld %lld",&a,&b)
#define pf1(a) printf("%lld\n",a)
#define pf2(a,b) printf("%lld %lld\n",a,b)
#define mx 10000007
#define mod 100000007
#define PI acos(-1.0)
#define size1 1000
#define pb push_back
int main()
{
ll num, m, tc, t = 1;
int arr[4];
for(ll i = 0 ; i < 3; i++){
char ch;
cin >> num >> ch;
if(ch == 'm') arr[i] = num + 100;
else if(ch == 'p') arr[i] = num + 200;
else arr[i] = num + 300;
}
sort(arr, arr + 3);
if(arr[0] == arr[1] && arr[1] == arr[2]){
cout << "0" << endl;
}
else if(arr[0] + 1 == arr[1] && arr[1] + 1 == arr[2]){
cout << "0" << endl;
}
else if(
arr[0] == arr[1] || arr[1] == arr[2] ||
arr[0] + 1 == arr[1] || arr[1] + 1 == arr[2] ||
arr[0] + 2 == arr[1] || arr[1] + 2 == arr[2]){
cout << "1" << endl;
}
else
cout << "2" << endl;
}

Post a Comment

0 Comments