这个代码好烂。。
/**//*
ID: lorelei3
TASK: crypt1
LANG: C++
*/
#include <fstream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
using namespace std;
const int N = 10;
int s[N];
bool f[N];
int main(){
int a,b,c,d,e,i,n,ans=0;
int ai[3], bi[3], res[4];
ifstream in("crypt1.in");
ofstream out("crypt1.out");
memset(f, false, sizeof(f));
in>>n;
for(i=0; i<n; ++i){
in>>s[i];
f[s[i]] = true;
}
for(a=0; a<n; ++a)
for(b=0; b<n; ++b)
for(c=0; c<n; ++c)
for(d=0; d<n; ++d){
if(s[a]*s[d]>10)
continue;
for(e=0; e<n; ++e){
memset(ai, 0, sizeof(a));
memset(bi, 0, sizeof(b));
memset(res, 0, sizeof(res));
int cc =0, bb=0;
bb = (s[c]*s[e])%10;
cc = (s[c]*s[e])/10;
ai[0] = bb;
bb = (s[b]*s[e]+cc)%10;
cc = (s[b]*s[e]+cc)/10;
ai[1] = bb;
ai[2] = (s[a]*s[e]+cc);
if(!(f[ai[0]] && f[ai[1]] && f[ai[2]]))
continue;
if(ai[2]>10)
continue;
bb = (s[c]*s[d])%10;
cc = (s[c]*s[d])/10;
bi[0] = bb;
bb = (s[b]*s[d]+cc)%10;
cc = (s[b]*s[d]+cc)/10;
bi[1] = bb;
bi[2] = (s[a]*s[d]+cc);
if(!(f[bi[0]] && f[bi[1]] && f[bi[2]]))
continue;
if(bi[2]>10)
continue;
res[0]=ai[0];
cc=0;
bb=(ai[1]+bi[0]+cc)%10;
cc=(ai[1]+bi[0]+cc)/10;
res[1]=bb;
bb=(ai[2]+bi[1]+cc)%10;
cc=(ai[2]+bi[1]+cc)/10;
res[2]=bb;
res[3]=bi[2]+cc;
if(res[3]>10)
continue;
else{
if(f[res[0]]&&f[res[1]]&&f[res[2]]&&f[res[3]]){
ans++;
}
}
}
}
out<<ans<<endl;
return 0;
}
posted on 2010-11-09 01:02
小阮 阅读(145)
评论(0) 编辑 收藏 引用 所属分类:
USACO