编程题目
第一题 两方英雄对战最大得分(暴力全排列)
int main(){
int n ;
vector<int> A, B;
cin >> n;
for(int i =0 ; i<n; i++){int x ; cin >> x ; A.push_back(x);}
for(int j =0 ; j<n; j++){int x ; cin >> x ; B.push_back(x);}
sort(A.begin() , A.end());
int maxScore =-1000000000;
do {
int score =0;
for(int i =0 ; i < A.size() ; i++){
if(A[i]-B[i] >0) score++;
else if(A[i]-B[i] <0) score--;
cout << A[i]<<"--";
}
maxScore = maxScore > score?maxScore:score;
}while(next_permutation(A.begin() , A.end() ));
cout << maxScore*100;
return 0;
}
第二题 小朋友不站在自己地方(公式 O(n))
int main(){
int n ;
cin >>n;
if(n==1||n==2){cout << (n==1)?0:1 ; return 0;}
int last = 1;
for(int i = 3 ; i <=n ; i++)
last =last*i + (i%2==0?1:-1);
cout << last;
return 0;
}