2 ruoshui1 ruoshui1 于 2014.06.13 14:56 提问

最小向量乘积,遇见错误请指正

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int main ( )
{
int n;
vector<int> vec1, vec2;
while( EOF != scanf( "%d", &n ) ){
int tmp;
ll sum = 0;
for( int i = 0; i < n; ++i ) {
scanf( "%d", &tmp );
vec1.push_back( tmp );
}
for( int i = 0; i < n; ++i ) {
scanf( "%d", &tmp );
vec2.push_back( tmp );
}
sort( vec1.begin( ), vec1.end( ) );
sort( vec2.begin( ), vec2.end( ), std::greater<int>() );
for( int i = 0; i < n; ++i ) {
sum += vec1[i] * vec2[i];
}
printf( "%lld\n", sum );
}
return 0;
}

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!