牛客小白月赛85(A-B)
牛客小白月赛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;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现