zoukankan      html  css  js  c++  java
  • srm 581 DIV1

    第一题都没做出来,伤不起~~~

     1 #include <iostream>
     2 #include <string>
     3 #include <vector>
     4 #include <cstdlib>
     5 #include <map>
     6 #include <algorithm>
     7 #include <stack>
     8 #include <queue>
     9 #include <cmath>
    10 #include <queue>
    11 using namespace std;
    12 typedef long long ll;
    13 string data = "?-+";
    14 class SurveillanceSystem {
    15 public:
    16     int count(string & containers, int pos, int L) {
    17         int res = 0;
    18         int sz=containers.size();
    19         for (int i = pos; i < min(pos + L,sz); i++) {
    20             if (containers[i] == 'X') {
    21                 res++;
    22             }
    23         }
    24         return res;
    25     }
    26     char check(map<int, int>& rct, map<int, int>& allct,
    27             map<int, int>& curpos) {
    28         string res;
    29         map<int, int>::iterator it;
    30         bool bfang = true;
    31         bool fang = false;
    32         for (it = curpos.begin(); it != curpos.end(); it++) {
    33             int num = it->first;
    34             int numct = it->second;
    35             if (allct[num] - numct < rct[num]) {
    36                 bfang = false;
    37                 break;
    38             }
    39         }
    40         for (it = curpos.begin(); it != curpos.end(); it++) {
    41             int num = it->first;
    42             if (rct[num] > 0) {
    43                 fang = true;
    44                 break;
    45             }
    46         }
    47         if (bfang && fang) {
    48             return 0;
    49         } else if (bfang) {
    50             return 1;
    51         } else {
    52             return 2;
    53         }
    54 
    55     }
    56     string getContainerInfo(string containers, vector<int> reports, int L) {
    57         map<int, int> rct;
    58         int szr = reports.size();
    59         int szc = containers.size();
    60         for (int i = 0; i < szr; i++) {
    61             rct[reports[i]]++;
    62         }
    63         map<int, int>::iterator itr;
    64         string res;
    65         map<int, int> ctnerct;
    66 
    67         for (int i = 0; i < szc - L + 1; i++) {
    68             int t = count(containers, i, L);
    69             ctnerct[t]++;
    70         }
    71         int t;
    72         for (int i = 0; i < szc; i++) {
    73             map<int, int> curpos;
    74             for (int j = max(0, i - L + 1); j < min(szc-L+1, i + 1); j++) {
    75                 int curnum = count(containers, j, L);
    76                 curpos[curnum]++;
    77             }
    78             t = check(rct, ctnerct, curpos);
    79             res=res+data[t];
    80         }
    81         return res;
    82     }
    83 
    84 };

    from kakamilan

  • 相关阅读:
    初探 Redis 客户端 Lettuce:真香!
    vscode 代码中查找并替换为换行符
    Jenkins Kubernetes插件添加 云
    Jenkins kubernetes插件的原理
    jenkins pipeline实现自动构建并部署至k8s
    python3 requests中的 stream参数
    rsync 开启用户密码认证
    rancher1版本 基本使用
    nginx http跳https
    sed合并多条指令修改文本
  • 原文地址:https://www.cnblogs.com/kakamilan/p/3118088.html
Copyright © 2011-2022 走看看