D. Challenges in school №41 模拟

题目链接

解题思路:判断形成目标状态所须的最小,最大时间,与标准时间对比,在其区间内,则可行,然后模拟

 1 #include<bits/sdtc++.h>
 2 using namespace std;
 3 #define ll long long 
 4 int n, k;
 5 ll maxk = 0ll, mink = 0ll, d;
 6 char str[3050];
 7 vector<int> v[300050];
 8 void solve()
 9 {
10     int p = 0, p2 = 0, kk = mink;
11     while(kk<k){
12         cout << "1 " << v[p][p2] << endl;
13         p2++;
14         if(p2==v[p].size()){
15             p2=0;
16             p++;
17         }
18         else kk++;
19     }
20     cout << v[p].size() - p2;
21     for(int i = p2; i < v[p].size(); i++)
22         cout << " " << v[p][i];
23     cout << endl;
24     while(p<mink){
25         cout << v[p].size();
26         for(int i = 0; i < v[p].size(); i++)
27             cout << " " << v[p][i];
28         cout << endl;
29         p++;
30     }
31 }
32 void check(int p){
33     for(int i = 1; i < n; ){
34         if(str[i] == 'R' && str[i+1] == 'L'){
35             str[i] = 'L';
36             str[i+1] = 'R';
37             v[p].push_back(i);
38             i += 2;
39         }
40         else i++;
41     }
42 }
43 int main()
44 {
45     ios::sync_with_stdio(false);
46     cin.tie(0); cout.tie(0);
47     cin >> n >> k >> (str+1);
48     check(0);
49     while(v[mink].size()&&mink<=k){
50         maxk += v[mink].size();
51         mink++;
52         check(mink);
53     }
54     if(mink<=k&&k<=maxk) solve();
55     else cout << -1 << endl;
56 }

 

posted @ 2020-04-10 22:06  jvruodejxt  阅读(182)  评论(0编辑  收藏  举报

Contact with me