Cod sursa(job #1448043)

Utilizator BopecovBolocan Petre Cosmin Vlad Bopecov Data 5 iunie 2015 23:26:12
Problema Jocul Flip Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.26 kb
#include <iostream>
#include <fstream>

using namespace std;

double sum_collumn(double a[16][16], int m, int j, int r){
	double suma = 0;
	for (int i = 0; i < m; i++)
		suma = suma + a[j][i]*r;
	return suma;
};

double sum_row(double a[16][16], int n, int j, int r){
	double suma = 0;
	for (int i = 0; i < n; i++)
		suma = suma + a[i][j]*r;
	return suma;
};

int main(){
	int n, m;
	double a[16][16];
	ifstream ifile("flip.in");
	ofstream ofile("flip.out");

	ifile >> n >> m;

	for (int i = 0; i < n; i++)
	for (int j = 0; j < m; j++)
		ifile >> a[i][j];
		
	int gata = 1;
	while (gata){
		gata = 0;
		
		for (int i = 0; i < n; i++){
			if (sum_collumn(a, m, i, 1) < sum_collumn(a, m, i, -1)){
				for (int q = 0; q < m; q++) a[i][q] *= (-1);
				gata = 1;
			}
		}

		for (int i = 0; i < m; i++){
			if (sum_row(a, n, i, 1) <sum_row(a, n, i, -1)){
				for (int q = 0; q < n; q++) a[q][i] = a[q][i] * (-1);
				gata = 1;
			}
		}
		}

	double suma = 0;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++)
			suma += a[i][j];
	}

	ofile << suma;
	cout.flush();

	//cout << n << endl << m << endl;
	
	//outf << atoi(a) + atoi(b);
	//cout.flush();
	//intr.close();
	//outf.close();
	//cout << endl;
	//system("pause");
}