test2的28th错了,有没有佬看看问题在哪
查看原帖
test2的28th错了,有没有佬看看问题在哪
1158336
lym61楼主2023/12/1 00:21
#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
long long cmp(const long long* a, const long long* b)
{
	return *a - *b;
}
int main()
{
	int t;
	scanf("%d", &t);
	while (t--) {
		int n; 
		scanf("%d", &n);
		int* WeiOfbox = (int*)malloc(sizeof(int) * n); assert(WeiOfbox);
		for (int i = 0; i < n; i++) scanf("%d", &WeiOfbox[i]);
		int axm = 1;
		long long max = 0; 
		while (axm < n) { 
			
			if (n % axm == 0) {
				int k = n / axm;
				long long* Karr = (long long*)calloc(k , sizeof(long long)); assert(Karr);
			
				int z = 0;
				for (int i = 0; i < k; i++)
				{
					for (int j = 0; j < axm; j++) 
					{
						Karr[i] += WeiOfbox[z++];

					}

				}
				qsort(Karr, k, sizeof(long long), cmp);
				max = max > Karr[k - 1] - Karr[0] ? max : Karr[k - 1] - Karr[0];
				
				free(Karr);
				Karr = NULL;

			}
			++axm;
			
		}
		printf("%lld\n",max);

		free(WeiOfbox);
		WeiOfbox = NULL;

	}
	

	
	return 0;
}
2023/12/1 00:21
加载中...