zoukankan      html  css  js  c++  java
  • SRM 578 DIV2 DIV1

    玩了二十多次,终于杀到了div1,纪念一下

    1、水题,求最大最小值的问题。

    2、话说找工作的时候有道类似的题,也是在图上遍历,然后将符合性质的点归为一类,将种类数计为n,且最少有一个,那么就是

        2^n - 1种。

     1 #include <iostream>
     2 #include <string>
     3 #include <vector>
     4 #include <cstdlib>
     5 #include <cmath>
     6 #include <map>
     7 #include <stack>
     8 #include <algorithm>
     9 #include <list>
    10 #include <ctime>
    11 #include <set>
    12 #include <queue>
    13 typedef long long ll;
    14 using namespace std;
    15 #define CLR(arr, what) memset(arr, what, sizeof(arr))
    16 int pos[100][100];
    17 int r, c;
    18 void dfs(int x, int y, int cur, int dist) {
    19     if (x < 0 || x >= r || y < 0 || y >= c)
    20         return;
    21 
    22     if (pos[x][y] == 1) {
    23         pos[x][y] = cur;
    24         for (int i = x - dist; i < x + dist + 1; i++) {
    25             for (int j = y - dist; j < y + dist + 1; j++) {
    26                 int tmp = abs(i - x) + abs(j - y);
    27                 if (tmp <= dist) {
    28                     dfs(i, j, cur, dist);
    29                 }
    30             }
    31         }
    32     } else if (pos[x][y] == 0) {
    33         return;
    34     } else {
    35         return;
    36     }
    37 }
    38 class GooseInZooDivTwo {
    39 public:
    40     int count(vector<string> field, int dist) {
    41         r = field.size();
    42         c = field[0].size();
    43         for (int i = 0; i < r; i++) {
    44             for (int j = 0; j < c; j++) {
    45                 pos[i][j] = (field[i][j] == 'v');
    46             }
    47         }
    48         int tag = 1;
    49         for (int i = 0; i < r; i++) {
    50             for (int j = 0; j < c; j++) {
    51                 if (pos[i][j] == 1) {
    52                     tag++;
    53                     dfs(i, j, tag, dist);
    54                 }
    55             }
    56         }
    57         if (1 == tag)
    58             return 0;
    59         int res = 1;
    60         for (int i = 1; i < tag; i++) {
    61             res = (res * 2) % 1000000007;
    62         }
    63         res = res - 1;
    64         return res;
    65     }
    66 };

    3、第三题没思路,伤不起。

     DIV-1

    1、和div-2的第二题类似,多了一个限制条件。

     1 #include <iostream>
     2 #include <string>
     3 #include <vector>
     4 #include <cstdlib>
     5 #include <cmath>
     6 #include <map>
     7 #include <stack>
     8 #include <algorithm>
     9 #include <list>
    10 #include <ctime>
    11 #include <set>
    12 #include <queue>
    13 typedef long long ll;
    14 using namespace std;
    15 #define CLR(arr, what) memset(arr, what, sizeof(arr))
    16 int pos[100][100];
    17 int r, c;
    18 int dfs(int x, int y, int cur, int dist) {
    19     if (x < 0 || x >= r || y < 0 || y >= c)
    20         return 0;
    21 
    22     if (pos[x][y] == 1) {
    23         int res = 1;
    24         pos[x][y] = cur;
    25         for (int i = x - dist; i < x + dist + 1; i++) {
    26             for (int j = y - dist; j < y + dist + 1; j++) {
    27                 int tmp = abs(i - x) + abs(j - y);
    28                 if (tmp <= dist) {
    29                     res = res + dfs(i, j, cur, dist);
    30                 }
    31             }
    32         }
    33         return res;
    34     } else if (pos[x][y] == 0) {
    35         return 0;
    36     } else {
    37         return 0;
    38     }
    39 }
    40 class GooseInZooDivOne {
    41 public:
    42     int count(vector<string> field, int dist) {
    43         r = field.size();
    44         c = field[0].size();
    45         for (int i = 0; i < r; i++) {
    46             for (int j = 0; j < c; j++) {
    47                 pos[i][j] = (field[i][j] == 'v');
    48             }
    49         }
    50         int tag = 1;
    51         int odd = 0;
    52         int even = 0;
    53         for (int i = 0; i < r; i++) {
    54             for (int j = 0; j < c; j++) {
    55                 if (pos[i][j] == 1) {
    56                     tag++;
    57                     int tmp = dfs(i, j, tag, dist);
    58                     if ((tmp % 2) == 0) {
    59                         even++;
    60                     } else {
    61                         odd++;
    62                     }
    63                 }
    64             }
    65         }
    66         if (1 == tag)
    67             return 0;
    68         int res = 1;
    69         for (int i = 0; i < (even); i++) {
    70             res = (res * 2) % 1000000007;
    71         }
    72 
    73         for (int i = 0; i < (odd - 1); i++) {
    74             res = (res * 2) % 1000000007;
    75         }
    76         res = res - 1;
    77         return res;
    78     }
    79 };

    from kakamilan

  • 相关阅读:
    zoj_3710Friends
    javamail例子
    HttpURLConnection类的用法
    发送邮件协议
    栈的定义
    tomcat中添加jconsole服务
    HttpURLConnection类的用法
    javamail例子
    tomcat中添加jconsole服务
    栈的定义
  • 原文地址:https://www.cnblogs.com/kakamilan/p/3056301.html
Copyright © 2011-2022 走看看