B. 250 Thousand Tons of TNT(模拟&前缀和)

Problem - B - Codeforces

解析:

        遍历因子,然后前缀和判断找出最大值即可。

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=2e5+5;
int n,a[N],sum[N];
int func(int k){
	int maxx=0,minn=0x3f3f3f3f3f3f3f3f;
	for(int i=1;i<=n;i+=k){
		maxx=max(maxx,sum[i+k-1]-sum[i-1]);
		minn=min(minn,sum[i+k-1]-sum[i-1]);
	}
//	cout<<maxx<<" "<<minn<<" "<<maxx-minn<<endl;
	return maxx-minn;
}
void solve(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		sum[i]=sum[i-1]+a[i];
	}
	int res=0;
	for(int i=1;i<=n/i;i++){
		if(n%i==0){
			int k=n/i;
			res=max(res,func(k));
			if(i!=k) res=max(res,func(i));
		}
	}
	printf("%lld\n\n",res);
}
signed main(){
	int t=1;
	scanf("%d",&t);
	while(t--) solve();
	return 0;
}
优化这段代码 if ( this.queryParam.tonnageOne == '' || this.queryParam.tonnageTwo == '' || this.queryParam.tonnageThree == '' || this.dataSource.some((item) => !item.feiGangName) || this.dataSource.some((item) => !item.feiGangPrice) || this.dataSourceFeWater.some((item) => !item.tscfhcbName) || this.dataSourceFeWater.some((item) => !item.temp) || this.dataSourceFeWater.some((item) => !item.tscfhcb_C) || this.dataSourceFeWater.some((item) => !item.tscfhcb_Si) || this.dataSourceFeWater.some((item) => !item.tscfhcb_Mn) || this.dataSourceFeWater.some((item) => !item.tscfhcb_P) || this.dataSourceFeWater.some((item) => !item.tscfhcb_S) || this.dataSourceFeWater.some((item) => !item.tscfhcb_Price) ) { this.$message.error('请检查值,或者名称不能为空!!!') } else { this.dataSource.forEach((item) => { item['acoursewareId'] = 3343772731908188 const editableItem = this.editableData[item.id] if (editableItem) { Object.assign(item, editableItem) } }) this.editableData = [] this.dataSourceFeWater.forEach((item) => { item['acoursewareId'] = 3343772731908188 const editableItem = this.editableDataFeWater[item.id] if (editableItem) { Object.assign(item, editableItem) } }) this.editableDataFeWater = [] console.log(this.dataSourceFeWater) // 清空可编辑数据 this.conceal = false this.concealFeWater = false var addZldwInfo = { AcoursewareId: 3343772731908188, tons1: this.queryParam.tonnageOne, tons2: this.queryParam.tonnageTwo, tons3: this.queryParam.tonnageThree, } let param = { addZldwInfo: addZldwInfo, addFgList: this.dataSource, b_TscfhcbListAdd: this.dataSourceFeWater, } FeAdd(param) .then((res) => {}) .catch((error) => {}) }
06-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值