SRM 593 1A 2013.12.10

SRM 593 1A 2013.12.10

DIV 1

250

 

Problem Statement


    

   

The pony Applejack has an N by N hexagonal board. The following picture shows the hexagonal board when N = 1, 2, 3, and 4.

 

The pony Applejack has an N by N hexagonalboard. The following picture shows the hexagonal board when N = 1, 2, 3, and4.     She wants to color some cells ofthe board. You are given a vector <string> board. If the j-th characterof the i-th element of board is 'X', she wants to color the cell (i, j). If shecolors two cells that share an edge, she must use different colors for thosecells. Return the minimal number of colors she needs.

Definition

    

Class:

HexagonalBoard

Method:

minColors

Parameters:

vector <string>

Returns:

int

Method signature:

int minColors(vector <string> board)

(be sure your method is public)

    

 

Constraints

-

board will contain between 1 and 50elements, inclusive.

-

Each element of board will contain exactlyN characters, where N is the number of elements in board.

-

Each character in board will be either 'X'or '-'.

Examples

0)

 

    

{"---",

 "---",

 "---"}

 

Returns: 0

She won't color any cells, so she won'tneed any colors.

1)

 

    

{"-X--",

 "---X",

 "----",

 "-X--"}

Returns: 1

She can color all cells with the samecolor.

2)

 

    

{"XXXX",

 "---X",

 "---X",

 "---X"}

Returns: 2

For example, she can color cells in thefollowing way:

Color cells (0, 0), (0, 2), (1, 3), and (3,3) red.

Color cells (0, 1), (0, 3), and (2, 3)blue.

3)

 

    

{"XX-XX--"

,"-XX-XXX"

,"X-XX--X"

,"X--X-X-"

,"XX-X-XX"

,"-X-XX-X"

,"-XX-XX-"}

Returns: 3

 

This problem statement is the exclusive andproprietary property of TopCoder, Inc. Any unauthorized use or reproduction ofthis information without the prior written consent of TopCoder, Inc. isstrictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.

 

CODE

#include<iostream>

#include<vector>

#include<string>

 

using namespace std;

 

class HexagonalBoard

{

private: int max(int a,int b)

                    {

                             if (a>b) return a;return b;

                    }

public: int minColors(vector <string>board)

                   {

                            intans=0,len=board.size();

                            intp[60][60]={0};

                            for(inti=0;i<len;i++)

                                     for(intj=0;j<len;j++)

                                     {

                                               if(board[i][j]=='X')

                                               {

                                                        intx=i+1,y=j+1,endk=len*len;

                                                        for(intk=1;k<=endk;k++)

                                                        {

                                                                 if((k!=p[x-1][y])&&(k!=p[x-1][y+1])&&(k!=p[x][y-1]))

                                                                 {

                                                                           p[x][y]=k;

                                                                           break;

                                                                 }

                                                        }

                                                        if(p[x][y]>ans) ans=p[x][y];

                                               }

                                     }

                            returnans;

                   }

};

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值