1. Title Description: Click to open the link
2. Problem-Solving ideas: The topic is a four-color theorem template problem, but there are several cases to advance special sentence: n==1 direct output, 1<n<5 time without solution, n==6 when the template will appear the same block, so to special sentence, other conditions can be directly used to construct the template.
3. Code:
#define _crt_secure_no_warnings#include<iostream> #include <algorithm> #include <cassert> #include <string> #include <sstream> #include <set> #include <vector> #include <stack> #include <map> #include <queue> #include <deque> #include <cstdlib> #include <cstdio> #include < cstring> #include <cmath> #include <ctime> #include <cctype> #include <functional>using namespace Std; #define ME (s) memset (s,0,sizeof (s)) #define PB push_backtypedef Long long ll;typedef unsigned int uint;typed EF unsigned long long ull;typedef pair <int, int> p;const int N = 117;char Mm[n][n];char col[2];int n;void Solve () The four-color theorem of the template {memset (mm, '. ', sizeof (mm)), for (int i = 0; i<n; i++) for (int j = 0; j<n; j + +) mm[i][j] = ' B '; for (int i = 0; i<n; i++) Mm[0][i] = ' Y '; for (int i = 0; i< (n-1)/2; i++) {char c = col[i% 2];for (int j = i + 1; j<n; + j) Mm[j][i] = C ; for (int j = 1; J <= i + 1; j + +) Mm[j][i + 1] = C;} for (int i =(n-1)/2; i<n-2; i++) {char c = col[i% 2];for (int j = i + 2; j<n; j + +) Mm[j][i] = c;mm[i + 2][i + 1] = c;for (int j = 2; J <= i + 2; J + +) Mm[j][i + 2] = C;} for (int i = 0; i<n; i++) {for (int j = 0; j<n; j + +) printf ("%c", Mm[i][j]);p rintf ("\ n");}} int main () {col[0] = ' G '; col[1] = ' R ', int t;scanf ("%d", &t), while (t--) {scanf ("%d", &n), if (n = = 1) printf ("y\n"); El Se if (n <= 4) printf ("No solution!\n"), else if (n = = 6) {printf ("yyyyyy\n");p rintf ("ggrgrr\n");p rintf ("grrgrb\n"); printf ("grggrb\n");p rintf ("grgrrb\n");p rintf ("grgbbb\n");} else solve (); N==5 and n>6 can be used to construct the template directly}}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
ZOJ 3810 A Volcanic Island (2014 Mudanjiang Division network game b)