`

SRM 398 Div II Level One: MinDifference

 
阅读更多

题目来源:http://community.topcoder.com/tc?module=ProblemDetail&rd=12170&pm=8161


代码如下:

#include <climits>
#include <cmath>

/************** Program  Begin *********************/
int Alist[10000];
class MinDifference {
public:
    int closestElements(int A0, int X, int Y, int M, int n) {
	Alist[0] = A0;
	for (int i = 1; i < n; i++) {
		Alist[i] = (Alist[i-1] * X + Y) % M;
	}

	int mind = INT_MAX;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if ( abs(Alist[i] - Alist[j]) < mind ) {
				mind = abs(Alist[i] - Alist[j]);
			}
		}
	}

	return mind;
    }
};

/************** Program End ************************/


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics