Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <math.h>
- #include "stdio.h"
- #include <iostream>
- #include <string>
- #include <algorithm>
- using namespace std;
- typedef std::vector<double> Vec;
- typedef std::vector<std::vector<double> > Mat;
- int egyesek_szamolasa(Vec x) {
- int egyesek = 0;
- for(int c = 0; c < x.size(); c++) {
- if(x[c] == 1) {
- egyesek++;
- }
- }
- return egyesek;
- }
- void printVec(Vec a) {
- for(int i = 0; i < a.size(); i++) {
- printf("%0.lf ", a[i]);
- }
- }
- void printMat(Mat A) {
- for(int i = 0; i < A.size(); i++) {
- for(int j = 0; j < A[0].size(); j++) {
- printf("%0.lf ", A[i][j]);
- }
- printf("\n");
- }
- }
- Vec next_generated_vector(int n) {
- Vec x;
- for (int i = 23; i >= 0; i--) {
- int k = n >> i;
- if (k & 1){
- x.push_back(1);
- } else {
- x.push_back(0);
- }
- }
- return x;
- }
- void szamolas(Mat A) {
- //legenerlunk egy sorvektor
- int meddig = pow(2,24);
- Vec x;
- int kodszo = 0, egyesek=0;
- int min_egyesek=24;
- for(int k = 1; k < meddig; k++) {
- x = next_generated_vector(k);
- int sum = 0;
- for(int i = 0; i < 12; i++) {
- for(int j = 0; j < 24; j++) {
- sum += A[i][j] * x[j];
- }
- if (sum%2==1) {
- //printf(" A %d. sor osszege(mod2-ben) %d tehat kilepunk\n", i, sum);
- x.clear();
- sum = 0;
- break;
- }
- else if(sum%2==0 && i==11) {
- egyesek = egyesek_szamolasa(x);
- printVec(x);
- printf(" :%d\n", egyesek);
- if(egyesek <= min_egyesek) {
- min_egyesek = egyesek;
- }
- egyesek = 0;
- kodszo++;
- x.clear();
- }
- }
- }
- printf("%d. kodszo \n", kodszo);
- printf("Legkevesebb 1-est tartalmazo kodszo: %d\n", min_egyesek);
- }
- Mat transzponalj(Mat A) {
- Mat B;
- Vec x;
- float a;
- for(int i = 0; i < A.size(); i++) {
- for(int j = 0; j < A[0].size(); j++) {
- a = A[j][i];
- x.push_back(a);
- a = 0;
- }
- B.push_back(x);
- }
- return B;
- }
- int main()
- {
- Mat A;
- double q;
- Vec x;
- //Beolvasas
- for(int i = 0; i < 12; i++){
- for(int j = 0; j < 24; j++) {
- scanf("%lf", &q);
- x.push_back(q);
- }
- A.push_back(x);
- x.clear();
- }
- Mat B;
- //Levalasszuk amit transzponalni akarunk
- for(int i = 0; i < 12; i++) {
- q = 0;
- for(int j = 12; j < 24; j++) {
- double q = A[i][j];
- x.push_back(q);
- }
- B.push_back(x);
- x.clear();
- }
- transzponalj(B);
- //Levalasszuk az A matrix elejet
- Mat C;
- for(int i = 0; i < 12; i++) {
- q = 0;
- for(int j = 0; j < 12; j++) {
- double q = A[i][j];
- x.push_back(q);
- }
- C.push_back(x);
- x.clear();
- }
- //Fuzzok ossze a C Ês a B Matrixot
- Mat D;
- for(int i = 0; i < 12; i++) {
- for(int j = 0; j < 24; j++) {
- if(j<12) {
- double q = B[i][j];
- x.push_back(q);
- }
- else {
- double q = C[i][j-12];
- x.push_back(q);
- }
- }
- D.push_back(x);
- x.clear();
- }
- printf("\n");
- printMat(D);
- szamolas(D);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement