const int N=100; double D(N); ... Void preprocess(){ //Write your code here, (1) } double Distance(int i, int j){ // Write your code bere (2) }
#include"iostream" #include"math.h" #define MAX 100 using namespace std; int main(int argc, char* argv[]) { int N; double D[MAX],sum=0,SumD[MAX]; cin>>N; for(int i=0;i<N;i++) { cin>>D[i]; sum+=D[i]; SumD[i] = sum; } while(true) { int a,b; cin>>a>>b; if(a>N||b>N) break; float temp = fabs(SumD[a-1]-SumD[b-1]); cout<<"result: "<<(temp>(sum-temp)?(sum-temp):temp)<<endl; } return 0; }
这道题你会答吗?花几分钟告诉大家答案吧!
扫描二维码,关注牛客网
下载牛客APP,随时随地刷题