TLE求助
  • 板块题目总版
  • 楼主Jerry_heng
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/3/4 22:21
  • 上次更新2023/10/23 23:02:48
查看原帖
TLE求助
763878
Jerry_heng楼主2023/3/4 22:21

SP9120

#include<bits/stdc++.h>
using namespace std;
string st1,st2,st3,st4,st5,st;
bool b[12],bb[12];
int mn=INT_MAX,s[12],ans[12];
char ch[12];
void ss(int k){
	if(k==12){
		int sum=s[0]+s[2]+s[5]+s[7];
		if(sum>=mn)return;
		if(s[1]+s[2]+s[3]+s[4]!=sum)return;
		if(s[7]+s[8]+s[9]+s[10]!=sum)return;
		if(s[1]+s[5]+s[8]+s[11]!=sum)return;
		if(s[4]+s[6]+s[9]+s[11]!=sum)return;
		if(s[0]+s[3]+s[6]+s[10]!=sum)return;
		for(int i=0;i<12;i++)ans[i]=s[i];
		mn=sum;
		return;
	}
	if(b[k])ss(k+1);
	else{
		for(int i=0;i<12;i++){
			if(!bb[i]){
				bb[i]=1;
				s[k]=i;
				ss(k+1);
				bb[i]=0;
			}
		}
	}
}
void pd(int x){
	if(st[x]>='A'&&st[x]<='L')s[x]=st[x]-'A',bb[st[x]-'A']=1,b[x]=1;
}
int main(){
	cin>>st1>>st2>>st3>>st4>>st5;
	st="            ";
	st[0]=st1[4];
	st[1]=st2[1];
	st[2]=st2[3];
	st[3]=st2[5];
	st[4]=st2[7];
	st[5]=st3[2];
	st[6]=st3[6];
	st[7]=st4[1];
	st[8]=st4[3];
	st[9]=st4[5];
	st[10]=st4[7];
	st[11]=st5[4];
	for(int i=0;i<12;i++)pd(i);
	ss(0);
	for(int i=0;i<12;i++)
		ch[i]=ans[i]+'A';
	cout<<"...."<<ch[0]<<"...."<<endl;
	cout<<"."<<ch[1]<<"."<<ch[2]<<"."<<ch[3]<<"."<<ch[4]<<"."<<endl;
	cout<<".."<<ch[5]<<"..."<<ch[6]<<".."<<endl;
	cout<<"."<<ch[7]<<"."<<ch[8]<<"."<<ch[9]<<"."<<ch[10]<<"."<<endl;
	cout<<"...."<<ch[11]<<"...."<<endl;
	return 0;
} 
2023/3/4 22:21
加载中...