• hdu 1204 深搜


    1. #include <iostream>
    2. #include <string>
    3. #define MAX 110
    4. #define OIL true
    5. #define BLANK false
    6. using namespace std;
    7. bool oil_map[MAX][MAX];
    8. int dir_map[8][2]={ {1,0},{-1,0},{0,1},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1} };
    9. void set_oil_map()
    10. {
    11. memset(oil_map,BLANK,sizeof(oil_map) );
    12. }
    13. void input_oil_map(int x,int y)
    14. {
    15. for(int i=1 ;i<=x ;i++)
    16. {
    17. string temp;
    18. cin>>temp;
    19. for(int j=1 ;j<=y ;j++)
    20. {
    21. if(temp[j-1]=='@' )
    22. oil_map[i][j]=OIL;
    23. }
    24. }
    25. }
    26. void search_oil_map(int x ,int y)
    27. {
    28. //if(oil_map[x][y]==OIL )
    29. oil_map[x][y]=BLANK;
    30. int search_x,search_y;
    31. for(int i=0 ;i<8 ;i++)
    32. {
    33. search_x=x+dir_map[i][0];
    34. search_y=y+dir_map[i][1];
    35. if(oil_map[search_x][search_y]==OIL )
    36. search_oil_map(search_x ,search_y );
    37. }
    38. }
    39. int main()
    40. {
    41. int n,m;
    42. while(cin>>m>>n &&(m+n)!=0 )
    43. {
    44. set_oil_map();
    45. input_oil_map(m,n);
    46. int count=0;
    47. for(int i=1 ;i<=m ;i++)
    48. for(int j=1 ;j<=n ;j++)
    49. {
    50. if(oil_map[i][j]==OIL )
    51. {
    52. search_oil_map(i,j);
    53. count++;
    54. }
    55. }
    56. cout<<count<<endl;
    57. }
    58. return 0;
    59. }
    60. /*Problem Description
    61. The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits.
    62. GeoSurvComp works with one large rectangular region of land at a time,
    63. and creates a grid that divides the land into numerous square plots.
    64. It then analyzes each plot separately, using sensing equipment to determine whether or not the plot contains oil.
    65. A plot containing oil is called a pocket. If two pockets are adjacent, then they are part of the same oil deposit.
    66. Oil deposits can be quite large and may contain numerous pockets.
    67. Your job is to determine how many different oil deposits are contained in a grid.
    68. Input
    69. The input file contains one or more grids.
    70. Each grid begins with a line containing m and n,
    71. the number of rows and columns in the grid, separated by a single space.
    72. If m = 0 it signals the end of the input; otherwise 1 <= m <= 100 and 1 <= n <= 100.
    73. Following this are m lines of n characters each (not counting the end-of-line characters).
    74. Each character corresponds to one plot, and is either `*',
    75. representing the absence of oil, or `@', representing an oil pocket.
    76. Output
    77. For each grid, output the number of distinct oil deposits.
    78. Two different pockets are part of the same oil deposit if they are adjacent horizontally,
    79. vertically, or diagonally. An oil deposit will not contain more than 100 pockets.
    80. */





    附件列表

    • 相关阅读:
      使用SWFUpload无刷新上传图片
      WP多语言
      C#将DataTable转化为List<T>
      Android 多语言
      Android开发 Failed to install *.apk on device 'emulator-5554': EOF
      ASP.NET MVC中将数据从Controller传递到视图
      安装和卸载程序时总是出现2502,2503错误代码的解决方法
      position固定菜单栏
      [position]返回顶部
      [css]后台管理系统布局
    • 原文地址:https://www.cnblogs.com/sober-reflection/p/20c27f529a9ad7a43d348fb4a120d0c7.html
    Copyright © 2020-2023  润新知