# hdu5755 2016 Multi-University Training Contest 3 Gambler Bo 解题报告

code：

#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<ctime>
#include<cmath>
#include<vector>
#include<string>
#include<bitset>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
using namespace std;

const int Mod = 3;
const int maxn = 1010;
struct E
{
int a[maxn],s;
}f[maxn],zero,tmp;
int x[maxn];
int n,m,num;
int N[3] = {0,1,2};

void G( int now )
{
if( now == num )
{
x[now] = ( f[now].s*N[ f[now].a[now] ] )%Mod;
return ;
}
if( f[now].a[now] == 0 )
{
for( int i=now+1;i<=num;i++ )
if( f[i].a[now] != 0 )
{
tmp = f[now];
f[now] = f[i];
f[i] = tmp;
break;
}
}
for( int i=now+1;i<=num;i++ )
{
if( f[i].a[now] != 0 )
{
int t1 = f[now].a[now], t2 = f[i].a[now];
for( int j=1;j<=num;j++ )
{
f[i].a[j] *= t1;
f[i].a[j] -= f[now].a[j]*t2;
f[i].a[j] %= Mod;
if( f[i].a[j] < 0 ) f[i].a[j] += Mod;
}
f[i].s = f[i].s*t1 - f[now].s*t2;
f[i].s %= Mod;
if( f[i].s < 0 ) f[i].s += Mod;
}
}
}
void get_x( int now )
{
for( int i=now+1;i<=num;i++ ) f[now].s -= f[now].a[i]*x[i];
f[now].s %= Mod;
x[now] = ( f[now].s*N[ f[now].a[now] ] )%Mod;
}

int main()
{
memset( zero.a,0,sizeof zero.a ); zero.s = 0;

int t,ct;
scanf("%d",&t);
while( t-- )
{
memset( x,0,sizeof x );
scanf("%d%d",&n,&m);
num = n*m;
for( int i=1;i<=n;i++ )
{
for( int j=1;j<=m;j++ )
{
scanf("%d",&ct);
int id = (i-1)*m+j; f[id] = zero;
f[id].s = (Mod-ct)%Mod;
f[id].a[id] = 2;
if( i>1 ) f[id].a[id-m] = 1;
if( i<n ) f[id].a[id+m] = 1;
if( j>1 ) f[id].a[id-1] = 1;
if( j<m ) f[id].a[id+1] = 1;
}
}

for( int i=1;i<=num;i++ ) G( i );
for( int i=num-1;i>=1;i-- ) get_x( i );

int ret = 0;
for( int i=1;i<=num;i++ )
{
if( x[i] < 0 ) x[i] += 3;
ret += x[i];
}

printf("%d\n",ret);
for( int i=1;i<=n;i++ )
{
for( int j=1;j<=m;j++ )
{
int id = (i-1)*m+j;
while( x[id] )
{
printf("%d %d\n",i,j);
x[id]--;
}
}
}
}

return 0;
}


#### 2016 Multi-University Training Contest 1题解报告

2016-07-19 18:47:56

#### 2017 Multi-University Training Contest 3

2017-08-01 19:08:44

#### 2016 Multi-University Training Contest 8（2016多校训练第八场）1011

2016-08-11 21:06:09

#### 2016 Multi-University Training Contest 2----解题报告

2016-07-22 09:09:01

#### 2016 Multi-University Training Contest 2 Acperience

2016-07-21 16:06:26

#### 2013 Multi-University Training Contest 3 (g) The Unsolvable Problem

2013-09-19 15:00:25

#### 2016 Multi-University Training Contest 1----解题报告

2016-07-20 10:33:42

#### 2016 Multi-University Training Contest 2（补题ing）

2016-07-22 21:48:03

#### HDU 3902 Swordsman 2011 Multi-University Training Contest 7 - Host by ECNU 计算几何

2011-08-04 00:50:56

#### 2012 Multi-University Training Contest

2013-07-20 15:41:21