啊哈哈哈哈,鸡汤来咯

暴力

题目大意

给一个范围 个数 ,在这个范围中找到一个数 ,使得 最小的情况下 最小

解法

暴力枚举 中的所有数,然后记录 的数,在求个最小值即可。

时间复杂度:O(rn)

代码如下~

//
#include <bits/stdc++.h>
#define ll long long
#define LM LLONG_MAX
#define IM INT_MAX
#define IMN INT_MIN
#define LMN LLONG_MIN
#define tr true
#define fa false 

using namespace std;

const int Maxn = 3e3 + 1;
ll k, l, r, n, ans = LM, a[Maxn];

int main(){
 freopen("remainder.in", "r", stdin);
 freopen("remainder.out", "w", stdout);
  cin >> n >> l >> r;
  for(int i = 1; i <= n; i++){
  	cin >> a[i];
  }
  for(int i = l; i <= r; i++){
  	ll sum = 0;
  	for(int j = 1; j <= n; j++){
  		sum += (a[j] % i);
  	}
  	// if(i == 20){
  		// cout << a[1] << ' ' << i << endl;
  	// }
  	if(sum < ans){
  		ans = sum;
  		k = i;
  	}
  }
  cout << k << endl;
  return 0;
}  

如有错误,请指出,谢谢🙏