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

同样是暴力,为什么一个500+,一个tle呢? 麻烦大牛解释一下,谢谢啦.

Posted by ct314171238 at 2008-11-20 18:40:08 on Problem 2769
这个是500+的代码:
#include<iostream>
using namespace std;
#define MAX 300
int s[MAX];
int m[MAX];
int main()
{
    int n, g, i, j, k;
    scanf("%d", &n);
    while(n--){
        scanf("%d", &g);
        memset(s, 0, sizeof(s));
        memset(m, 0, sizeof(m));
        for(i=0; i<g; i++){
            scanf("%d", s+i);
        }
        for(j=1; ; j++){
            for(i=0; i<g; i++){
                m[i] = s[i] % j;
            }
            for(i=0; i<g; i++){
                for(k=i+1; k<g; k++){
                    if(m[k] == m[i])
                        break;
                }
                if(k != g)
                    break;
            }
            if(i == g)
                break;
        }
        printf("%d\n", j);
    }
    return 0;
}


这个是tle的代码:
#include <iostream>
using namespace std;

int flag[1000000];

int main() {
	int n, g, s[301];
	int i, j, tmp;
	scanf("%d", &n);
	while(n--){
		scanf("%d", &g);
		for(i=1; i<=g; i++) scanf("%d", s+i);
		for(j=1; ;j++){
			memset(flag,0,sizeof(flag));
			for(i=1; i<=g; i++){
				tmp = s[i]%j;
				if(flag[tmp]) break;
				flag[tmp] = 1;
			}
			if(i>g) break;
		}
		printf("%d\n",j);
	}
	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