青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

oyjpArt ACM/ICPC算法程序設(shè)計(jì)空間

// I am new in programming, welcome to my blog
I am oyjpart(alpc12, 四城)
posts - 224, comments - 694, trackbacks - 0, articles - 6

TopCoder SRM341 LandAndSea

Posted on 2007-03-17 20:02 oyjpart 閱讀(1301) 評(píng)論(0)  編輯 收藏 引用 所屬分類(lèi): ACM/ICPC或其他比賽
Problem Statement for LandAndSea

Problem Statement

????

Bob's father bought him a toy map of islands and seas. The map is a two-dimensional grid where each cell is either 'x' or '.'. A sea is defined as a maximal connected group of '.' cells, where two '.' cells are connected if they are vertically or horizontally adjacent. An island is defined as a maximal connected group of 'x' cells, where two 'x' cells are connected if they are vertically, horizontally, or diagonally adjacent. An island has a level of 0 if it contains no other islands. An island has a level of K+1 if it contains one or more islands and the highest level of a contained island is K. An island A contains island B if A and B are different and, if you start sailing from any point of island B, you won't be able to sail out of island A (you can sail only horizontally and vertically, but not diagonally).

For example, the given map below has 5 islands with level 0 (islands 0 - 4 on the right picture) and one island with level 1 (island 5). Please note that starting at island 3, you can not sail outside island 5 (you can not sail diagonally), but its possible get out of island 1 when starting at island 4.

xxx.x...xxxxx        000.0...11111
xxxx....x...x        0000....1...1
........x.x.x        ........1.4.1
..xxxxx.x...x        ..55555.1...1
..x...x.xxx.x        ..5...5.111.1
..x.x.x...x..        ..5.3.5...1..
..x...x...xxx        ..5...5...111
...xxxxxx....        ...555555....
x............        2............

Given a String[] seaMap, return a int[], where the k-th element is the number of islands of level k. The int[] must contain exactly (m + 1) elements, where m is the highest level of an island in the map.

?

Definition

????
Class: LandAndSea
Method: howManyIslands
Parameters: String[]
Returns: int[]
Method signature: int[] howManyIslands(String[] seaMap)
(be sure your method is public)
????
?

Constraints

- seaMap will contain between 1 and 50 elements, inclusive.
- Each element of seaMap will contain between 1 and 50 characters, inclusive.
- Each element of seaMap will contain the same number of characters.
- Each element of seaMap will contain only '.' and lowercase 'x' characters.
?

Examples

0)
????
{"x"}
Returns: {1 }
1)
????
{
"xxxxx",
"x...x",
"x.x.x",
"x...x",
"xxxxx"
}
Returns: {1, 1 }
2)
????
{
"xxxxx",
"x...x",
"x.x.x",
"x...x",
"xxxxx",
"xxxxx",
"x...x",
"x.x.x",
"x...x",
"xxxxx"
}
Returns: {2, 1 }
3)
????
{
"..",
".."
}
Returns: { }
4)
????
{
"............",
".......xxxx.",
"..xxx.x...x.",
"..x..x..x.x.",
"..x.x.x...x.",
"..xx...xxx.."
}
Returns: {1, 1 }
TopCoder 官方Solution
我覺(jué)得夠創(chuàng)意~
LandAndSea
??
Used as: Division Two - Level Three:
Value1050
Submission Rate26 / 694 (3.75%)
Success Rate1 / 26 (3.85%)
High Scorevanessa for 457.68 points (48 mins 19 secs)
Average Score457.68 (for 1 correct submission)
Used as: Division One - Level Two:
Value550
Submission Rate250 / 544 (45.96%)
Success Rate73 / 250 (29.20%)
High Scoregozman for 359.52 points (23 mins 28 secs)
Average Score250.35 (for 73 correct submissions)

The solution can be split into two parts - generating a tree with nodes considered as? islands and seas and finding the number of islands of each level. In generating a tree, we will add covering waters '.' as the boundary of the map. We use the flood fill to find all seas and islands. The sea connected with the boundary element is defined as the root of the tree. From each visited sea we will visit unvisisted islands if they have at least one element vertically or horizontally adjacent to any element of the sea. From each visited island we will visit unvisisted seas if they have at least one element vertically, horizontally, or diagonally adjacent to any element of the island.

                    ...............000000000000000
xxx.x...xxxxx .xxx.x...xxxxx.011101000222220 xxxx....x...x .xxxx....x...x.011110000200020 ........x.x.x .........x.x.x.000000000203020 ..xxxxx.x...x ...xxxxx.x...x.000444440200020 ..x...x.xxx.x -> ...x...x.xxx.x.000466640222020 ..x.x.x...x.. ...x.x.x...x...000467640002000 ..x...x...xxx ...x...x...xxx.000466640002220 ...xxxxxx.... ....xxxxxx.....000044444400000 x............ .x.............050000000000000
............... 000000000000000

In the picture above, connected groups 0 and 6 are seas and connected groups are islands. The root 0 has children 1, 2, 3, 4, 5. The node 4 has a child 6(a sea). The sea 6 has a child 7(an island).

After creating the tree, it is easy to find the number of islands of each level as following. Any island or sea that have no child will be defined as level 1 and 0, respectively. The level of each island is defined as the maximum level of all its own children plus 1 and the level of each sea is defined as the maximum level of all its own children.
下面是官方提供的參賽者的code:
#include?<iostream>
#include?<sstream>
#include?<cstdio>
#include?<cstdlib>
#include?<cmath>
#include?<memory>
#include?<cctype>
#include?<string>
#include?<vector>
#include?<list>
#include?<queue>
#include?<deque>
#include?<stack>
#include?<map>
#include?<set>
#include?<algorithm>
using?namespace?std;

typedef?long?long?Int;
typedef?pair<int,int>?PII;
typedef?vector<int>?VInt;

#define?FOR(i,?a,?b)?for(i?=?a;?i?<?b;?i++)
#define?RFOR(i,?a,?b)?for(i?=?a?-?1;?i?>=?b;?i--)
#define?CLEAR(a,?b)?memset(a,?b,?sizeof(a))
#define?COPY(a,?b)?memcpy(a,?b,?sizeof(a))
#define?SIZE(a)?int((a).size())?
#define?ALL(a)?(a).begin(),(a).end()?
#define?FOREACH(i,?a)?for(i?=?(a).begin();?i?!=?(a).end();?i++)?
#define?PB?push_back
#define?MP?make_pair

vector<string>?A;
int?B[64][64];
int?N,?M;

int?DX[]?=?{1,?-1,?0,?0,?1,?1,?-1,?-1};
int?DY[]?=?{0,?0,?1,?-1,?1,?-1,?1,?-1};

void?dfs(int?x,?int?y,?queue<PII>&?Q)
{
??B[x][y]?=?1;
??int?i;
??int?finish?=?A[x][y]?==?'.'???4?:?8;
??FOR(i,?0,?finish)
??{
????int?xx?=?x?+?DX[i];
????int?yy?=?y?+?DY[i];

????if(xx?<?0?||?xx?>=?N?||?yy?<?0?||?yy?>=?M?||?B[xx][yy])
??????continue;

????if(A[x][y]?==?A[xx][yy])
??????dfs(xx,?yy,?Q);
????else
??????Q.push(PII(xx,?yy));
??}
}

class?LandAndSea?{
??VInt?Res;

??int?F(int?x,?int?y)
??{
????queue<PII>?Q;
????dfs(x,?y,?Q);

????int?res?=?-1;
????while(!Q.empty())
????{
??????int?xx?=?Q.front().first;
??????int?yy?=?Q.front().second;
??????Q.pop();
??????if(B[xx][yy]?==?0)
????????res?=?max(res,?F(xx,?yy));
????}

????if(A[x][y]?!=?'.')
????{
??????res++;
??????while(SIZE(Res)?<=?res)
????????Res.PB(0);

??????Res[res]++;
????}

????return?res;
??}

??public:
??vector?<int>?howManyIslands(vector?<string>?seaMap)?{
????N?=?SIZE(seaMap);
????M?=?SIZE(seaMap[0]);
????int?i;
????FOR(i,?0,?N)
??????seaMap[i]?=?"."?+?seaMap[i]?+?".";

????seaMap.insert(seaMap.begin(),?string(M?+?2,?'.'));
????seaMap.PB(string(M?+?2,?'.'));

????N?+=?2;
????M?+=?2;

????Res.clear();
????A?=?seaMap;
????CLEAR(B,?0);
????F(0,?0);

????return?Res;
??}
};
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲日本电影在线| 久久精品国产亚洲精品| 欧美激情精品久久久久久蜜臀 | 中文在线不卡| 在线亚洲免费| 国产一区二区三区久久久| 久久免费99精品久久久久久| 久久久久久久久久久久久久一区| 亚洲国产日韩欧美| 亚洲精品乱码| 国产日韩在线一区| 欧美va亚洲va日韩∨a综合色| 欧美精品18+| 欧美一区二区三区的| 久久伊伊香蕉| 亚洲一区二区久久| 久久九九全国免费精品观看| 91久久精品国产91久久| 亚洲视频在线免费观看| 伊人久久大香线蕉综合热线| 国产精品久久国产精品99gif| 香蕉亚洲视频| 欧美久久久久久蜜桃| 欧美有码在线观看视频| 女女同性精品视频| 欧美一区=区| 欧美日本高清| 麻豆av福利av久久av| 欧美视频在线观看| 亚洲福利国产精品| 国产视频一区三区| 一区二区福利| 日韩午夜三级在线| 久久婷婷影院| 欧美一区二区三区免费看| 欧美二区在线| 麻豆精品网站| 国产亚洲精品自拍| 亚洲一区二区精品| 野花国产精品入口| 美国十次成人| 久久欧美中文字幕| 国产精品嫩草久久久久| 亚洲精品乱码久久久久久蜜桃麻豆 | 欧美电影打屁股sp| 国语自产精品视频在线看| 一区二区三区精密机械公司| 亚洲人成7777| 久久躁日日躁aaaaxxxx| 久久精品国产亚洲高清剧情介绍| 欧美日韩中文字幕日韩欧美| 亚洲高清免费在线| 亚洲国产欧美一区二区三区久久| 欧美一区二区在线免费观看| 亚洲欧美日韩一区二区三区在线| 欧美激情精品久久久久久| 亚洲承认在线| 亚洲片国产一区一级在线观看| 久久久久久久综合日本| 欧美黄色免费网站| 亚洲欧洲一区二区在线播放| 亚洲第一天堂无码专区| 乱码第一页成人| 欧美黄色成人网| 亚洲另类黄色| 欧美日韩成人一区二区三区| 日韩一级大片在线| 这里只有精品在线播放| 欧美视频精品在线观看| 中文国产成人精品久久一| 亚洲综合不卡| 国产伦精品一区二区三区四区免费 | 久久婷婷蜜乳一本欲蜜臀| 欧美.com| 999在线观看精品免费不卡网站| 免费视频最近日韩| 亚洲日本免费| 亚洲欧美成人一区二区在线电影 | 久久综合给合久久狠狠色| 亚洲大胆美女视频| 亚洲一区二区在线播放| 国产欧美日韩激情| 久久久免费av| 日韩天堂av| 久久9热精品视频| 在线观看福利一区| 欧美日韩午夜激情| 欧美在线高清| 91久久久久久久久久久久久| 久久蜜桃av一区精品变态类天堂| 欧美国产欧美亚州国产日韩mv天天看完整 | 美女999久久久精品视频| 亚洲精品人人| 久久人人看视频| 一区二区三区回区在观看免费视频| 国产精品av免费在线观看| 久久成人精品一区二区三区| 亚洲国产视频直播| 久久精品99久久香蕉国产色戒 | 国产日韩精品入口| 欧美二区在线播放| 欧美一区二区三区免费观看视频 | 午夜精品理论片| 亚洲国产视频一区| 久久久久一区| 亚洲一区二区免费| 亚洲成人在线观看视频| 国产精品一区久久久| 欧美电影在线观看完整版| 午夜精品免费在线| 夜色激情一区二区| 欧美成在线观看| 久久精品免费播放| 亚洲影院免费观看| 亚洲精品美女在线观看| 国产一区清纯| 国产欧美在线看| 欧美午夜激情小视频| 欧美黄色aaaa| 免费视频一区| 久久久久女教师免费一区| 亚洲综合激情| 亚洲香蕉成视频在线观看| 亚洲福利在线观看| 欧美成人精品在线视频| 久久精品中文字幕免费mv| 亚洲宅男天堂在线观看无病毒| 亚洲精品一区二区在线| 在线观看亚洲视频啊啊啊啊| 国产午夜亚洲精品不卡| 国产精品视频第一区| 欧美日韩精品二区第二页| 欧美激情在线播放| 男人的天堂成人在线| 欧美超级免费视 在线| 久久夜色精品一区| 久久免费视频网| 久久视频这里只有精品| 久久午夜视频| 欧美成人亚洲| 欧美日本高清视频| 欧美视频亚洲视频| 国产精品视频大全| 国产亚洲精品久久久久动| 国产区二精品视| 国产专区精品视频| 亚洲动漫精品| 亚洲毛片一区| 中文高清一区| 香港成人在线视频| 久久久www成人免费精品| 美日韩精品免费| 亚洲全部视频| 伊人夜夜躁av伊人久久| 亚洲国产精品久久久久秋霞影院 | 亚洲一区二区三区国产| 欧美一区观看| 免费成人av在线看| 欧美日韩精选| 国产午夜久久| 亚洲欧洲另类| 亚洲一区在线免费观看| 久久精品五月婷婷| 最新日韩中文字幕| 亚洲综合视频1区| 久久影院午夜论| 欧美视频精品一区| 国产在线乱码一区二区三区| 亚洲二区在线| 亚洲欧美日韩精品久久奇米色影视 | 中文日韩电影网站| 久久精彩免费视频| 91久久精品日日躁夜夜躁国产| 一本久久综合亚洲鲁鲁五月天 | 亚洲人成在线观看网站高清| 亚洲在线一区| 欧美国产综合一区二区| 国产精品另类一区| 激情偷拍久久| 亚洲欧美激情四射在线日| 免费亚洲视频| 亚洲在线视频一区| 欧美精品九九99久久| 国产综合色产| 亚洲私人影院| 欧美国产精品一区| 香港久久久电影| 欧美日韩国内自拍| 伊人久久亚洲热| 欧美在线播放高清精品| 最新精品在线| 久久精品亚洲乱码伦伦中文| 国产精品v一区二区三区| 亚洲电影av| 久久久久久免费| 一本色道久久综合亚洲精品高清| 久久av最新网址| 国产精品一区在线播放| 日韩一级在线观看| 欧美激情欧美狂野欧美精品|