牛客小白月赛85(A-B)

发布时间 2024-01-06 16:57:56作者: 月下~观星

牛客小白月赛85

A.ACCEPT

算法分析:

凑出
ACCEPT个数

map统计A,C/2,E,P,T的个数

注意:

蒻蒟map用法用错导致简单题wa

map<int,char>

p['A']++时会判断'A'为int类型而不是char类型读为Ascill码

map<char,int>读入就没问题了

  #include<bits/stdc++.h>
using namespace std;
int n;
typedef long long ll;
int t;
int m[100010];
void sovle()
{
    cin >> n;
    string a;
    cin >> a;
    map<char,int>p;
    for (int i = 0; i < a.size(); i++)
        p[a[i]]++;
    // int A,c,e,P,T;
    m[1] = p['A'];
    m[2] = p['C'] / 2; m[3] = p['E']; m[4] = p['P']; m[5] = p['T'];
    int res = 1e9;
    for (int i = 1; i <= 5; i++)
        res = min(res, m[i]);
    cout << res << endl;
}
int main()
{
    ios::sync_with_stdio(false); cin.tie(); cout.tie();
    cin >> t;
    while (t--)
        sovle();
    return 0;
}

B.咕呱蛙

算法分析:

垛积术

蒻蒟只会数学写法没有观察思维

写出数列通项公式(高中学的垛积术还没用过高中)

1 3 6 10

2 3 4

1 1

n阶等差数列通式

n阶函数

高中普通的是一阶等差数列,这里是二阶

f(x)=Ax^2+Bx+C

三个未知数三个函数得到f(x)=1/2 x^2 + 1/2 x

f(x)=1/2(x)(x+1)

要使得结果为偶数x或者(x+1)有4的因子才可以先抵消1/2再有2因子

#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
ll n;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n;
    ll ans=1;
    ans=ans*((n-1)/2+1)*4;//(n-1)/2+1求的是有多少个4,整数上取整方法,偶数无影响,奇数会算多一个,不这么特判好像会溢出
   if(n%2!=0)//特判奇数n为偶数结果-1
    {
      ans--;
    }
    cout<<ans;
    return 0;
}