Cod sursa(job #2583187)
Utilizator | Data | 17 martie 2020 21:00:34 | |
---|---|---|---|
Problema | Jocul Flip | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 1.99 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("flip.in");
ofstream g("flip.out");
int main()
{
float N,M,st,OK=1,s1=0,s2=0;
int i,j;
f>>N>>M;
int a[999][999],b[999][999];
for(i=1; i<=N; i++)
{
for(j=1; j<=M; j++)
{
f>>a[i][j];
f>>b[i][j];
}
}
while(OK)
{
OK=1;
for(j=1; j<=M; j++){
st=0;
for(i=1; i<=N; i++)
{
st+=a[i][j];
}
if(st<=0)
{
OK=0;
for(i=1; i<=N; i++)
{
a[i][j]*=-1;
}
}
}
for(j=1; j<=N; j++){
st=0;
for(i=1; i<=M; i++)
{
st+=a[j][i];
}
if(st<=0)
{
OK=0;
for(i=1; i<=M; i++)
{
a[j][i]*=-1;
}
}
}
}
OK=1;
while(OK)
{
OK=1;
for(j=1; j<=N; j++){
st=0;
for(i=1; i<=M; i++)
{
st+=b[j][i];
}
if(st<=0)
{
OK=0;
for(i=1; i<=M; i++)
{
b[j][i]*=-1;
}
}
}
for(j=1; j<=M; j++){
st=0;
for(i=1; i<=N; i++)
{
st+=b[i][j];
}
if(st<=0)
{
OK=0;
for(i=1; i<=N; i++)
{
b[i][j]*=-1;
}
}
}
}
for(i=1; i<=N; i++)
{
for(j=1; j<=M; j++)
{
s1+=a[i][j];
s2+=b[i][j];
}
}
if(s1>s2){g<<s1;}
else g<<s2;
f.close();
g.close();
}