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

原文地址:https://www.cnblogs.com/kakamilan/p/3118088.html