挑战2.7.1 Round 1A 2008 A. Minimum Scalar Product 贪心

题目链接:

https://code.google.com/codejam/contest/32016/dashboard#s=p0

题意:

题解:

代码:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 #define MS(a) memset(a,0,sizeof(a))
 5 #define MP make_pair
 6 #define PB push_back
 7 const int INF = 0x3f3f3f3f;
 8 const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;
 9 inline ll read(){
10     ll x=0,f=1;char ch=getchar();
11     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
12     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
13     return x*f;
14 }
15 //////////////////////////////////////////////////////////////////////////
16 const int maxn = 800+10;
17 
18 ll a[maxn],b[maxn];
19 
20 int main(){
21     freopen("2.7.1_A-large-practice.in","r",stdin);
22     freopen("2.7.1_A-large-practice.out","w",stdout);
23     int T=read();
24     for(int cas=1; cas<=T; cas++){
25         int n = read();
26         for(int i=1; i<=n; i++)
27             a[i] = read();
28         for(int i=1; i<=n; i++)
29             b[i] = read();
30         sort(a+1,a+1+n);
31         sort(b+1,b+1+n);
32         ll ans = 0;
33         for(int i=1; i<=n; i++){
34             ans += a[i]*b[n-i+1];
35         }
36         cout << "Case #" << cas << ": " << ans << endl;
37     }
38 
39     return 0;
40 }
原文地址:https://www.cnblogs.com/yxg123123/p/6827623.html