Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- using namespace std;
- long rot[1000][1000], stag[1000][1000];
- typedef struct{
- int brojPoklapajucih, rotiranja;
- }maksZaRotiranje;
- int rotdCOUNT(long rot[][1000], long stat[][1000], int n){
- int cnt = 0;
- for(int i = 0; i < n; i++){
- for(int j = 0; j < n; j++){
- if(rot[i][j] == stat[i][j]){
- cnt++;
- }
- }
- }
- return cnt;
- }
- void prtmat(long mat[][1000], int n){
- for(int i = 0; i < n; i++){
- for(int j = 0; j < n; j++){
- cout << mat[i][j] << " ";
- }
- }
- cout << endl;
- }
- void rota(long rotp[][1000], int n){
- long help[n][n]; int b = 0;
- for(int i = 0; i < n; i++){
- b = 0;
- for(int j = n - 1; j >= 0; j--){
- help[i][b] = rotp[j][i];
- ++b;
- }
- }
- for(int i = 0; i < n; i++){
- for(int j = 0; j < n; j++){
- rotp[i][j] = help[i][j];
- }
- }
- prtmat(rotp, n);
- }
- int main(){
- int n;
- cout << "n" << endl;
- cin >> n;
- cout << "rot" << endl;
- for(int i = 0; i < n; i++){
- for(int j = 0; j < n; j++){
- cin >> rot[i][j];
- }
- }
- cout << "stag" << endl;
- for(int i = 0; i < n; i++){
- for(int j = 0; j < n; j++){
- cin >> stag[i][j];
- }
- }
- if(n == 1){
- if(rot[0][0] == stag[0][0]) cout << 0;
- else cout << 1;
- return 0;
- }
- maksZaRotiranje starimaks, novimaks;
- starimaks.brojPoklapajucih = 0; starimaks.rotiranja = 0;
- novimaks.brojPoklapajucih = 0; novimaks.rotiranja = 0;
- prtmat(rot, n);
- int oof, oonf;
- for(int i = 0; i < 4; i++){
- novimaks.brojPoklapajucih = rotdCOUNT(rot, stag, n);
- novimaks.rotiranja = i;
- cout << "rodtcound, rotiranja " << novimaks.brojPoklapajucih << " " << novimaks.rotiranja << endl;
- prtmat(rot, n);
- oof = novimaks.brojPoklapajucih - novimaks.rotiranja;
- oonf = starimaks.brojPoklapajucih - starimaks.rotiranja;
- if(oof > oonf){
- starimaks.brojPoklapajucih = novimaks.brojPoklapajucih;
- starimaks.rotiranja = novimaks.rotiranja;
- }
- rota(rot, n);
- }
- int resenje = (n*n - starimaks.brojPoklapajucih) + starimaks.rotiranja;
- cout << "najkrace je " << resenje << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment