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

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

 #include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
const int maxn=;
int coupon1[maxn],coupon2[maxn];
int product1[maxn],product2[maxn];
bool cmp(int a,int b){
return a>b;
}
int main(){
int n,m,c1=,c2=,p1=,p2=;
long long cx,px,ans=;
scanf("%d", &n);
for(int i=;i<n;i++){
scanf("%lld",&cx);
if(cx>=) {
coupon1[c1++]=cx;
}
else {
coupon2[c2++]=cx;
}
}
scanf("%d",&m);
for(int i=;i<m;i++){
scanf("%lld",&px);
if(px>=) {
product1[p1++]=px;
}
else {
product2[p2++]=px;
}
}
sort(coupon1,coupon1+c1,cmp);
sort(coupon2,coupon2+c2);
sort(product1,product1+p1,cmp);
sort(product2,product2+p2);
for(int i=;i<c1;i++){
ans+=coupon1[i]*product1[i];
}
for(int i=;i<c2;i++){
ans+=coupon2[i]*product2[i];
}
printf("%lld",ans);
return ;
}

A1037的更多相关文章

  1. A1037. Magic Coupon

    The magic shop in Mars is offering some magic coupons. Each coupon has an integer N printed on it, m ...

  2. A1037 Magic Coupon (25 分)

    一.技术总结 这也是一个贪心算法问题,主要在于想清楚,怎么解决输出和最大,两个数组得确保符号相同位相乘,并且绝对值尽可能大. 可以用两个vector容器存储,然后排序从小到大或是从大到小都可以,一次从 ...

  3. PAT甲级——A1037 Magic Coupon

    The magic shop in Mars is offering some magic coupons. Each coupon has an integer N printed on it, m ...

  4. 1037 Magic Coupon (25 分)

    1037 Magic Coupon (25 分) The magic shop in Mars is offering some magic coupons. Each coupon has an i ...

  5. 1.21 贪心入门上午PAT例题题解

    1.B1023 #include<cstdio> int a[10]; int main() { for(int i=0;i<=9;i++) { scanf("%d&quo ...

  6. PAT_A1037#Magic Coupon

    Source: PAT A1037 Magic Coupon (25 分) Description: The magic shop in Mars is offering some magic cou ...

  7. PAT甲级题解分类byZlc

    专题一  字符串处理 A1001 Format(20) #include<cstdio> int main () { ]; int a,b,sum; scanf ("%d %d& ...

随机推荐

  1. IGraphicsContainer->AddElement函数

    纠结中...... IGraphicsContainer.AddElement函数应该是比较简单的,可能无论添加什么要素,就是无法显示出结果出来. 难道添加元素前是有什么需要设置的?或是其它一些原因? ...

  2. Windows Server、 Windows 区别

    今天脑补了普通Windows 操作系统与Windows Server区别,感觉清楚了很多. Microsoft WindowsServer,是美国微软公司研制的一套操作体系,它面世于1985年,起先仅 ...

  3. Android sdk manager 更新 5.0 太难了,终于解决

    由于众所周知的原因,必须在hosts中增加一些网址对应,才可以更新 203.208.46.146 www.google.com 203.208.46.1 plus.google.com 203.208 ...

  4. Foj 2296 Alice and Bob(博弈、搜索)

    Foj 2296 Alice and Bob 题意 两个人博弈,规则如下:轮流取0~9中的数字,最后Alice所得的数字个数为1~n中,数位在Alice所取集合中出现奇数次的. 双方想获得尽量多,问A ...

  5. TreadingTCPServer

    TreadingTCPServer实现的socket服务器内部会为每个client创建一个线程,该线程用来和客户端进行交互. 1.TreadingTCPServer基础 使用TreadingTCPSe ...

  6. Angular4 @HostBinding @HostListener

    host属性 @Component({ selector: 'jhi-project', templateUrl: './project.html', styleUrls: [], host: { ' ...

  7. Burnside引理和Polya定理

    转载自:https://blog.csdn.net/whereisherofrom/article/details/79631703 Burnside引理 笔者第一次看到Burnside引理那个公式的 ...

  8. iOS开发中的Markdown渲染

    iOS开发中的Markdown渲染 BearyChat的消息是全面支持Markdown语法的,所以在开发BearyChat的iOS客户端的时候需要处理Markdown的渲染. 主要是两套实现方案: 直 ...

  9. 5、RabbitMQ-订阅模式 Publish/Subscribe

    http://www.rabbitmq.com/tutorials/tutorial-three-java.html 1.模型图 我们之前学习的都是一个消息只能被一个消费者消费,那么如果我想发一个消息 ...

  10. 关于SpringMVC整合freemarker报错问题

    错误信息: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'FreeMa ...