考试复盘
T 1 T1 T1
我可太喜欢这种不要脑子的莽试题了!!
考场上猜的结论 d > 3 d>3 d>3无解
d = 1 , d = 2 d=1,d=2 d=1,d=2的填法也试出来了
d = 3 d=3 d=3只试出来了 n , m n,m n,m是 3 3 3的倍数的填法
但是另外的情况就 G G GG GG了
最后交上去竟然还敲挂了(ˉ▽ˉ;)…乌鸡鲅鱼
这道题应该是这一段考试以来唯几接近整正解的题目了
思考的:大讨论,猜结论
T 2 T2 T2
发现了很多小性质,想到了与根号有关的因子上面去
但是,呃emmmmmm~~
我不知道这个集合应该怎么填
所以找到的那些小性质并没有什么卵用
(和善的微笑
思考的:质数/因子有关的各种算法, D P DP DP
T 3 T3 T3
考场上敲得暴力——又挂了w(゚Д゚)waz
链想的树形 D P DP DP但是也没打,没想明白
看到无环的部分分也想不出做法
思考的: t a r j a n tarjan tarjan强连通,树形 D P DP DP,暴力,后缀数组(纯粹是看到了字符串比较
nmd
大讨论好哇b( ̄▽ ̄)d
-
n , m , d n,m,d n,m,d都是奇数
− 1 -1 −1
-
d > 3 d>3 d>3
− 1 -1 −1
在考场上肯定是猜的结论,就是反复试啊,就是连不出来
从 ( 1 , 1 ) (1,1) (1,1)先开始满足,要往外连 > 3 >3 >3条线,肯定跨越了一个小正方格
感性理解都感觉最后几行会有点被困住连不出去
-
d = 1 d=1 d=1
-
点数为奇数
− 1 -1 −1
-
点数为偶数
相邻两个连边即可
-
-
d = 2 d=2 d=2
- 点数为奇数
- 点数为偶数
- 点数为奇数
-
d = 3 d=3 d=3
-
n = 3 n=3 n=3
-
m = 4 m=4 m=4
− 1 -1 −1
-
m = 6 m=6 m=6
-
o t h e r w i s e otherwise otherwise
排除掉两边的对称,中间一定是偶数列,两两配对即可
-
-
n , m n,m n,m为偶数
-
o t h e r w i s e otherwise otherwise
-
m
=
5
m=5
m=5
-
o
t
h
e
r
w
i
s
e
otherwise
otherwise
-
m
=
5
m=5
m=5
-
代码虽然有三百多行,7K大,但是是非常不动脑子的莽敲,请不要感到害怕,ㄟ(▔=▔)ㄏ
#include <cstdio>
#include <iostream>
using namespace std;
int T, n, m, d;
bool flag;
void print( int x1, int y1, int x2, int y2 ) {
if( flag ) printf( "%d %d %d %d\n", y1, x1, y2, x2 );
else printf( "%d %d %d %d\n", x1, y1, x2, y2 );
}
void subtask1() {
printf( "%d\n", ( n * m ) >> 1 );
if( n & 1 ) swap( n, m ), flag = 1;
for( int i = 1;i <= n;i ++ )
for( int j = 1;j <= m;j ++ )
if( i & 1 )
print( i, j, i + 1, j );
}
void subtask2() {
printf( "%d\n", ( n * m * d ) >> 1 );
if( ( n & 1 ) && ( m & 1 ) ) {
//red
print( 1, 1, 2, 2 );
print( n, 1, n, 2 );
//yellow
for( int i = 1;i < n;i ++ )
print( i, 1, i + 1, 1 );
//blue
for( int i = 3;i <= n;i ++ )
for( int j = 2;j < m;j ++ )
print( i, j, i, j + 1 );
//green
for( int i = 3;i <= n;i ++ )
if( ( n - i + 1 ) & 1 )
print( i, m, i - 1, m );
else
print( i, 2, i - 1, 2 );
//pink
for( int i = 2;i <= m;i ++ )
print( 1, i, 2, i );
//orange
for( int i = 2;i < m;i ++ )
if( i & 1 )
print( 2, i, 2, i + 1 );
else
print( 1, i, 1, i + 1 );
}
else {
if( n & 1 ) swap( n, m ), flag = 1;
//red
print( 1, 1, 1, 2 );
print( n, 1, n, 2 );
//yellow
for( int i = 1;i < n;i ++ )
print( i, 1, i + 1, 1 );
//blue
for( int i = 1;i <= n;i ++ )
for( int j = 2;j < m;j ++ )
print( i, j, i, j + 1 );
//green
for( int i = 1;i < n;i ++ )
if( i & 1 )
print( i, m, i + 1, m );
else
print( i, 2, i + 1, 2 );
}
}
void subtask3_0() {
if( n != 3 ) swap( n, m ), flag = 1;
if( m == 4 ) {
printf( "-1\n" );
return;
}
printf( "%d\n", ( n * m * d ) >> 1 );
//red
print( 1, 1, 2, 1 );
print( 2, 1, 3, 1 );
print( 1, m, 2, m );
print( 2, m, 3, m );
for( int i = 1;i < m;i ++ )
print( 1, i, 1, i + 1 ), print( 3, i, 3, i + 1 );
if( m == 6 ) {
print( 1, 1, 2, 2 );
print( 2, 1, 2, 2 );
print( 3, 1, 2, 2 );
print( 1, 2, 2, 3 );
print( 3, 2, 2, 3 );
print( 3, 3, 2, 3 );
print( 1, 6, 2, 5 );
print( 2, 6, 2, 5 );
print( 3, 6, 2, 5 );
print( 1, 5, 2, 4 );
print( 1, 4, 2, 4 );
print( 3, 5, 2, 4 );
print( 1, 3, 3, 4 );
}
else {
//yellow
print( 1, 1, 2, 2 );
print( 2, 1, 2, 2 );
print( 3, 1, 2, 2 );
print( 1, 2, 2, 3 );
print( 1, 3, 2, 3 );
print( 3, 2, 2, 3 );
print( 1, 4, 2, 4 );
print( 3, 3, 2, 4 );
print( 3, 4, 2, 4 );
//green
for( int i = 5;i <= m - 4;i ++ )
print( 1, i, 2, i ), print( 2, i, 3, i );
//pink
for( int i = 5;i <= m - 4;i ++ )
if( i & 1 )
print( 2, i, 2, i + 1 );
//blue
print( 1, m, 2, m - 1 );
print( 2, m, 2, m - 1 );
print( 3, m, 2, m - 1 );
print( 1, m - 1, 2, m - 2 );
print( 1, m - 2, 2, m - 2 );
print( 3, m - 1, 2, m - 2 );
print( 1, m - 3, 2, m - 3 );
print( 3, m - 3, 2, m - 3 );
print( 3, m - 2, 2, m - 3 );
}
}
void subtask3_1() {
printf( "%d\n", ( n * m * d ) >> 1 );
if( ! ( n & 1 ) && ! ( m & 1 ) ) {
//red
print( 1, 1, 2, 2 );
print( 1, m, 2, m - 1 );
//yellow
for( int i = 1;i < m;i ++ )
print( 1, i, 1, i + 1 );
//green
for( int i = 1;i <= m;i ++ )
print( 1, i, 2, i );
//blue
for( int i = 1;i <= m;i ++ )
if( i & 1 )
print( 2, i, 2, i + 1 );
for( int i = 2;i <= n - 2;i ++ ) {
//pink
print( i, 1, i + 1, 1 );
print( i, m, i + 1, m );
if( i & 1 ) {
//grey
print( i, 2, i + 1, 2 );
print( i, m - 1, i + 1, m - 1 );
//orange
for( int j = 1;j < m;j ++ )
print( i, j, i, j + 1 );
//purple
for( int j = 1;j < m;j ++ )
print( i + 1, j, i + 1, j + 1 );
}
else {
//black
for( int j = 3;j <= m - 2;j ++ )
print( i, j, i + 1, j );
}
}
//red
print( n, 1, n - 1, 2 );
print( n, m, n - 1, m - 1 );
//yellow
for( int i = 1;i < m;i ++ )
print( n, i, n, i + 1 );
//green
for( int i = 1;i <= m;i ++ )
print( n, i, n - 1, i );
//blue
for( int i = 1;i <= m;i ++ )
if( i & 1 )
print( n - 1, i, n - 1, i + 1 );
}
else {
if( n & 1 ) swap( n, m ), flag = 1;
if( m == 5 ) {
//red
print( 1, 1, 2, 2 );
print( 1, 1, 2, 1 );
print( 2, 1, 2, 2 );
print( 1, 2, 2, 3 );
print( 1, 3, 2, 3 );
print( 1, m, 2, m - 1 );
//yellow
for( int i = 1;i < m;i ++ )
print( 1, i, 1, i + 1 );
//green
for( int i = 4;i <= m;i ++ )
print( 1, i, 2, i );
//blue
for( int i = 4;i <= m;i ++ )
if( ! ( i & 1 ) )
print( 2, i, 2, i + 1 );
for( int i = 2;i <= n - 2;i ++ ) {
//pink
print( i, 1, i + 1, 1 );
print( i, m, i + 1, m );
if( i & 1 ) {
//grey
print( i, m - 1, i + 1, m - 1 );
//orange
for( int j = 1;j < m;j ++ )
print( i, j, i, j + 1 );
//purple
for( int j = 1;j < m;j ++ )
print( i + 1, j, i + 1, j + 1 );
}
else {
//black
for( int j = 2;j <= m - 2;j ++ )
print( i, j, i + 1, j );
}
}
//red
print( n, 1, n - 1, 1 );
print( n, 1, n - 1, 2 );
print( n - 1, 1, n - 1, 2 );
print( n, 2, n - 1, 3 );
print( n, 3, n - 1, 3 );
print( n, m, n - 1, m - 1 );
//yellow
for( int i = 1;i < m;i ++ )
print( n, i, n, i + 1 );
//green
for( int i = 4;i <= m;i ++ )
print( n, i, n - 1, i );
//blue
for( int i = 4;i <= m;i ++ )
if( ! ( i & 1 ) )
print( n - 1, i, n - 1, i + 1 );
}
else {
//red
print( 1, 1, 2, 2 );
print( 2, 1, 2, 2 );
print( 2, 3, 2, 4 );
print( 1, m, 2, m - 1 );
//yellow
for( int i = 1;i < m;i ++ )
print( 1, i, 1, i + 1 );
//green
for( int i = 1;i <= m;i ++ )
print( 1, i, 2, i );
//blue
for( int i = 4;i <= m;i ++ )
if( ! ( i & 1 ) )
print( 2, i, 2, i + 1 );
for( int i = 2;i <= n - 2;i ++ ) {
//pink
print( i, 1, i + 1, 1 );
print( i, m, i + 1, m );
if( i & 1 ) {
//grey
print( i, 2, i + 1, 2 );
print( i, 4, i + 1, 4 );
print( i, m - 1, i + 1, m - 1 );
//orange
for( int j = 1;j < m;j ++ )
print( i, j, i, j + 1 );
//purple
for( int j = 1;j < m;j ++ )
print( i + 1, j, i + 1, j + 1 );
}
else {
//black
print( i, 3, i + 1, 3 );
for( int j = 5;j <= m - 2;j ++ )
print( i, j, i + 1 , j);
}
}
//red
print( n, 1, n - 1, 2 );
print( n - 1, 1, n - 1, 2 );
print( n - 1, 3, n - 1, 4 );
print( n, m, n - 1, m - 1 );
//yellow
for( int i = 1;i < m;i ++ )
print( n, i, n, i + 1 );
//green
for( int i = 1;i <= m;i ++ )
print( n, i, n - 1, i );
//blue
for( int i = 4;i <= m;i ++ )
if( ! ( i & 1 ) )
print( n - 1, i, n - 1, i + 1 );
}
}
}
int main() {
freopen( "nmd.in", "r", stdin );
freopen( "nmd.out", "w", stdout );
scanf( "%d", &T );
while( T -- ) {
scanf( "%d %d %d", &n, &m, &d );
if( ( d > 3 ) || ( ( d & 1 ) && ( n & 1 ) && ( m & 1 ) ) )
printf( "-1\n" );
else if( d == 1 )
subtask1();
else if( n == 1 || m == 1 )
printf( "-1\n" );
else if( d == 2 )
subtask2();
else if( n == 2 || m == 2 )
printf( "-1\n" );
else if( n == 3 || m == 3 )
subtask3_0();
else
subtask3_1();
flag = 0;
}
return 0;
}