Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

枚举就好了。

Posted by canyousayyes at 2012-08-20 15:05:05 on Problem 3782
枚举第一组包含多少个数字,然后嘗试把后面的数列分成同等和的组別。
複杂度O(N^2),不过数据太弱了,0ms过

代码如下︰

#include <iostream>
#include <cstdio>
using namespace std;
int main(){
	int p, m, d[10010], i, j, z, minsum, sum;
	scanf("%d", &p);
	while(p--){
		scanf("%d%d", &z, &m);
		for (i=0; i<m; i++) scanf("%d", d+i);
		for (i=0, minsum=0; i<m; i++){
			minsum+=d[i];
			for (j=i+1, sum=0; j<m; j++){
				sum+=d[j];
				if (sum>minsum) break;
				if (sum==minsum) sum=0;
			}
			if (j==m && sum==0) break;
		}
		printf("%d %d\n", z, minsum);
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator