Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <algorithm>
- using namespace std;
- long long qtd, minQtd;
- int p[3];
- int tmpP[3];
- char str[5] ="BCG";
- long long b[3][3];
- long long count() {
- long long sum=0;
- for (int i=0; i<3; i++)
- for (int j=0; j<3; j++)
- if (j!=tmpP[i]) sum+=b[i][j];
- return sum;
- }
- int main() {
- while (scanf("%lld", &b[0][0])!=EOF) {
- for (int i=0; i<3; i++)
- for (int j=0; j<3; j++)
- if (i || j) scanf("%lld", &b[i][j]);
- for (int i=0; i<3; i++)
- swap(b[i][1],b[i][2]);
- for (int i=0; i<3; i++)
- tmpP[i]=i;
- minQtd=-1;
- do {
- qtd=count();
- if (qtd<minQtd || minQtd==-1) {
- for (int i=0; i<3; i++)
- p[i]=tmpP[i];
- minQtd=qtd;
- }
- } while (next_permutation(tmpP,tmpP+3));
- for (int i=0; i<3; i++)
- printf("%c", str[p[i]]);
- printf(" %lld\n", minQtd);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement