A No to Palindromes!
Test instructions: To a string of length n of the first m character, to define a string is good when and only if each of his substrings is not a palindrome, now give a good string, than his dictionary order the first good string.
Puzzle: From the back to each bit of enumeration, if the current enumeration of the bit into a good string after, just to determine whether he and his front of a character is the same as the length of a palindrome 2, or with the front of his front two characters to form a palindrome string length 3.
Then we find the first position that can be changed, and each of the following positions will enumerate the first characters that can be obtained from ' a '.
1#include <cstdio>2 3#include <cmath>4 5#include <cstring>6 7#include <iostream>8 9#include <algorithm>Ten One A - using namespacestd; - the Chars[ -]; - - intn,p; - + - + intCheckintPosCharch) A at { - - if(pos>0&&s[pos-1]==CH)return 0; - - if(pos>1&&s[pos-2]==CH)return 0; - in return 1; - to } + - intMain () the * { $ Panax Notoginsengscanf"%d%d",&n,&p); - thescanf"%s", s); + A for(inti=n-1; i>=0;--i) the + { - $ for(intch=s[i]+1;ch<'a'+p;++ch) $ - { - the if(!check (I,ch))Continue; - Wuyis[i]=ch; the - for(intj=i+1; j<n;++j) Wu - for(s[j]='a';! Check (J,s[j]) &&s[j]<'a'+p;++s[j]); About $printf"%s", s); - - return 0; - A } + the } - $printf"NO"); the the return 0; the the}
View Code
B Restore Cube
Test instructions: Given eight triples (x, y, z), each element within the ternary group can be exchanged, asking if there is any possibility that these eight triples correspond to eight points in space to form a cube.
A clear and straightforward enumeration of all condition checks is possible, for checking whether eight points can form a cube. We can enumerate each point and figure out the other points to his distance.
If the distance is x x x root two x square root two x square root two x root root three x this form must be a cube.
1#include <cstdio>2 3#include <iostream>4 5#include <cmath>6 7#include <cstring>8 9#include <algorithm>Ten One using namespacestd; A -typedefLong LongLL; - theLL map[Ten][5]; - -LL a[Ten]; - + - +LL Dist (intXinty) A at { - - return(map[x][1]-map[y][1]) * (map[x][1]-map[y][1]) + (map[x][2]-map[y][2]) * (map[x][2]-map[y][2]) + (map[x][3]-map[y][3]) * (map[x][3]-map[y][3]); - - } - in intWorkintx) - to { + - intnum=0; the * for(intI=1; i<=8;++i) $ Panax Notoginseng { - the if(i==x)Continue; + A++num;a[num]=Dist (i,x); the + } - $Sort (A +1, A +1+num); $ - if(a[1]==0|| a[1]!=a[2]|| a[1]!=a[3]|| a[4]!=a[5]|| a[4]!=a[6]|| a[4]!=2*a[1]|| a[7]!=3*a[1])return 0; - the return 1; - Wuyi } the - intCheck () Wu - { About $ for(intI=1; i<=8; ++i)if(!work (i))return 0; - -printf"yes\n"); - A for(intI=1; i<=8;++i) + the { - $ for(intj=1; j<=3; ++j) printf ("%i64d", Map[i][j]); the theprintf"\ n"); the the - in } the the return 1; About the } the the intDfsintx) + - { the Bayi if(x==9)returncheck (); the theSort (map[x]+1, map[x]+4); - - Do the the { the the if(Dfs (x+1))return 1;; - the} while(Next_permutation (map[x]+1, map[x]+4)); the the return 0;94 the } the the intMain ()98 About { - 101 for(intI=1; i<=8;++i)102 103 for(intj=1; j<=3; ++j) scanf ("%i64d",&map[i][j]);104 the if(!dfs (1)) printf ("no\n");106 107 return 0;108 109}
View Code
C substitutes in number
Test instructions: Give a number, and now give a lot of replacements, for a replacement: Ask for a number from 0 to 9 all into the number T (can be empty), the last transformed number mod (1e9+7).
The puzzle: Suppose we finally get the number corresponding to each number, then we can directly convert from the initial number to the final result. (not to be continued)
Codeforces Round #265 (Div. 1)