1501 Country in a map
来源:互联网 发布:淘宝上做代理赚钱吗 编辑:程序博客网 时间:2024/06/05 20:18
Accept: 264 Submit: 456
Time Limit: 1000 mSec Memory Limit : 32768 KB
Problem Description
You are given a rectangular map of a continent. The map is a grid of squares, each square has a color. A country is a connected set of squares (squares are connected if they share an edge) that have the same color. Neighboring countries have different colors. Find the size (in squares) of the largest country.
There will be at least one country in the map.
There will be at least one country in the map.
Input
Input data will be provided as standard input to the program. The first line of input contains the number of test cases (<=10). Each test case begins with a line containing two numbers W and H, the width and height of the map, separated by a single space, 1 <= W,H <= 10. The next H lines contain W characters each | they describe the map. Colors are represented by the letters A-Z. Water (no country) is represented by a dot.
Output
For each test case output one line containing the size of the largest country.
Sample Input
1
6 5
...BBB
.AAAAB
..BBA.
..BB..
......
Sample Output
5
Source
FOJ月赛-2007年5月我的程序:
#include<iostream>
using namespace std;
typedef struct{
char val;
bool flag;
}VF;
VF map[100][100];
char ch;
int thisarea=0;
int m,n;
int visit(int i,int j)
{
if(map[i][j].flag==false && map[i][j].val!='.' && map[i][j].val==ch)
{
map[i][j].flag=true;
thisarea++;
if(i-1>=0)
visit(i-1,j);
if(i+1<m)
visit(i+1,j);
if(j-1>=0)
visit(i,j-1);
if(j+1<n)
visit(i,j+1);
}
return thisarea;
}
int main()
{
int i,j,count,area;
cin>>count;
while(count>0)
{
area=0;
cin>>n>>m;
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
cin>>map[i][j].val;
map[i][j].flag=false;
}
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
ch=map[i][j].val;
thisarea=0;
visit(i,j);
if(thisarea>area)
area=thisarea;
}
count--;
cout<<area<<endl;
}
return 0;
}
using namespace std;
typedef struct{
char val;
bool flag;
}VF;
VF map[100][100];
char ch;
int thisarea=0;
int m,n;
int visit(int i,int j)
{
if(map[i][j].flag==false && map[i][j].val!='.' && map[i][j].val==ch)
{
map[i][j].flag=true;
thisarea++;
if(i-1>=0)
visit(i-1,j);
if(i+1<m)
visit(i+1,j);
if(j-1>=0)
visit(i,j-1);
if(j+1<n)
visit(i,j+1);
}
return thisarea;
}
int main()
{
int i,j,count,area;
cin>>count;
while(count>0)
{
area=0;
cin>>n>>m;
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
cin>>map[i][j].val;
map[i][j].flag=false;
}
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
ch=map[i][j].val;
thisarea=0;
visit(i,j);
if(thisarea>area)
area=thisarea;
}
count--;
cout<<area<<endl;
}
return 0;
}
- 1501 Country in a map
- hdu 4340 Capturing a country
- hdu 4340 Capturing a country
- HDU 4340 Capturing a country ()
- How To Loop A Map In Java
- The most happiest country in the world
- POJ3114 Country in Wars Tarjan+Dij
- Ralph And His Tour in Binary Country
- 【树形DP】 hdu4340 Capturing a country
- hdu - 4340 - Capturing a country - 树形dp
- HDU4340 Capturing a country 树状DP经典
- HDU 4340 Capturing a country 树形DP
- HDU 4340 Capturing a country(树形DP)
- HDU4340 Capturing a country 树形dp
- How to Iterate Over a Map in Java
- How to Iterate Over a Map in Java
- How to initialize a static const map in c++?
- c++函数映射(Mapping Functions to a Map in C++)
- 内核比较2.6 内核中改进了内存管理
- sizeof() 用法汇总
- 怎样在symbian 程序中添加背景图片
- Windows下PHP+mysql+apache安装(%100成功)
- DOOM启世录的启示
- 1501 Country in a map
- 哀悼青海玉树遇难同胞
- 4 使用持久化对象
- 使用AjaxPro调用Session、Cookie
- 进程与线程
- 虚函数 析构函数 抽象类
- 怎么从S60 Epoc上删除应用程序
- 超好的HTML解析工具PHP Simple HTML DOM Parser 中文手册
- Intent的一些用法(不断更新)