文章目录
- 考试复盘
- nmd
考试复盘
T1T1T1
我可太喜欢这种不要脑子的莽试题了!!
考场上猜的结论d>3d>3d>3无解
d=1,d=2d=1,d=2d=1,d=2的填法也试出来了
d=3d=3d=3只试出来了n,mn,mn,m是333的倍数的填法
但是另外的情况就GGGGGG了
最后交上去竟然还敲挂了(ˉ▽ˉ;)…乌鸡鲅鱼
这道题应该是这一段考试以来唯几接近整正解的题目了
思考的:大讨论,猜结论
T2T2T2
发现了很多小性质,想到了与根号有关的因子上面去
但是,呃emmmmmm~~
我不知道这个集合应该怎么填
所以找到的那些小性质并没有什么卵用
(和善的微笑
思考的:质数/因子有关的各种算法,DPDPDP
T3T3T3
考场上敲得暴力——又挂了w(゚Д゚)waz
链想的树形DPDPDP但是也没打,没想明白
看到无环的部分分也想不出做法
思考的:tarjantarjantarjan强连通,树形DPDPDP,暴力,后缀数组(纯粹是看到了字符串比较
nmd
大讨论好哇b( ̄▽ ̄)d
-
n,m,dn,m,dn,m,d都是奇数
−1-1−1
-
d>3d>3d>3
−1-1−1
在考场上肯定是猜的结论,就是反复试啊,就是连不出来
从(1,1)(1,1)(1,1)先开始满足,要往外连>3>3>3条线,肯定跨越了一个小正方格
感性理解都感觉最后几行会有点被困住连不出去
-
d=1d=1d=1
-
点数为奇数
−1-1−1
-
点数为偶数
相邻两个连边即可
-
-
d=2d=2d=2
- 点数为奇数
- 点数为偶数
- 点数为奇数
-
d=3d=3d=3
-
n=3n=3n=3
-
m=4m=4m=4
−1-1−1
-
m=6m=6m=6
-
otherwiseotherwiseotherwise
排除掉两边的对称,中间一定是偶数列,两两配对即可
-
-
n,mn,mn,m为偶数
-
otherwiseotherwiseotherwise
- m=5m=5m=5
- otherwiseotherwiseotherwise
- m=5m=5m=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 ) ) {//redprint( 1, 1, 2, 2 );print( n, 1, n, 2 );//yellowfor( int i = 1;i < n;i ++ )print( i, 1, i + 1, 1 );//bluefor( int i = 3;i <= n;i ++ )for( int j = 2;j < m;j ++ )print( i, j, i, j + 1 );//greenfor( int i = 3;i <= n;i ++ )if( ( n - i + 1 ) & 1 )print( i, m, i - 1, m );elseprint( i, 2, i - 1, 2 );//pinkfor( int i = 2;i <= m;i ++ )print( 1, i, 2, i ); //orangefor( int i = 2;i < m;i ++ )if( i & 1 )print( 2, i, 2, i + 1 );elseprint( 1, i, 1, i + 1 );} else {if( n & 1 ) swap( n, m ), flag = 1;//redprint( 1, 1, 1, 2 );print( n, 1, n, 2 );//yellowfor( int i = 1;i < n;i ++ )print( i, 1, i + 1, 1 );//bluefor( int i = 1;i <= n;i ++ )for( int j = 2;j < m;j ++ )print( i, j, i, j + 1 );//greenfor( int i = 1;i < n;i ++ )if( i & 1 )print( i, m, i + 1, m );elseprint( 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 {//yellowprint( 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 );//greenfor( int i = 5;i <= m - 4;i ++ )print( 1, i, 2, i ), print( 2, i, 3, i );//pinkfor( int i = 5;i <= m - 4;i ++ )if( i & 1 )print( 2, i, 2, i + 1 );//blueprint( 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 ) ) {//redprint( 1, 1, 2, 2 );print( 1, m, 2, m - 1 );//yellowfor( int i = 1;i < m;i ++ )print( 1, i, 1, i + 1 );//greenfor( int i = 1;i <= m;i ++ )print( 1, i, 2, i );//bluefor( int i = 1;i <= m;i ++ )if( i & 1 )print( 2, i, 2, i + 1 );for( int i = 2;i <= n - 2;i ++ ) {//pinkprint( i, 1, i + 1, 1 );print( i, m, i + 1, m );if( i & 1 ) {//greyprint( i, 2, i + 1, 2 );print( i, m - 1, i + 1, m - 1 );//orangefor( int j = 1;j < m;j ++ )print( i, j, i, j + 1 );//purplefor( int j = 1;j < m;j ++ )print( i + 1, j, i + 1, j + 1 );}else {//blackfor( int j = 3;j <= m - 2;j ++ )print( i, j, i + 1, j );}}//redprint( n, 1, n - 1, 2 );print( n, m, n - 1, m - 1 );//yellowfor( int i = 1;i < m;i ++ )print( n, i, n, i + 1 );//greenfor( int i = 1;i <= m;i ++ )print( n, i, n - 1, i );//bluefor( 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 ) {//redprint( 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 );//yellowfor( int i = 1;i < m;i ++ )print( 1, i, 1, i + 1 );//greenfor( int i = 4;i <= m;i ++ )print( 1, i, 2, i );//bluefor( int i = 4;i <= m;i ++ )if( ! ( i & 1 ) )print( 2, i, 2, i + 1 );for( int i = 2;i <= n - 2;i ++ ) {//pinkprint( i, 1, i + 1, 1 );print( i, m, i + 1, m );if( i & 1 ) {//greyprint( i, m - 1, i + 1, m - 1 );//orangefor( int j = 1;j < m;j ++ )print( i, j, i, j + 1 );//purplefor( int j = 1;j < m;j ++ )print( i + 1, j, i + 1, j + 1 );}else {//blackfor( int j = 2;j <= m - 2;j ++ )print( i, j, i + 1, j );}}//redprint( 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 );//yellowfor( int i = 1;i < m;i ++ )print( n, i, n, i + 1 );//greenfor( int i = 4;i <= m;i ++ )print( n, i, n - 1, i );//bluefor( int i = 4;i <= m;i ++ )if( ! ( i & 1 ) )print( n - 1, i, n - 1, i + 1 );}else {//redprint( 1, 1, 2, 2 );print( 2, 1, 2, 2 );print( 2, 3, 2, 4 );print( 1, m, 2, m - 1 );//yellowfor( int i = 1;i < m;i ++ )print( 1, i, 1, i + 1 );//greenfor( int i = 1;i <= m;i ++ )print( 1, i, 2, i );//bluefor( int i = 4;i <= m;i ++ )if( ! ( i & 1 ) )print( 2, i, 2, i + 1 );for( int i = 2;i <= n - 2;i ++ ) {//pinkprint( i, 1, i + 1, 1 );print( i, m, i + 1, m );if( i & 1 ) {//greyprint( i, 2, i + 1, 2 );print( i, 4, i + 1, 4 );print( i, m - 1, i + 1, m - 1 );//orangefor( int j = 1;j < m;j ++ )print( i, j, i, j + 1 );//purplefor( int j = 1;j < m;j ++ )print( i + 1, j, i + 1, j + 1 );}else {//blackprint( i, 3, i + 1, 3 );for( int j = 5;j <= m - 2;j ++ )print( i, j, i + 1 , j);}}//redprint( 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 );//yellowfor( int i = 1;i < m;i ++ )print( n, i, n, i + 1 );//greenfor( int i = 1;i <= m;i ++ )print( n, i, n - 1, i );//bluefor( 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();elsesubtask3_1();flag = 0;}return 0;
}