分析:在无限改之后终于过了,里面要处理的细节比较多,最后可以抽象成字符串,用set来去重
1 /* 2 PROB:combo 3 ID:wanghan 4 LANG:C++ 5 */ 6 #include "iostream" 7 #include "cstdio" 8 #include "cstring" 9 #include "string" 10 #include "vector" 11 #include "set" 12 using namespace std; 13 int n,num; 14 vector<int> Next; 15 set<string> h; 16 vector<int> p[4]; 17 vector<int> q[4]; 18 int a1,a2,a3,b1,b2,b3; 19 void init() 20 { 21 for(int i=1;i<=n;i++) 22 Next.push_back(i); 23 for(int i=1;i<=n;i++) 24 Next.push_back(i); 25 if(Next.size()<=5){ 26 for(int i=1;i<=5;i++) 27 Next.push_back(1); 28 } 29 } 30 string Rev(int num){ //转化成字符串 31 string res=""; 32 while(num){ 33 int mod=num%10; 34 res+=(mod+'0'); 35 num/=10; 36 } 37 int i=0,j=res.length()-1; 38 while(i<j){ 39 swap(res[i],res[j]); 40 i++,j--; 41 } 42 return res; 43 } 44 void solve1(int ans,int flag){ 45 int pos; 46 for(int i=0;i<Next.size();i++){ 47 if(ans==Next[i]){ 48 pos=i; break; 49 } 50 } 51 if(pos<2) pos+=max(n,2); 52 p[flag].push_back(Next[pos-2]); 53 p[flag].push_back(Next[pos-1]); 54 p[flag].push_back(Next[pos]); 55 p[flag].push_back(Next[pos+1]); 56 p[flag].push_back(Next[pos+2]); 57 /*cout<<flag<<":"<<endl; 58 for(int i=0;i<p[flag].size();i++) 59 cout<<p[flag][i]<<endl; 60 cout<<endl;*/ 61 } 62 void solve2(int ans,int flag){ 63 int pos; 64 for(int i=0;i<Next.size();i++){ 65 if(ans==Next[i]){ 66 pos=i; break; 67 } 68 } 69 if(pos<2) pos+=max(2,n); 70 q[flag].push_back(Next[pos-2]); 71 q[flag].push_back(Next[pos-1]); 72 q[flag].push_back(Next[pos]); 73 q[flag].push_back(Next[pos+1]); 74 q[flag].push_back(Next[pos+2]); 75 /*cout<<flag<<":"<<endl; 76 for(int i=0;i<q[flag].size();i++) 77 cout<<q[flag][i]<<endl; 78 cout<<endl;*/ 79 } 80 int main() 81 { 82 freopen("combo.in","r",stdin); 83 freopen("combo.out","w",stdout); 84 cin>>n; 85 init(); 86 cin>>a1>>a2>>a3>>b1>>b2>>b3; 87 solve1(a1,0); 88 solve1(a2,1); 89 solve1(a3,2); 90 solve2(b1,0); 91 solve2(b2,1); 92 solve2(b3,2); 93 for(int i=0;i<p[0].size();i++){ 94 for(int j=0;j<p[1].size();j++){ 95 for(int k=0;k<p[2].size();k++){ 96 string tt=""; 97 tt+=Rev(p[0][i]); 98 tt+=Rev(p[1][j]); 99 tt+=Rev(p[2][k]); 100 h.insert(tt); 101 } 102 } 103 } 104 for(int i=0;i<q[0].size();i++){ 105 for(int j=0;j<q[1].size();j++){ 106 for(int k=0;k<q[2].size();k++){ 107 string yy=""; 108 yy+=Rev(q[0][i]); 109 yy+=Rev(q[1][j]); 110 yy+=Rev(q[2][k]); 111 h.insert(yy); 112 } 113 } 114 } 115 set<string>::iterator it; 116 /*for(it=h.begin();it!=h.end();it++) 117 cout<<*it<<endl;*/ 118 cout<<h.size()<<endl; 119 return 0; 120 }