zoukankan      html  css  js  c++  java
  • A1037

    给两个序列,一一对应相乘,求最大和。

    0不算数,输入时按正负共分为4个数组。

     1 #include<cstdio>
     2 #include<algorithm>
     3 #include<iostream>
     4 using namespace std;
     5 const int maxn=100010;
     6 int coupon1[maxn],coupon2[maxn];
     7 int product1[maxn],product2[maxn];
     8 bool cmp(int a,int b){
     9     return a>b;
    10 }
    11 int main(){
    12     int n,m,c1=0,c2=0,p1=0,p2=0;
    13     long long cx,px,ans=0;
    14     scanf("%d", &n);
    15     for(int i=0;i<n;i++){
    16         scanf("%lld",&cx);
    17         if(cx>=0) {
    18             coupon1[c1++]=cx;
    19         }
    20         else {
    21             coupon2[c2++]=cx;
    22         }
    23     }
    24     scanf("%d",&m);
    25     for(int i=0;i<m;i++){
    26         scanf("%lld",&px);
    27         if(px>=0) {
    28             product1[p1++]=px;
    29         }
    30         else {
    31             product2[p2++]=px;
    32         }
    33     }
    34     sort(coupon1,coupon1+c1,cmp);
    35     sort(coupon2,coupon2+c2);
    36     sort(product1,product1+p1,cmp);
    37     sort(product2,product2+p2);
    38     for(int i=0;i<c1;i++){
    39         ans+=coupon1[i]*product1[i];
    40     }
    41     for(int i=0;i<c2;i++){
    42         ans+=coupon2[i]*product2[i];
    43     }
    44     printf("%lld",ans);
    45     return 0;
    46 }
  • 相关阅读:
    推理思维
    模糊数学
    Android 加法程序
    线程特点
    单例模式的优缺点
    lua 字符串过滤,特殊字符过滤
    cocos2dx
    cocos2dx之控制台输出
    C++基础(using)
    生活常识
  • 原文地址:https://www.cnblogs.com/Lynn-2019/p/10391438.html
Copyright © 2011-2022 走看看