• Codeforces Round #632 (Div. 2) D-Challenges in school №41(模拟好题)


     Challenges in school №41

     

     

     学习博客:here

    AC_Code;

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 typedef long long ll;
     4 const int maxn = 3e6+10;
     5 const int inf = 0x3f3f3f3f;
     6 const double pi = acos(-1.0);
     7 #define rep(i,first,second) for(ll i=first;i<=second;i++)
     8 #define dep(i,first,second) for(ll i=first;i>=second;i--)
     9 
    10 int n,k;
    11 char str[3005];
    12 vector<int>v[maxn];
    13 ll maxk,mink,d;
    14 
    15 void solve(){
    16     int p=0,p2=0,kk=mink;
    17     while( kk<k ){
    18         cout<<"1 "<<v[p][p2]<<'
    ';//用cout<<"1 "<<v[p][p2]<<endl;就超时了
    19         p2++;
    20         if( p2==v[p].size() ){
    21             p2=0;
    22             p++;
    23         }
    24         else kk++;
    25     }
    26     cout<<v[p].size()-p2;
    27     for(int i=p2;i<v[p].size();i++){
    28         cout<<' '<<v[p][i];
    29     }
    30     cout<<'
    ';//用cout<<endl就超时了
    31     p++;
    32 
    33     while( p<mink ){
    34         cout<<v[p].size();
    35         for(int i=0;i<v[p].size();i++){
    36             cout<<' '<<v[p][i];
    37         }
    38         cout<<'
    ';//用cout<<endl就超时了
    39         p++;
    40     }
    41 }
    42 
    43 void check(int p){
    44     for(int i=1;i<n; ){
    45         if( str[i]=='R' && str[i+1]=='L' ){
    46             str[i]='L';
    47             str[i+1]='R';
    48             v[p].push_back(i);
    49             i+=2;
    50         }
    51         else{
    52             i++;
    53         }
    54     }
    55 }
    56 
    57 int main(){
    58     scanf("%d%d",&n,&k);
    59     scanf("%s",str+1);
    60 
    61     check(0);
    62     while( v[mink].size() && mink<=k ){
    63         maxk += v[mink].size();
    64         mink++;
    65         check(mink);
    66     }
    67     if( mink<=k && k<=maxk ){
    68         solve();
    69     }
    70     else{
    71         printf("-1
    ");
    72     }
    73     return 0;
    74 }
  • 相关阅读:
    Linux下C程序插入执行shell脚本
    #ifdef预编译相关用法
    LAMP开发之环境搭建(2014.12.7在ubuntu下)
    Qt在VS2010的安装与配置
    vs2010配备boost编程环境
    Ubuntu虚拟机与Window、Arm的通信
    大小端测试程序
    Ubuntu安装google Gtest
    设计模式之单例模式
    设计模式之原型模式
  • 原文地址:https://www.cnblogs.com/wsy107316/p/12668645.html
Copyright © 2020-2023  润新知