Topic Address: http://codeforces.com/contest/1255/problem/D
Meaning of the questions: k chickens to decimeter, there are some places where there is no rice rice, chicken all points of difference to the smallest, to even up the score can be regarded as a collection.
Idea: to traverse the map again, the key is to go bow-shaped, so we can guarantee to each chicken together. Provided m total sum, the bird can be divided sum / k to block has m. sum% k of sharing it wants (see here to understand the code).
AC Code:
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 using namespace std; 6 typedef long long ll; 7 char s[63]; 8 void sol(){ 9 int r,c,k; 10 scanf("%d%d%d",&r,&c,&k); 11 char maps[101][101]; 12 for(int i=0;i<r;i++) 13 scanf("%s",maps[i]); 14 int sum=0; 15 for(int i=0;i<r;i++) 16 for(int j=0;j<c;j++) 17 if(maps[i][j]=='R') sum++; 18 int a=0,b=0; 19 for(int i=0;i<r;i++){ 20 is IF (I & . 1 ) { 21 is for ( int J = 0 ; J <C; J ++ ) { 22 is IF (B + (Maps [I] [J] == ' R & lt ' )> ((A <SUM% K)? (SUM / K + . 1 ) :( SUM / K))) { // first partial sum% k th sum / k + 1, the remaining sub-SUM / K 23 is a ++ ; 24 Maps [I] [J] = S [ A]; 25 B = . 1 ; 26 is } 27 the else { 28 B = + (Maps [I] [J] == ' R & lt' ); // for each assigned to a recorded bit with a meter 29 Maps [I] [J] = S [A]; 30 } 31 is } 32 } 33 is the else { 34 is for ( int J = the C- . 1 ; J> = 0 ; J, ) { 35 IF (B + (Maps [I] [J] == ' R & lt ' )> (? (A <SUM% K) (SUM / K + . 1 ) :( SUM / K))) { 36 A ++ ; 37 [ Maps [I] [J] = S [A]; 38 is b=1; 39 } 40 else{ 41 b+=(maps[i][j]=='R'); 42 maps[i][j]=s[a]; 43 } 44 } 45 } 46 } 47 for(int i=0;i<r;i++){ 48 for(int j=0;j<c;j++) 49 printf("%c",maps[i][j]); 50 printf("\n"); 51 } 52 } 53 int main(){ 54 int T; 55 cin>>T; 56 for(int i=0;i<62;i++){ 57 if(i<26) s[i]=i+'a'; 58 else if(i<52) s[i]=i-26+'A'; 59 else s[i]=i-52+'0'; 60 } 61 while(T--) sol(); 62 return 0; 63 }