zoukankan      html  css  js  c++  java
  • HDU 5319 Painter

    题意:红色从左上向右下涂,蓝色从右上向左下涂,既涂红色又涂蓝色就变成绿色,问最少涂几下能变成给的图。

    解法:模拟一下就好了,注意细节。

    代码:

    #include<stdio.h>
    #include<iostream>
    #include<algorithm>
    #include<string>
    #include<string.h>
    #include<math.h>
    #include<limits.h>
    #include<time.h>
    #include<stdlib.h>
    #include<map>
    #include<queue>
    #include<set>
    #include<stack>
    #include<vector>
    #define LL long long
    using namespace std;
    int main()
    {
        int T;
        while(~scanf("%d", &T))
        {
            while(T--)
            {
                int n;
                scanf("%d", &n);
                string s[55];
                for(int i = 0; i < n; i++)
                    cin >> s[i];
                int m = s[0].size();
                int ans = 0;
                for(int i = 0; i < n; i++)
                {
                    for(int j = 0; j < m; j++)
                    {
                        if(s[i][j] == 'R')
                        {
                            ans++;
                            int x = i, y = j;
                            while(x < n && y < m && (s[x][y] == 'R' || s[x][y] == 'G'))
                            {
                                if(s[x][y] == 'R')
                                    s[x][y] = '.';
                                else
                                    s[x][y] = 'B';
                                x++;
                                y++;
                            }
                        }
                        else if(s[i][j] == 'B')
                        {
                            ans++;
                            int x = i, y = j;
                            while(x < n && y >= 0 && (s[x][y] == 'B' || s[x][y] == 'G'))
                            {
                                if(s[x][y] == 'B')
                                    s[x][y] = '.';
                                else
                                    s[x][y] = 'R';
                                x++;
                                y--;
                            }
                        }
                        else if(s[i][j] == 'G')
                        {
                            ans += 2;
                            int x = i, y = j;
                            while(x < n && y < m && (s[x][y] == 'R' || s[x][y] == 'G'))
                            {
                                if(s[x][y] == 'R')
                                    s[x][y] = '.';
                                else
                                    s[x][y] = 'B';
                                x++;
                                y++;
                            }
                            x = i, y = j;
                            while(x < n && y >= 0 && (s[x][y] == 'B' || s[x][y] == 'G'))
                            {
                                if(s[x][y] == 'B')
                                    s[x][y] = '.';
                                else
                                    s[x][y] = 'R';
                                x++;
                                y--;
                            }
                        }
                    }
                }
                printf("%d
    ", ans);
            }
        }
        return 0;
    }
    

      

  • 相关阅读:
    向量空间模型 词袋模型
    python 小点
    python list的append()和extend()方法
    numpy 数组运算
    内置函数和numpy中的min(),max()函数
    python index()函数
    Python支持的正则表达式元字符和语法
    Python多线程
    查看linux机器配置&内核版本
    Shell获取文件的文件名和扩展名的例子
  • 原文地址:https://www.cnblogs.com/Apro/p/4695752.html
Copyright © 2011-2022 走看看