2026年7月23日(课堂笔记)
2026-07-23 20:37:10
发布于:广东
// 桐桐撒金币
//前缀和 前缀的和
1 2 3 4 5 6 7
pre[i] -->[1,i]的和
pre[1]=1;
pre[2]=3;
pre[3]=6;
pre[4]=a[1]+a[2]+a[3]+a[4]=10;
pre[5]=pre[4]+a[5]=15;
//通项
pre[i]=pre[i-1]+a[i];
[L,R]
[1,R]-->pre[r];
[1,R]-[1,L-1]
pre[R]-pre[L-1];
//前缀最大值,前缀最小值
//前缀异或和^
//5 和 9 组成的最大数字(考试版)
//https://www.acgo.cn/problemset/info/111887?teamCode=2042058713337094144
//最多可以换k次
//从最左边开始换
//只将5换做9
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
int k;
cin>>s>>k;
for(int i=0;i<s.size();i++){
if(s[i]=='5'&&k>0){
s[i]='9';
k--;
}
}
cout<<s<<endl;
}
//租用机甲
https://www.acgo.cn/problemset/info/112248?teamCode=2042058713337094144
#include <bits/stdc++.h>
//贪心策略:买最便宜的,送最贵的
using namespace std;
long long c,i=0;
int main(){
int a[1000086],res=0,n;
cin>>n;
for(int i=1;i<=n;i++){cin>>a[i];}
sort(a+1,a+1+n);
for(int i=1;i<=(n+1)/2;i++){res=res+a[i];}
cout<<res;
return 0;
}
// 奋斗的小蜗牛
//https://www.acgo.cn/problemset/info/112247?teamCode=2042058713337094144
//白天,晚上
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
#define ll long long
int main(){
int t;
cin>>t;
while(t--){//1e3
int h;cin>>h;
if(h<=10){
cout<<1<<endl;
}
int day=1;h-=10;//提前走完最后一天
day+=(h+4)/5;//前面的天数每天会增加5的高度,反向求h高度需要多少天
// 10
//55
//12
//h/5+1;
//1 :1
//2 :1
//3 :1
//10:1
//11:2;;
//12:2;
//13:2;
//14:2;
//15:2;
//16:3;
//20:3:
//21:4;
//26:5;
//31:6;
// 1 2 3 4 5 6 7 8 9
//1.4--->1
//1.5--->2;
double a=1.4;
int b=a+0.5;
cout<<day<<endl;
}
}
//
以 23 结尾的数字个数
//https://www.acgo.cn/problemset/info/111730?teamCode=2042058713337094144
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
#define ll long long
int a[N],b[N],pre[N];
int main(){
int n,q;
cin>>n>>q;
for(int i=1;i<=n;i++){
cin>>a[i];
if(a[i]%100==23)b[i]=1;
else b[i]=0;
}
for(int i=1;i<=n;i++)pre[i]=pre[i-1]+b[i];
while(q--){
int l,r;
cin>>l>>r;
ll sum=pre[r]-pre[l-1];
cout<<sum<<' ';
}
}
//书架
#include <bits/stdc++.h>
using namespace std;
const int N = 20005;
int hi[N];
int main(){
int n, b;
cin >> n >> b;
for (int i = 1;i <= n;i++){
cin >> hi[i];
}
sort(hi + 1, hi + n + 1, greater<int>());
int i = 1, count = 0, sum = 0;
while (sum < b){
sum += hi[i];
count++;
i++;
}
cout << count;
return 0;
}
//【嵌套循环】【入门】沙漏
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
#define ll long long
int main(){
int l,r;
int n;cin>>n;
l=1;r=n;
for(int i=1;i<=n/2+1;i++){
for(int j=1;j<=r;j++){
if(l<=j&&j<=r)cout<<'*';
else cout<<' ';
}
cout<<endl;
l++,r--;
}
l=n/2;r=l+2;
for(int i=1;i<=n-(n/2+1);i++){
for(int j=1;j<=r;j++){
if(l<=j&&j<=r)cout<<'*';
else cout<<' ';
}
cout<<endl;
l--;r++;
}
}
// 求和
//https://www.acgo.cn/problemset/info/111743?teamCode=2042058713337094144
//5
//a1*a2+a1*a3+a1*a4+a1*a5; a1(a2+a3+a4+a5)
//a2*a3+a2*a4+a2*a5; a2(a3+a4+a5)
//a3*a4+a3*a5 a3(a4+a5)
//a4*a5
//10
//a1*[2,10]
//a2*[3,10];
//a3*[4,10];
//ai*[i+1,n];
//(pre[n]-pre[i])*a[i];
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
#define ll long long
ll a[N],pre[N];
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=n;i++)pre[i]=pre[i-1]+a[i];
ll sum=0;
for(int i=1;i<=n;i++){//n
sum+=a[i]*(pre[n]-pre[i]);
}
cout<<sum<<endl;
}
全部评论 7
/** * _ooOoo_ * o8888888o * 88" . "88 * (| -_- |) * O\ = /O * ____/`---'\____ * . ' \\| |// `. * / \\||| : |||// \ * / _||||| -:- |||||- \ * | | \\\ - /// | | * | \_| ''\---/'' | | * \ .-\__ `-` ___/-. / * ___`. .' /--.--\ `. . __ * ."" '< `.___\_<|>_/___.' >'"". * | | : `- \`.;`\ _ /`;.`/ - ` : | | * \ \ `-. \_ __\ /__ _/ .-` / / * ======`-.____`-.___\_____/___.-`____.-'====== * `=---=' * 拜佛处 * ............................................. * 佛祖保佑 永无BUG * * 祝大家考试考好 天天向上2026-07-23 来自 广东
4老师帅气

2026-07-23 来自 广东
3老师你人真好
2026-07-23 来自 广东
2学生到此一游
2026-07-23 来自 广东
2

































































2026-07-24 来自 广东
1
2026-07-24 来自 广东
1
/** * _ooOoo_ * o8888888o * 88" . "88 * (| -_- |) * O\ = /O * ___/`---'\____ * . ' \\| |// `. * / \\||| : |||// \ * / _||||| -:- |||||- \ * | | \\\ - /// | | * | \_| ''\---/'' | | * \ .-\__ `-` ___/-. / * ___`. .' /--.--\ `. . __ * ."" '< `.___\_<|>_/___.' >'"". * | | : `- \`.;`\ _ /`;.`/ - ` : | | * \ \ `-. \_ __\ /__ _/ .-` / / * ======`-.____`-.___\_____/___.-`____.-'====== * `=---=' * ............................................. * 佛曰:bug泛滥,我已瘫痪! * * 在有些时候佛祖是帮不了你们的哈哈哈! */2026-07-24 来自 广东
06
2026-07-24 来自 山西
0



































有帮助,赞一个