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

oyjpArt ACM/ICPC算法程序設計空間

// 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 閱讀(1302) 評論(0)  編輯 收藏 引用 所屬分類: 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
我覺得夠創意~
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>
            亚洲视频高清| 欧美中文字幕第一页| 国产精品大片免费观看| 欧美护士18xxxxhd| 欧美日韩视频在线一区二区 | 国产精品久在线观看| 欧美视频观看一区| 国产精品亚洲а∨天堂免在线| 国产精品日韩二区| 伊人久久成人| 中文国产一区| 久久人人97超碰精品888 | 欧美高清视频免费观看| 亚洲国内高清视频| 亚洲精品一区二区三区福利| 一级日韩一区在线观看| 亚洲欧美视频一区| 免费观看在线综合| 国产精品乱码| 91久久精品网| 性久久久久久久久| 亚洲二区视频| 性色av一区二区三区红粉影视| 久久久亚洲欧洲日产国码αv | 亚洲激情视频在线播放| 亚洲精品在线免费观看视频| 小黄鸭精品aⅴ导航网站入口| 久久艳片www.17c.com| 亚洲成人资源| 欧美一区在线直播| 欧美日韩国产一区| 亚洲第一精品福利| 午夜激情一区| 91久久精品久久国产性色也91 | 猫咪成人在线观看| 亚洲婷婷国产精品电影人久久| 久久久久久伊人| 国产日韩精品电影| 亚洲视频在线一区观看| 欧美大片免费观看| 欧美中文字幕精品| 国产精品影片在线观看| 亚洲一区二区三区免费视频| 亚洲电影第1页| 久久综合九色九九| 极品日韩av| 久久久一区二区| 欧美一区国产在线| 国产亚洲一级| 久久精品国产综合精品| 亚洲网站在线观看| 国产精品国产亚洲精品看不卡15| 99riav1国产精品视频| 亚洲激情综合| 欧美成人四级电影| 亚洲啪啪91| 欧美国产日韩一区二区在线观看 | 久久亚洲综合| 性久久久久久| 国产专区欧美精品| 久久噜噜噜精品国产亚洲综合| 亚洲欧美日韩国产| 国产欧美精品| 久久―日本道色综合久久| 欧美一区二区三区免费在线看| 国产精品久久久久aaaa九色| 亚洲欧美另类国产| 欧美一区二区啪啪| 伊人久久av导航| 欧美黄色一级视频| 欧美激情综合亚洲一二区| 在线视频精品| 亚洲女同精品视频| 国产在线成人| 欧美韩日精品| 欧美日韩国产色站一区二区三区| 艳女tv在线观看国产一区| 一区二区电影免费观看| 亚洲欧美视频在线观看| 亚洲欧美不卡| 欧美在线观看网址综合| 黄色精品网站| 亚洲欧洲精品一区二区| 国产精品白丝jk黑袜喷水| 久久精品视频免费| 欧美一区二区三区视频免费| 性欧美xxxx大乳国产app| 亚洲综合色自拍一区| 国产一区二区三区在线免费观看| 欧美aaa级| 欧美日韩亚洲一区二区三区在线观看| 亚洲永久字幕| 欧美14一18处毛片| 性8sex亚洲区入口| 欧美高清视频| 久久久999国产| 欧美日韩理论| 欧美黑人在线播放| 国产日韩欧美三区| 亚洲区在线播放| 狠狠色丁香久久婷婷综合丁香| 亚洲人成亚洲人成在线观看| 国产亚洲一区二区三区| 亚洲精品老司机| 一区在线影院| 亚洲欧美在线x视频| 中文高清一区| 欧美激情第1页| 欧美成人精品一区二区三区| 国产精品嫩草久久久久| 亚洲理论在线观看| 亚洲欧洲精品成人久久奇米网 | 国产一区二区三区免费不卡| 亚洲区一区二区三区| 伊人精品在线| 欧美亚洲网站| 亚洲女同同性videoxma| 欧美大片网址| 欧美91大片| 国精品一区二区| 亚洲一区二区欧美| 亚洲一区二区三区免费视频| 欧美精品三级| 亚洲国产网站| 亚洲精品久久久蜜桃| 免费毛片一区二区三区久久久| 久久男人资源视频| 韩国精品一区二区三区| 欧美影视一区| 久久亚洲一区二区| 一区二区在线观看视频| 午夜精品电影| 久久视频这里只有精品| 国内激情久久| 久久久五月天| 嫩草国产精品入口| 在线观看亚洲一区| 久久亚洲精品一区| 欧美电影免费观看大全| 亚洲国产精品激情在线观看| 久久精品国产清高在天天线| 亚洲深夜福利在线| 欧美日韩国产成人在线| 91久久精品美女高潮| 亚洲精品乱码久久久久久蜜桃麻豆 | 亚洲三级视频在线观看| 欧美黑人在线播放| 一区二区欧美亚洲| 久久久国产亚洲精品| 在线观看日韩国产| 欧美.www| 99视频热这里只有精品免费| 亚洲欧美精品伊人久久| 国产日韩欧美一区在线| 久久精品亚洲精品| 亚洲国产精品黑人久久久| 一本大道久久a久久综合婷婷 | 一区二区av在线| 午夜综合激情| 在线成人激情| 欧美日韩一区二区在线观看| 亚洲淫性视频| 欧美高清成人| 午夜精品成人在线视频| 18成人免费观看视频| 欧美日韩综合一区| 欧美在线视频一区二区三区| 亚洲成人在线网站| 欧美亚洲免费电影| 亚洲日本中文字幕区| 国产精品福利在线观看网址| 销魂美女一区二区三区视频在线| 欧美成在线视频| 香港久久久电影| 亚洲精品乱码久久久久久| 国产精品一区二区久久精品| 美日韩精品免费观看视频| 亚洲最新合集| 欧美高清在线播放| 午夜精品久久久久久久99黑人| 在线播放视频一区| 国产精品视频一区二区高潮| 美女在线一区二区| 欧美专区福利在线| 国产精品99久久99久久久二8 | 欧美色另类天堂2015| 久久精品欧美日韩| 亚洲午夜小视频| 亚洲福利视频三区| 久久久久综合网| 亚洲欧美日韩久久精品 | 欧美一区二区免费视频| 亚洲人成在线影院| 国产在线国偷精品产拍免费yy| 欧美精品一区二区三区四区| 久久国产精品久久久久久久久久 | 久久精品欧美| 久久视频一区二区| 中日韩高清电影网| 亚洲黄一区二区三区|