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

为什么这个代码把int f[30]放在main()里定义就RE了?癫狂....

Posted by wangang at 2010-09-10 22:08:15 on Problem 3536
这个是AC的代码:
#include<iostream>
using namespace std;

int f[30];

int main(){
	int num, i, j, k, a, b, c;
	while(scanf("%d", &num) != EOF){
		int n = 0;
		for(i = 1; i * i <= num; i ++)
			if(num % i == 0){
				f[n ++] = i;
				f[n ++] = num / i;
			}
		int ans = 999999999;
		for(i = 0; i < n; i ++)
			for(j = 0; j < n; j ++){
				if(num % (f[i]*f[j])) continue;
				for(k = 0; k < n; k ++){
					if(f[i]*f[j]*f[k] != num) continue;
					if(f[i]*f[j]+f[j]*f[k]+f[k]*f[i] >= ans) continue;
					ans = f[i]*f[j]+f[j]*f[k]+f[k]*f[i];
					a = f[i]; b = f[j]; c = f[k];
				}
			}
		printf("%d %d %d\n", a, b, c);
	}
	return 0;
}


这个是RE的代码(就int f[30]位置不一样啊0.0|||)
#include<iostream>
using namespace std;

int main(){
	int num, f[30], i, j, k, a, b, c;
	while(scanf("%d", &num) != EOF){
		int n = 0;
		for(i = 1; i * i <= num; i ++)
			if(num % i == 0){
				f[n ++] = i;
				f[n ++] = num / i;
			}
		int ans = 999999999;
		for(i = 0; i < n; i ++)
			for(j = 0; j < n; j ++){
				if(num % (f[i]*f[j])) continue;
				for(k = 0; k < n; k ++){
					if(f[i]*f[j]*f[k] != num) continue;
					if(f[i]*f[j]+f[j]*f[k]+f[k]*f[i] >= ans) continue;
					ans = f[i]*f[j]+f[j]*f[k]+f[k]*f[i];
					a = f[i]; b = f[j]; c = f[k];
				}
			}
		printf("%d %d %d\n", a, b, c);
	}
	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