【浮*光】【Codeforces Round #490 (Div. 3)】解题报告

来自CF999 &&&

#include <bits/stdc++.h>
using namespace std;

/*【A】从头或尾开始做题,只能完成小于等于k的题,
不能完成就无法前进。问最多能做多少题。 */

const int maxn = 101;
int n,k,a[maxn],cnt,l;

int main(){
    cin>>n>>k;
    for(int i=1;i<=n;++i) cin>>a[i];
    for(int i=1;i<=n;++i){
        if(a[i]<=k) cnt++;
        else { l = i; break; } //左边被卡住的地方
    }
    if(cnt==n){ //全部可以,输出,退出
        cout<<n; return 0;
    }
    for(int i=n;i>l;i--){ //反向
        if(a[i]<=k) ++cnt;
        else break;
    }
    cout<<cnt;
    return 0;

http://codeforces.com/contest/999/problem/B

#include <bits/stdc++.h>
using namespace std;

/*【B】 一个长度为n的字符串t,将n的【因子】从大到小排个序(设为a[i]),
每次把t的第一个字符到第a[i]个字符翻转,得到一个怪异的串s。给出n和s,求t。 */

// 先把n分解质因数,然后进行“逆操作”,即把因子从小到大排序,然后把给的串reverse回去。

const int maxn = 110;
int n,a[maxn],cnt;
string t;
int main() {
    cin>>n>>t;
    for(int i=1;i<=n;++i) //找因子
        if(n%i==0)  a[++cnt]=i;
    for(int i=1;i<=cnt;++i)
        reverse(t.begin(), t.begin() + a[i]); //模拟每个在因子个数处交换
    cout<<t<<endl;
    return 0;
}

http://codeforces.com/contest/999/problem/C

#include <bits/stdc++.h>
using namespace std;

/*【C】给一个长度为n的字符串s,要删除k个字符。
规则:先把a删完,再把b删完......最后(如果可能)把z删完。求删后的串。 */

//统计每个字符出现次数,“前缀和”与k比较,判断临界特殊情况。 

const int maxn = 400004;
char s[maxn],ans[maxn];
int n,k,a[30],stops,res,sum,len;

int main(){
    scanf("%d%d%s",&n,&k,s);
    for(int i=0;i<n;++i) a[s[i]-'a']++;  //注意数组编号
    for(int i=0;i<26;++i){
        sum+=a[i]; //前缀和思想
        if(sum>=k){
            stops=i; //只删一部分的串
            res=k+a[i]-sum; //此串不用删的部分
            break;
        }
    }
    for(int i=0;i<n;++i){
        if(s[i]-'a'>stops) ans[len++] = s[i]; //判断该字符有无
        else if(s[i]-'a'==stops){
            res--; //严格按照删去的个数
            if(res<0) ans[len++]=s[i];
        }
    }
    cout<<ans;
    return 0;
}

http://codeforces.com/contest/999/problem/D

http://codeforces.com/contest/999/problem/E

http://codeforces.com/contest/999/problem/F







猜你喜欢

转载自blog.csdn.net/flora715/article/details/80775830