Cod sursa(job #542391)

Utilizator andunhillMacarescu Sebastian andunhill Data 26 februarie 2011 12:54:25
Problema Pixels Scor 0
Compilator cpp Status done
Runda Romanian Master in Mathematics and Sciences 2011, Ziua 2 Marime 1.33 kb
#include<fstream>
using namespace std;
ifstream f("pixels.in");
ofstream g("pixels.out");
struct dif 
{	int sus,dr,jos,st;
};
int N;
int A[101][101];
int B[101][101];
dif a[101][101];
char mat[101][101];
void read(int N,int a[101][101])
{	int i,j;
	for(i=1;i<=N;i++)
		for(j=1;j<=N;j++)
			f>>a[i][j];
}
int maxx(int a,int b,int c,int d)
{	int m;
	m=max(a,max(b,max(c,d)));
	return m;
}
int main()
{	int i,j,alb,neg;
	int sa,sn,sd; sa=sn=sd=0;
	f>>N;
	read(N,A);
	read(N,B);
	for(i=1;i<=N;i++)
		for(j=1;j<=N;j++)
			f>>a[i][j].sus>>a[i][j].dr>>a[i][j].jos>>a[i][j].st;
	for(i=1;i<=N;i++)
		for(j=1;j<=N;j++)
		{	alb=maxx(A[i][j]+B[i][j+1]+B[i+1][j]-a[i][j].dr-a[i][j].jos,
					A[i][j]+B[i][j+1]+A[i+1][j]-a[i][j].dr,
					A[i][j]+A[i][j+1]+B[i+1][j]-a[i][j].jos,
					A[i][j]+A[i][j+1]+A[i+1][j]);
			neg=maxx(B[i][j]+A[i][j+1]+A[i+1][j]-a[i][j].dr-a[i][j].jos,
					B[i][j]+A[i][j+1]+B[i+1][j]-a[i][j].dr,
					B[i][j]+B[i][j+1]+A[i+1][j]-a[i][j].jos,
					B[i][j]+B[i][j+1]+B[i+1][j]);
			if(alb<=neg)
				mat[i][j]='N';
			else mat[i][j]='A';
		}
	for(i=1;i<=N;i++)
		for(j=1;j<=N;j++)
		{	if(mat[i][j]=='A')
				sa+=A[i][j];
			else sn+=B[i][j];
			if(mat[i][j]!=mat[i-1][j]) sd+=a[i][j].sus;
			if(mat[i][j]!=mat[i][j+1]) sd+=a[i][j].dr;
		}
	g<<sa+sn-sd;
	f.close();
	g.close();
	return 0;
}