#include <stdio.h>
#include <math.h>
#define MAX 100000
int absolute(int a){
int absoluteValue;
if(a >= 0)
absoluteValue = a;
else if(a < 0)
absoluteValue = -a;
return absoluteValue;
}
int Distance(int A[], int nA){
int i, j;
int distance = 0;
int D[MAX];
int least;
for(i = 0 ; i < nA ; i++){
for(j = 0 ; j < nA ; j++){
distance = absolute(A[i] - A[j]);
D[i] += distance;
}
}
least = D[0];
int index = 0;
for(i = 1 ; i < nA ; i++){
if(least > D[i]){
least = D[i];
index = A[i];
}
}
printf("%d %d", index, least);
}
int main(){
int i;
int nA;
int A[MAX];
scanf("%d", &nA);
for (i = 0 ; i < nA ; i++){
scanf("%d", &A[i]);
}
Distance(A, nA);
}
医院应安装在城镇与医院之间的最小距离处。接收村庄的数量,在第一维度上接收村庄的位置,然后显示医院的安装位置。我不知道怎么了。感谢您的帮助。
答案 0 :(得分:0)
您遇到了三个错误:
class ColorType {
static get RED () {
return "red";
}
static get GREEN () {
return "green";
}
static get BLUE () {
return "blue";
}
}
// Use case.
const color = Color.create(ColorType.RED);