思维题 Gym 100553A Alter Board

 

题目传送门

 1 /*  2  题意:一个n×m的矩形,相邻的颜色不同,黑或白。问最少的翻转次数,每次翻转可指定任意一个子矩形  3  思维题:最少要把偶数行和列翻转,也就是n/2+m/2次  4 */  5 #include <cstdio>  6 using namespace std;  7  8 int main(void) //Gym 100553A Alter Board  9 { 10 // freopen ("A.in", "r", stdin); 11 freopen ("alter.in", "r", stdin); 12 freopen ("alter.out", "w", stdout); 13 14 int n, m; 15 while (scanf ("%d%d", &n, &m) == 2) 16  { 17 printf ("%d\n", n / 2 + m / 2); 18 for (int i=2; i<=n; i+=2) 19  { 20 printf ("%d %d %d %d\n", i, 1, i, m); 21  } 22 for (int i=2; i<=m; i+=2) 23  { 24 printf ("%d %d %d %d\n", 1, i, n, i); 25  } 26  } 27 28 return 0; 29 }

 

你可能感兴趣的:(alter)