Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <algorithm>
- #include <string.h>
- using namespace std;
- char order[]="BGC";
- int mat[3][3];
- char bestBot[5] = "GCB";
- int bot[3] = {0,1,2};
- long long sum=(1LL<<32);
- void lowerString(int qtd) {
- char tmp[5]="";
- for (int i=0; i<3; i++)
- tmp[i]=order[bot[i]];
- tmp[3]='\0';
- if (strcmp(tmp,bestBot)<0 || qtd<sum)
- strcpy(bestBot,tmp);
- }
- long long countExc() {
- long long s=0;
- for (int i=0; i<3; i++)
- for (int j=0; j<3; j++)
- if (j!=bot[i]) s+=mat[i][j];
- return s;
- }
- int main() {
- while (scanf("%d", &mat[0][0])!=EOF) {
- sum=(1LL<<32);
- strcpy(bestBot,"GCB");
- for (int i=0; i<3; i++)
- for (int j=0; j<3; j++)
- if (i || j) scanf("%d", &mat[i][j]);
- do {
- long long tmp=countExc();
- if (tmp<=sum) {
- lowerString(tmp);
- sum=tmp;
- }
- } while (next_permutation(bot, bot+3));
- printf("%s %lld\n", bestBot,sum);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement