测评机: Xeost[5]
得分: 90分
提交日期: 2011-8-20 10:19:00
有效耗时: 516毫秒
RQNOJ近期在线比赛列表
RQNOJ八月份月赛 时间:2011-8-27 18:00:00 [报名]
测试结果1: 通过本测试点|有效耗时47ms
测试结果2: 通过本测试点|有效耗时47ms
测试结果3: 通过本测试点|有效耗时46ms
测试结果4: 通过本测试点|有效耗时63ms
测试结果5: 通过本测试点|有效耗时47ms
测试结果6: 通过本测试点|有效耗时125ms
测试结果7: 通过本测试点|有效耗时47ms
测试结果8: 选手程序运行超过时限
测试结果9: 通过本测试点|有效耗时47ms
测试结果10:通过本测试点|有效耗时47ms
PASS看你们写那么长的搜索真纠结..40行的代码没搞定- -
#include<iostream>
using namespace std;
char s[3][27],zm[27];
int n,had[27],used[27],hash[27],st[27],top=-1,stop=-1,m=0;
void dfs(int c,int m,int stop)
{
int i,k=0;
while(c==st[stop]+1&&stop!=n-1)
if((had[s[0][n-stop-1]-65]+had[s[1][n-stop-1]-65]+m)%n!=had[s[2][n-stop-1]-65]) return;
else {m=(had[s[0][n-stop-1]-65]+had[s[1][n-stop-1]-65]+m)/n; stop++;}
if(c==n)
if((had[s[0][n-stop-1]-65]+had[s[1][n-stop-1]-65]+m)==had[s[2][n-stop-1]-65])
{for(i=0;i<n;i++) cout<<had[i]<<' ';
exit(0);
}
else return;
for(i=n-1;i>=0;i--)
if(!hash[i])
{
hash[i]=true;
had[zm[c]-65]=i;
dfs(c+1,m,stop);
hash[i]=false;
}
}
int main()
{
int i,j;
cin>>n;
for(i=0;i<n;i++) had[i]=1;
for(i=0;i<3;i++) cin>>s[i];
for(i=n-1;i>=0,memcmp(hash,had,sizeof(had))!=0;i--)
{
for(j=0;j<3;j++)
if(!hash[s[j][i]-65]) {hash[s[j][i]-65]=true; zm[++top]=s[j][i];}
st[++stop]=top;
}
for(i=stop;i<n;i++) st[i]=top;
memset(hash,0,sizeof(hash));
memset(had,0,sizeof(had));
stop=0;
dfs(0,0,0);
}