ZOJ - 4034 Mahjong Sorting

题意:给你一个有序的麻将序列,有三种牌面和一个白板。你有3*m个麻将,问幸运麻将有几种可能,幸运麻将应该放在最左端且不能影响给出序列的有序性。如果有白板的话,白板在幸运麻将的位置,如果幸运麻将在的话,在第一个。

题意说完了,分类模拟一下就可以了, flag记录有无白板和位置

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=101000;
#define INF 0x3f3f3f3f
struct node{
	char op[2];
	int x;
}a[N];
map<string,int>mp;
int n,m;
int cul(string s,int x)
{
	return mp[s]*m+x;
}
int main()
{
	int T;mp["C"]=0;mp["B"]=1;mp["D"]=2;
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d%d",&n,&m);
		int flag=0;
		for(int i=1;i<=n;i++)
		{
			scanf("%s",a[i].op);
			if(a[i].op[0]=='W') flag=i;
			else scanf("%d",&a[i].x);
		}
		a[n+1].op[0]='D';
		a[n+1].x=m+1;
		int ans=0;
		if(flag==0)
		{
			if(cul(a[1].op,a[1].x)>cul(a[2].op,a[2].x)) ans=1;
			else ans=3*m-n+1;
		}
		else if(flag==1)
			ans=cul(a[2].op,a[2].x)-1;
		else if(flag==2)
			ans=cul(a[3].op,a[3].x)-cul(a[1].op,a[1].x);
		else
		{
			if(cul(a[1].op,a[1].x)>cul(a[2].op,a[2].x)) ans=1;
			else ans=cul(a[flag+1].op,a[flag+1].x)-cul(a[flag-1].op,a[flag-1].x)-1;
		} 
		printf("%d\n",ans);
	}	
	return 0;
}

猜你喜欢

转载自blog.csdn.net/mmk27_word/article/details/84201462
ZOJ