• ZOJ 3810 A Volcanic Island (2014年牡丹江赛区网络赛B题)


    1.题目描写叙述:点击打开链接

    2.解题思路:本题是四色定理的模板题。只是有几种情况要提前特判一下:n==1直接输出,1<n<5时候无解,n==6时候套用模板会出现同样的块。因此要特判一下。其它情况都能直接利用模板构造出来。

    3.代码:

    #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_back
    typedef long long ll;
    typedef unsigned int uint;
    typedef unsigned long long ull;
    typedef pair <int, int> P;
    
    
    
    const int N = 117;
    char mm[N][N];
    char col[2];
    int n;
    
    void solve()  //四色定理的模板
    {
    	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]);
    		printf("
    ");
    	}
    }
    
    int main()
    {
    	col[0] = 'G';
    	col[1] = 'R';
    	int T;
    	scanf("%d", &T);
    	while (T--)
    	{
    		scanf("%d", &n);
    		if (n == 1)printf("Y
    ");
    		else if (n <= 4)
    			printf("No solution!
    ");
    		else if (n == 6)
    		{
    			printf("YYYYYY
    ");
    			printf("GGRGRR
    ");
    			printf("GRRGRB
    ");
    			printf("GRGGRB
    ");
    			printf("GRGRRB
    ");
    			printf("GRGBBB
    ");
    		}
    		else solve();  //n==5和n>6时候能够直接使用模板构造
    	}
    }
    

  • 相关阅读:
    Apache Dubbo已不再局限于Java语言
    生产Server遭挖矿程序入侵,暴力占用CPU
    【转载】【原创】贵在,难在,成在
    【转载】【原创】生命中,要有自己的一方晴天
    (转)网上看的一篇文章,感觉会给程序员一些启发
    (转)在JSP客户端限制表单重复提交
    (转)用javascript做删除时的提示信息
    (转)上传自动显示图片 代码
    控制文字长度,多出的文字用省略号代替
    PS快捷键 未完
  • 原文地址:https://www.cnblogs.com/mthoutai/p/7220324.html
Copyright © 2020-2023  润新知