其他分享
首页 > 其他分享> > 2022/7/15 CSP-S模拟题总结

2022/7/15 CSP-S模拟题总结

作者:互联网

题单贴贴

A.烽火传递

AC code
#include<bits/stdc++.h>
using namespace std;

inline int read(){
	int s=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(isdigit(ch)){
		s=s*10+int(ch-'0');
		ch=getchar();
	}
	return s*f;
}

const int N=2e5+10;

int n,m;
int a[N];
int f[N],q[N];

int main(){
//	freopen("signal.in","r",stdin);
//	freopen("signal.out","w",stdout);
	n=read(),m=read();
	for(int i=1;i<=n;++i)
		a[i]=read();
	int l=1,r=1;
	for(int i=1;i<=n;++i){
		while(l<r && i-q[l]>m) ++l;
		f[i]=f[q[l]]+a[i];
//		if(i==1331) cerr<<q[l]<<endl;
		while(l<=r && f[i]<=f[q[r]])
			--r;
		q[++r]=i;
//		printf("%d %d\n",i,f[i]);
	}
	int ans=0x3f3f3f3f;
	for(int i=max(1,n-m+1);i<=n;++i)
		ans=min(ans,f[i]);
//	cerr<<ans<<endl;
	printf("%d",ans);
	return 0;
}
/*
5 3
1 2 5 6 2
*/

B.小R与回家

C.疯狂的火神

AC code
#include<bits/stdc++.h>
using namespace std;

inline int read(){
	int s=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(isdigit(ch)){
		s=s*10+int(ch-'0');
		ch=getchar();
	}
	return s*f;
}

const int N=1e3+10;

#define ll long long

int T;
int n,t;
ll f[N][N<<2];

struct memr{
	int a,b,c;
	bool operator<(const memr &_){
		return (double)b/c>(double)_.b/_.c;
	}
}in[N];

int main(){
//	freopen("crazy.in","r",stdin);
//	freopen("crazy.out","w",stdout);
	T=read();
	while(T--){
		n=read(),t=read();
		for(int i=1;i<=n;++i){
			in[i].a=read(),in[i].b=read(),in[i].c=read();
		}
		sort(in+1,in+n+1);
		memset(f,0,sizeof(f));
		for(int i=1;i<=n;++i){
			for(int j=t;j;--j){
				if(j>=in[i].c)
					f[i][j]=max(f[i][j],f[i-1][j-in[i].c]+in[i].a-in[i].b*j);
				f[i][j]=max(f[i][j],f[i-1][j]);
			}
		}
		ll ans=0;
		for(int i=1;i<=t;++i)
			ans=max(ans,f[n][i]);
		printf("%lld\n",ans);
	}
	return 0;
}
/*
1
4 10
110 5 9
30 2 1
80 4 8
50 3 2

*/

D.火神的鱼

标签:ch,15,int,模拟题,read,while,freopen,CSP,getchar
来源: https://www.cnblogs.com/Star-LIcsAy/p/16483306.html