其他分享
首页 > 其他分享> > Help Victoria the Wise CodeForces - 98A

Help Victoria the Wise CodeForces - 98A

作者:互联网

原题链接
考察:枚举
错误思路:
  枚举每一面为正面,给骰子每一面编号,然后求出当前枚举骰子状况每一面为正面的情况,并用字符串记录.
错误原因:
  不一定只转一次.....
思路:
  参考官方题解:

Code

#include <iostream> 
#include <cstring>
#include <set>
using namespace std;
const int N = 10;
string s;
set<string> st;
int ans;
bool vis[N];
string change(int w,string s)
{
	string str = "";
	if(w==1) return str = s;
	if(w==2)
	{
		str+=s[3],str+=s[2],str+=s[0];
		str+=s[1],str+=s[4],str+=s[5];
	}
	if(w==3)
	{
		str+=s[4],str+=s[5],str+=s[2];
		str+=s[3],str+=s[1],str+=s[0];
	}
	if(w==4)
	{
		str+=s[2],str+=s[3],str+=s[1];
		str+=s[0],str+=s[4],str+=s[5];
	}
	if(w==5)
	{
		str+=s[1],str+=s[0],str+=s[3];
		str+=s[2],str+=s[4],str+=s[5];
	}
	if(w==6)
	{
		str+=s[5],str+=s[4],str+=s[3];
		str+=s[2],str+=s[1],str+=s[0];
	}
	return str;
}
string rorate(string s)
{
	string str = s.substr(0,2);
	str+=s[4];
	str+=s[5];
	str+=s[3];
	str+=s[2];
	return str;
}
void dfs(string str)
{
	if(str.size()==6)
	{
		if(!st.count(str))
		{
			ans++;
			for(int i=1;i<=6;i++)
			{
				string sp = change(i,str);
				for(int j=1;j<=4;j++) st.insert(sp = rorate(sp));
			}
		}
		return;
	}
	for(int i=0;i<s.size();i++)
	{
		if(vis[i]) continue;
		vis[i] = 1;
		dfs(str+s[i]);
		vis[i] = 0;
	}
}
int main()
{
	cin>>s;
	dfs("");
	printf("%d\n",ans);
	return 0;
}

标签:24,include,return,string,int,CodeForces,str,Wise,98A
来源: https://www.cnblogs.com/newblg/p/15270485.html