20求
查看原帖
20求
1328844
72728abcd楼主2024/12/11 15:23

程序

#include<bits/stdc++.h>
using namespace std;
long long n,s,t,j=0;
string b;
vector<char> c;
int main()
{
	cin>>n>>s>>b;
	t=s;
	c.resize(n);
	for(int i=0;i<n;i++)
	{
		c[i]='0';
	}
	for(int i=0;i<b.length();i++)
	{
		c[j]=b[i];
		j++;
		while(j&&c[j]=='U'&&(c[j-1]=='L'||c[j-1]=='R'))
		{
			c[j]='0';
			c[j-1]='0';
			j-=2;
		}
	}
	for(int i=0;i<j;i++)
	{
		if(c[i]=='U')
		{
			if(t%2)
			{
				t--;
				t/=2;
			}
			else
			{
				t/=2;
			}
		}
		if(c[i]=='L')
		{
			t*=2;
		}
		if(c[i]=='R')
		{
			t*=2;
			t++;
		}
	}
	cout<<t;
	return 0;
}
2024/12/11 15:23
加载中...