Hi, This is regarding the problem 253 (painting cube ) on uva.http://acm.uva.es/p/v2/253.html I have got this problem accepted from the below code. I have removed some variables and other things to make sure this problem doesn't get accepted by copy paste method.
here are few questions. I think most of them are able to solve this problem by creating an array of 24 strings and then checking if it matches with any one of them. This is really simple. 1) Are there any smarter ways of doing this problem. 2) What would one do if only reflections are to be accepted other than rotations. Again i don't want to do it by generating arrays. 3) Are there any hashing or other smart ways or elegant ways to solve this problem . If you think like posting code please mail it to [EMAIL PROTECTED] 4) How would one solve the problem if it is extended to 4 or 5 dimensions. Is there any math behind it. [code] char *str[4] = { "123456", "135246", "154326", "142536" }; char *other[5] = { "624351", "326154", "263415", "421653", "564312" }; char *strarr[24]; char mystr[7]; void gen (void) { for (i = 0; i < 24; i++) strarr[i] = (char *) calloc (7, sizeof (char)); for (i = 0; i < 4; i++) { strcpy (strarr[cnt], str[i]); cnt++; } for (i = 0; i < 5; i++) { strcpy (strarr[cnt], other[i]); cnt++; } for (i = 0; i < 5; i++) { m.clear (); for (j = 0; j < 6; j++) { m[str[0][j]] = other[i][j]; } for (k = 1; k < 4; k++) { for (p = 0; p < 6; p++) { mystr[p] = m[str[k][p]]; } mystr[p] = '\0'; strcpy (strarr[cnt], mystr); cnt++; } } for (i = 0; i < cnt; i++) printf ("%s\n", strarr[i]); return; } int check(char *fstr,char *ostr) { char *cons=(char *)calloc(7,sizeof(char)); for(i=0;i<24;i++) { k=0; for(j=0;j<6;j++) { cons[k++]=fstr[strarr[i][j]-'0'-1]; } if(strcmp(cons,ostr)==0) return 1; } if(i==24) return 0; } int main () { gen (); while(scanf(" %s",bstr)!=EOF) { strncpy(bstr1,bstr,6); strncpy(bstr2,bstr+6,6); bstr1[6]='\0'; bstr2[6]='\0'; fl=check(bstr1,bstr2); if(fl==1) printf("TRUE\n"); else printf("FALSE\n"); } return 0; } [/code] --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/algogeeks -~----------~----~----~----~------~----~------~--~---