牛客ioi周赛23-普及组 1-3题解 总结
发布日期:2021-05-07 03:05:49 浏览次数:159 分类:精选文章

本文共 2415 字,大约阅读时间需要 8 分钟。

1.小L的作文

链接:https://ac.nowcoder.com/acm/contest/11164/A

来源:牛客网

小 L 刚考完期末,他写了一篇很烂的作文,烂到老师都不愿意给它扣分,只能给他加分,已知老师比较牛,所以他发现一个字符 x 就会加一分。问你小 L 最后可以得到多少分。

输入描述:
第一行,给你一个字符 x,表示可以加分的字符。
第二行,给你一个字符串 s,表示文章。

输出描述:

一个整数,表示小 L 得了多少分。

#include 
using namespace std;int main() { char x; string s; cin >> x >> s; int ans=0;//答案 for(auto t:s) ans += t==x;//用t遍历s cout << ans; return 0;}

总结:

题目很简单,但是遍历string的方法需要学习一下,更加简单。

auto遍历,智能指针yyds,自动识别类型。

t==s 很巧妙,等于的话就加一,不等的话加零。

auto遍历适用于所有的遍历,只不过这种遍历是遍历完数据,当要遍历部分数据时就要换一种方法。

auto遍历举例:

数组:

int s[4];    for(int i=0;i<4;i++) cin>>s[i];    for(auto t:s) //用t遍历s   		 cout << t;

map:

map
mp;for(auto i : mp) cout<
<
<<"\n";

set:

set
se;for(suto i:se) cout<

2.小L的多项式

在这里插入图片描述

刚开始我就是无脑做的,连想都没想,一看快速幂,就直接快速幂了。

#include
using namespace std;typedef long long LL;const int mod = 998244353 ;int n,m;int a[1005],x;LL fast(LL a,LL b){ LL res = 1; while(b>0) { if(b&1) res = res*a%mod; b>>=1; a=a*a%mod; } return res;}//龟速乘 long long quick_mul(long long x,long long y) { long long ans=0; while(y!=0){ if(y&1) ans = (ans+x)%mod; //ans+=x,ans%=mod; x = x*2%mod; //x=x+x,x%=mod; y>>=1; } return ans;}int main(){ cin>>n; for(int i=0;i<=n;i++) cin>>a[i]; cin>>m; for(int i=1;i<=m;i++) { LL ans = 0; cin>>x; ans+=a[0]; for(int j=1;j<=n;j++) { ans += (a[j]*fast(x,j))%mod; ans %= mod; } cout<
<<" "; } return 0;}

但其实再看式子可以发现规律:

在这里插入图片描述

#include 
#define mod 998244353 using namespace std;int a[10005];int main() { int n; cin >> n; for(int i=0;i<=n;i++) cin >> a[i]; int q; cin >> q; while(q--) { int x; cin >> x; long long ans=0;//long long for(int i=n;i>=0;i--) ans=(ans*x+a[i])%mod;//每次*x+a[i] cout << ans << " "; } return 0;}

3.小L的编辑器

在这里插入图片描述

在这里插入图片描述

L 后缀 abd -> 要反转

R 前缀 ce -> 不需要反转

#include 
#include
using namespace std;string a,b,x,y;//x后缀,y前缀int main() { cin >> a >> b; int n=a.size(); for(int i=0;i

自己写的方法,模拟

#include
using namespace std;string s1,s2;char ch1[1000005];char ch2[1000005];int main(){ cin>>s1>>s2; int r = 1,l=1; for(int i=0;i
=1;i--) cout<

其实思路差不多一样

4. 小L的数列

dp问题,自己还是不太会,水平也只到这里了,原谅自己太菜了。

建议做一下最长公共子序列的问题。

上一篇:jquery超全详解
下一篇:每日一题-bfs最短路径变式

发表评论

最新留言

感谢大佬
[***.8.128.20]2025年04月06日 09时51分08秒