【lightoj - 1012 - Guilty Prince (一题被搞死)】

本文深入探讨了游戏开发领域的核心技术,包括游戏引擎、Unity、Cocos2d等,以及AI音视频处理技术的应用,如视频分割、语义识别、语音识别等。从理论到实践,为开发者提供全面的技术指导。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

记得很久以前做过这个题目的,那时候记得应该实在福州oj上做过的。

 

 

1012 - Guilty Prince
Time Limit: 2 second(s)Memory Limit: 32 MB

Once there was a king named Akbar. He had a son named Shahjahan. For an unforgivable reason the king wanted him to leave the kingdom. Since he loved his son he decided his son would be banished in a new place. The prince became sad, but he followed his father's will. In the way he found that the place was a combination of land and water. Since he didn't know how to swim, he was only able to move on the land. He didn't know how many places might be his destination. So, he asked your help.

For simplicity, you can consider the place as a rectangular grid consisting of some cells. A cell can be a land or can contain water. Each time the prince can move to a new cell from his current position if they share a side.

Now write a program to find the number of cells (unit land) he could reach including the cell he was living.

Input

Input starts with an integer T (≤ 500), denoting the number of test cases.

Each case starts with a line containing two positive integers W and HW and H are the numbers of cells in the x and y directions, respectively. W and H are not more than 20.

There will be H more lines in the data set, each of which includes W characters. Each character represents the status of a cell as follows.

1) '.' - land

2) '#' - water

3) '@' - initial position of prince (appears exactly once in a dataset)

Output

For each case, print the case number and the number of cells he can reach from the initial position (including it).

Sample Input

Output for Sample Input

4

6 9

....#.

.....#

......

......

......

......

......

#@...#

.#..#.

11 9

.#.........

.#.#######.

.#.#.....#.

.#.#.###.#.

.#.#..@#.#.

.#.#####.#.

.#.......#.

.#########.

...........

11 6

..#..#..#..

..#..#..#..

..#..#..###

..#..#..#@.

..#..#..#..

..#..#..#..

7 7

..#.#..

..#.#..

###.###

...@...

###.###

..#.#..

..#.#..

Case 1: 45

Case 2: 59

Case 3: 6

Case 4: 13

 


PROBLEM SETTER: AKM MUBASHWIR ALAM
SPECIAL THANKS: JANE ALAM JAN (SOLUTION, DATASET)
 
 
 
========================================================================================================================================
先贴自己代码吧。不过还是不能通过,本机都没有通过嘞。。弱弱了。。。
 
  1 // Project name : 1012 ( 1012 Guilty Prince ) 
  2 // File name    : main.cpp
  3 // Author       : iCoding
  4 // E-mail       : honi.linux@gmail.com
  5 // Date & Time  : Wed Aug  8 19:11:24 2012
  6 
  7 
  8 #include <iostream>
  9 #include <stdio.h>
 10 #include <string>
 11 #include <cmath>
 12 #include <algorithm>
 13 using namespace std;
 14 
 15 /*************************************************************************************/
 16 /* data */
 17 #ifndef MAXN
 18 #define MAXN 30
 19 #endif
 20 
 21 const char CH_EMPTY = '.';
 22 const char CH_START = '@';
 23 const char CH_BLOCK = '#';
 24 
 25 int n, m;
 26 
 27 char iMap[MAXN][MAXN];
 28 
 29 int iAnswer;
 30 
 31 int dir_x[4] = {0 , 0, -1, 1};
 32 int dir_y[4] = {-1, 1,  0, 0};
 33 
 34 int start_x;
 35 int start_y;
 36 /*************************************************************************************/
 37 /* procedure */
 38 void debug()
 39 {
 40     cout << "--debug msg--" << endl;
 41 }
 42 void iInit()
 43 {
 44     /*set all memory of iMap to CH_BLOCK*/
 45     for (int i = 0; i < MAXN; i++)
 46     {
 47         for (int j = 0; j < MAXN; j++)
 48         {
 49             iMap[i][j] = CH_BLOCK;
 50         }
 51     }
 52 
 53     /*init for iAnswer*/
 54     iAnswer = 0;
 55 
 56     /*init for iMap*/
 57     for (int i = 1; i <= n; i++)
 58     {
 59         string line;
 60         cin >> line;
 61         //cout << line << endl;
 62         for (int j = 1; j <= m; j++)
 63         {
 64             if      (line[j-1] == CH_EMPTY)
 65             {
 66                 iMap[i][j] = CH_EMPTY;
 67             }
 68             else if (line[j-1] == CH_BLOCK)
 69             {
 70                 iMap[i][j] = CH_BLOCK;
 71             }
 72             else if (line[j-1] == CH_START)
 73             {
 74                 iMap[i][j] = CH_EMPTY;
 75                 start_x = i;
 76                 start_y = j;
 77             }
 78         }
 79     }
 80 }
 81 
 82 bool iCanGo(int x, int y)
 83 {
 84     if (iMap[x][y] == CH_BLOCK)
 85     {
 86         return false;
 87     }
 88     else
 89     {
 90         return true;
 91     }
 92 }
 93 
 94 void iDFS(int x, int y)
 95 {
 96     //debug();
 97     cout << "--" << x <<  " " << y << endl;
 98     /*iMap[x][y] = CH_BLOCK;
 99     iAnswer++;
100     for (int iDirCase = 0; iDirCase < 4; iDirCase++)
101     {
102         if (iCanGo(x + dir_x[iDirCase] , y + dir_y[iDirCase]))
103         {
104             iDFS(x + dir_x[iDirCase] , y + dir_y[iDirCase]);
105         }
106     }*/
107 
108     bool iFlagGo[4] = {false, false, false, false};
109     for (int iDirCase = 0; iDirCase < 4; iDirCase++)
110     {
111         if (iCanGo(x + dir_x[iDirCase] , y + dir_y[iDirCase]))
112         {
113             iFlagGo[iDirCase] = true;
114             iMap[x + dir_x[iDirCase]][y + dir_y[iDirCase]] = CH_BLOCK;
115             iAnswer++;
116         }
117     }
118 
119     for (int iDirCase = 0; iDirCase , 4; iDirCase++)
120     {
121         if (iFlagGo[iDirCase])
122         {
123             iDFS(x + dir_x[iDirCase] , y + dir_y[iDirCase]);
124         }
125     }
126 }
127 
128 
129 /*************************************************************************************/
130 /* main */
131 int main()
132 {
133     int iT;
134     cin >> iT;
135     for (int iCaseCount = 1; iCaseCount <= iT; iCaseCount++)
136     {
137         cout << "Case " << iCaseCount << ": ";
138         cin >> m >> n;
139         iInit();
140         iMap[start_x][start_y] = CH_BLOCK;
141         iAnswer = 1;
142         iDFS(start_x, start_y);
143         cout << iAnswer << endl;
144     }
145     return 0;
146 }
147 
148 // end 
149 // Code by Sublime text 2
150 // iCoding@CodeLab 

 

 

本来今晚是

2012阿里云“凌云杯”高校编程大赛 - 热身赛(时间待定)

 

 

可是进去没题目的。。搞毛啊。。。所以还是自己找题做咯。。

 

 

先上自己代码。等下AC继续。。。

 

 

 

终于AC了。。原来在119杭的iDirCase < 4写成了iDirCase , 4。。。罪过罪过。。害我调试那么久。。

 

  1 // Project name : 1012 ( 1012 Guilty Prince ) 
  2 // File name    : main.cpp
  3 // Author       : iCoding
  4 // E-mail       : honi.linux@gmail.com
  5 // Date & Time  : Wed Aug  8 19:11:24 2012
  6 
  7 
  8 #include <iostream>
  9 #include <stdio.h>
 10 #include <string>
 11 #include <cmath>
 12 #include <algorithm>
 13 using namespace std;
 14 
 15 /*************************************************************************************/
 16 /* data */
 17 #ifndef MAXN
 18 #define MAXN 30
 19 #endif
 20 
 21 const char CH_EMPTY = '.';
 22 const char CH_START = '@';
 23 const char CH_BLOCK = '#';
 24 
 25 int n, m;
 26 
 27 char iMap[MAXN][MAXN];
 28 
 29 int iAnswer;
 30 
 31 int dir_x[4] = {0 , 0, -1, 1};
 32 int dir_y[4] = {-1, 1,  0, 0};
 33 
 34 int start_x;
 35 int start_y;
 36 /*************************************************************************************/
 37 /* procedure */
 38 void debug()
 39 {
 40     cout << "--debug msg--" << endl;
 41 }
 42 void iInit()
 43 {
 44     /*set all memory of iMap to CH_BLOCK*/
 45     for (int i = 0; i < MAXN; i++)
 46     {
 47         for (int j = 0; j < MAXN; j++)
 48         {
 49             iMap[i][j] = CH_BLOCK;
 50         }
 51     }
 52 
 53     /*init for iAnswer*/
 54     iAnswer = 0;
 55 
 56     /*init for iMap*/
 57     for (int i = 1; i <= n; i++)
 58     {
 59         string line;
 60         cin >> line;
 61         //cout << line << endl;
 62         for (int j = 1; j <= m; j++)
 63         {
 64             if      (line[j-1] == CH_EMPTY)
 65             {
 66                 iMap[i][j] = CH_EMPTY;
 67             }
 68             else if (line[j-1] == CH_BLOCK)
 69             {
 70                 iMap[i][j] = CH_BLOCK;
 71             }
 72             else if (line[j-1] == CH_START)
 73             {
 74                 iMap[i][j] = CH_EMPTY;
 75                 start_x = i;
 76                 start_y = j;
 77             }
 78         }
 79     }
 80 }
 81 
 82 bool iCanGo(int x, int y)
 83 {
 84     if (iMap[x][y] == CH_BLOCK)
 85     {
 86         return false;
 87     }
 88     else
 89     {
 90         return true;
 91     }
 92 }
 93 
 94 void iDFS(int x, int y)
 95 {
 96     //debug();
 97     //cout << "--" << x <<  " " << y << endl;
 98     /*iMap[x][y] = CH_BLOCK;
 99     iAnswer++;
100     for (int iDirCase = 0; iDirCase < 4; iDirCase++)
101     {
102         if (iCanGo(x + dir_x[iDirCase] , y + dir_y[iDirCase]))
103         {
104             iDFS(x + dir_x[iDirCase] , y + dir_y[iDirCase]);
105         }
106     }*/
107 
108     bool iFlagGo[4] = {false, false, false, false};
109     for (int iDirCase = 0; iDirCase < 4; iDirCase++)
110     {
111         if (iCanGo(x + dir_x[iDirCase] , y + dir_y[iDirCase]))
112         {
113             iFlagGo[iDirCase] = true;
114             iMap[x + dir_x[iDirCase]][y + dir_y[iDirCase]] = CH_BLOCK;
115             iAnswer++;
116         }
117     }
118 
119     for (int iDirCase = 0; iDirCase < 4; iDirCase++)
120     {
121         if (iFlagGo[iDirCase])
122         {
123             iDFS(x + dir_x[iDirCase] , y + dir_y[iDirCase]);
124         }
125     }
126 }
127 
128 
129 /*************************************************************************************/
130 /* main */
131 int main()
132 {
133     int iT;
134     cin >> iT;
135     for (int iCaseCount = 1; iCaseCount <= iT; iCaseCount++)
136     {
137         cout << "Case " << iCaseCount << ": ";
138         cin >> m >> n;
139         iInit();
140         iMap[start_x][start_y] = CH_BLOCK;
141         iAnswer = 1;
142         iDFS(start_x, start_y);
143         cout << iAnswer << endl;
144     }
145     return 0;
146 }
147 
148 // end 
149 // Code by Sublime text 2
150 // iCoding@CodeLab 

 

 

转载于:https://www.cnblogs.com/ismdeep/archive/2012/08/08/2628898.html

资源下载链接为: https://pan.quark.cn/s/9648a1f24758 这个HTML文件是一个专门设计的网页,适合在告白或纪念日这样的特殊时刻送给女朋友,给她带来惊喜。它通过HTML技术,将普通文字转化为富有情感和创意的表达方式,让数字媒体也能传递深情。HTML(HyperText Markup Language)是构建网页的基础语言,通过标签描述网页结构和内容,让浏览器正确展示页面。在这个特效网页中,开发者可能使用了HTML5的新特性,比如音频、视频、Canvas画布或WebGL图形,来提升视觉效果和交互体验。 原本这个文件可能是基于ASP.NET技术构建的,其扩展名是“.aspx”。ASP.NET是微软开发的一个服务器端Web应用程序框架,支持多种编程语言(如C#或VB.NET)来编写动态网页。但为了在本地直接运行,不依赖服务器,开发者将其转换为纯静态的HTML格式,只需浏览器即可打开查看。 在使用这个HTML特效页时,建议使用Internet Explorer(IE)浏览器,因为一些老的或特定的网页特效可能只在IE上表现正常,尤其是那些依赖ActiveX控件或IE特有功能的页面。不过,由于IE逐渐被淘汰,现代网页可能不再对其进行优化,因此在其他现代浏览器上运行可能会出现问题。 压缩包内的文件“yangyisen0713-7561403-biaobai(html版本)_1598430618”是经过压缩的HTML文件,可能包含图片、CSS样式表和JavaScript脚本等资源。用户需要先解压,然后在浏览器中打开HTML文件,就能看到预设的告白或纪念日特效。 这个项目展示了HTML作为动态和互动内容载体的强大能力,也提醒我们,尽管技术在进步,但有时复古的方式(如使用IE浏览器)仍能唤起怀旧之情。在准备类似的个性化礼物时,掌握基本的HTML和网页制作技巧非常
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值