2021-11-03 CFS ROUDN 753 水题记录

这里是平时水水比赛的流水账式思路记录,如果有值得研究的题则会另写详细题解。
点这里进入比赛

Problem A. Linear Keyboard

-题意
  最简单的按题意模拟。
-参考代码

#include<iostream>
#include<string>
#include<cmath>
#include<map>
using namespace std;
int main()
{
    int t;
    string s;
    cin>>t;
    while(t--){
        map<char,int> MP;
        for(int i=0;i<26;i++){
            char c;
            cin>>c;

            MP[c] = i;
        }
        cin>>s;
        int ans = 0;
        for(int i=1;i<s.length();i++){
            ans += abs(MP[s[i]]-MP[s[i-1]]);
         
        }
        cout<<ans<<endl;
    }
}

Problem B. Odd Grasshopper

-题意思路
  也是比较简单的类似模拟题,直接找规律即可,然后细节部分再细化下。
-参考代码

#include<iostream>
using namespace std;
typedef long long ll;
int main()
{
    int t;
    ll x0,n;
    cin>>t;
    while(t--){
        cin>>x0>>n;
        if(x0%2==0){  // strat at even
            ll times = n/4;
            ll left = n%4;
            ll ans = 0;
            if(left ==0){
                ans = 0;
            }
            else if(left == 1){
                ans = -(times*4+1);
            }
            else if(left == 2){
                ans = 1;
            }
            else{
                ans = times*4+4;
            }
            ans += x0;
            cout<<ans<<endl;
        }
        else{
            ll times = n/4;
            ll left = n%4;
            ll ans = 0;
            if(left ==0){
                ans = 0;
            }
            else if(left == 1){
                ans = times*4+1;
            }
            else if(left == 2){
                ans = -1;
            }
            else{
                ans = -(times*4+4);
            }
            ans += x0;
            cout<<ans<<endl;      
        }
    }
    return 0;
}

Problem C. Minimum Extraction

-题意思路
  极大化最小值(maximize a minimum),但是属于是最简单的那种,由于每一次变化都是全体变化,所以用相对的思想去理解题意就可以知道求的是最大的相邻差值。(os:比赛的时候脑子抽了MAXN定错了导致4发罚时然后时间也来不及了,我是🥬🐶)
-参考代码

#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN = 2e5 + 10;
typedef long long ll;
int main()
{
    ios::sync_with_stdio(false);
    int t;
    cin >> t;
    int a[MAXN];
    while (t--)
    {
        int n;
        cin >> n;
        for (int i = 0; i < n; i++)
            cin >> a[i];
        sort(a, a + n);
        ll ans = a[0];
        for (int i = 1; i < n; i++)
        {
            ans = max(ans, 1ll * (a[i] - a[i - 1]));
        }
        cout << ans << endl;
    }
    return 0;
}

Problem D. Blue-Red Permutation

-题意思路
  题意很简单,一个数组中规定了一些只能使其变大,一些只能使其变小,问你能否变大变小后实现一个1-n的任意排列。用贪心思想就能做,可以变大的让他尽量变大,可以变小的让他尽量变小,用堆或者排序来确定思考顺序。(os:最后几分钟写的代码略显臃肿了,甚至还没来的及交上去就结束了呜呜呜以后MAXN一定要好好看是多少,而且数组大小开错了这次居然是会爆时间,学到了)
-参考代码

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
const int MAXN = 2e5 + 10;
bool cmp(int a, int b)
{
    return a > b;
}
int main()
{
    int t, n;
    int a[MAXN];
    int b[MAXN];
    int c[MAXN];
    int lenb, lenc;
    string s;
    cin >> t;
    while (t--)
    {
        cin >> n;
        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
        }
        cin >> s;
        lenb = 0;
        lenc = 0;
        for (int i = 0; i < n; i++)
        {
            if (s[i] == 'B')
            {
                b[lenb] = a[i];
                lenb++;
            }
            else
            {
                c[lenc] = a[i];
                lenc++;
            }
        }
        sort(b, b + lenb);
        sort(c, c + lenc, cmp);
        int mini = 1;
        int flag = 1;
        int maxi = n;
        for (int i = 0; i < lenb; i++)
        {
            if (mini <= b[i]) mini++;
            else
            {
                flag = 0;
                break;
            }
        }
        for (int i = 0; i < lenc; i++)
        {

            if (maxi >= c[i])maxi--;
            else
            {
                flag = 0;
                break;
            }
        }
        if (flag)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
}

。。。待补题

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值