【PAT甲级】1037 Magic Coupon (25 分)
题意:
输入一个正整数N(<=1e5),接下来输入N个整数。再输入一个正整数M(<=1e5),接下来输入M个整数。每次可以从两组数中各取一个,求最大的两个数的乘积的和。
AAAAAccepted code:
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
long long a[],b[];
long long c[],d[];
int cnta,cntb,cntc,cntd;
int main(){
int n,m;
cin>>n;
long long x;
for(int i=;i<=n;++i){
cin>>x;
if(x>)
a[++cnta]=x;
else if(x<)
b[++cntb]=x;
}
cin>>m;
for(int i=;i<=m;++i){
cin>>x;
if(x>)
c[++cntc]=x;
else if(x<)
d[++cntd]=x;
}
long long ans=;
sort(a+,a++cnta);
sort(b+,b++cntb);
sort(c+,c++cntc);
sort(d+,d++cntd);
for(int i=;i<=min(cntb,cntd);++i)
ans+=b[i]*d[i];
for(int i=cnta,j=cntc;i&&j;--i,--j)
ans+=a[i]*c[j];
cout<<ans;
return ;
}
【PAT甲级】1037 Magic Coupon (25 分)的更多相关文章
- PAT 甲级 1037 Magic Coupon (25 分) (较简单,贪心)
1037 Magic Coupon (25 分) The magic shop in Mars is offering some magic coupons. Each coupon has an ...
- PAT 甲级 1037 Magic Coupon
https://pintia.cn/problem-sets/994805342720868352/problems/994805451374313472 The magic shop in Mars ...
- PAT Advanced 1037 Magic Coupon (25) [贪⼼算法]
题目 The magic shop in Mars is ofering some magic coupons. Each coupon has an integer N printed on it, ...
- 1037 Magic Coupon (25分)
The magic shop in Mars is offering some magic coupons. Each coupon has an integer N printed on it, m ...
- PAT 甲级 1020 Tree Traversals (25分)(后序中序链表建树,求层序)***重点复习
1020 Tree Traversals (25分) Suppose that all the keys in a binary tree are distinct positive intege ...
- PAT 甲级 1146 Topological Order (25 分)(拓扑较简单,保存入度数和出度的节点即可)
1146 Topological Order (25 分) This is a problem given in the Graduate Entrance Exam in 2018: Which ...
- PAT 甲级 1071 Speech Patterns (25 分)(map)
1071 Speech Patterns (25 分) People often have a preference among synonyms of the same word. For ex ...
- PAT 甲级 1063 Set Similarity (25 分) (新学,set的使用,printf 输出%,要%%)
1063 Set Similarity (25 分) Given two sets of integers, the similarity of the sets is defined to be ...
- PAT 甲级 1059 Prime Factors (25 分) ((新学)快速质因数分解,注意1=1)
1059 Prime Factors (25 分) Given any positive integer N, you are supposed to find all of its prime ...
随机推荐
- js将后台传入得时间格式化
//格式化时间函数Date.prototype.Format = function (fmt) { var o = { "M+": this.getMonth() + 1, //月 ...
- CentOS6.5_x64安装MySQL-5.6.17,在已经启动MySQL服务的情况下,出现密码报错ERROR 2002 (HY000)
1.修改MySQL配置文件,使MySQL登陆时跳过密码验证 skip-grant-tables 2.重启MySQL服务 service mysql restart 3.进入MySQL,修改user表中 ...
- linux 配置IPSAN存储
一 SAN存储 1.1 SAN存储介绍 存储区域网络(Storage Area Network,简称SAN)采用网状通道(Fibre Channel ,简称FC,区别与Fiber Channel光纤通 ...
- sqlmap+burpsuit
sqlmap可以批量扫描burpsuit导出的requests日志文件,从而进行批量扫描是否存在SQL注入. 首先设置burpsuit记录代理的Requests 把记录的日志文件保存在sqlmap的目 ...
- Vue基础笔记3
插槽指令 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <titl ...
- 【MySQL】数据类型之数字相关
" 目录 #. 数值类型 1. 数值范围验证 /. 有符号 /. 无符号 2. int类型显示长度验证 #. 浮点型 1. 验证 /. 建表 /. 精度 #. 日期类型 1. 验证 /. y ...
- Amoeba介绍及原理
Amoeba的中文意思是变型虫 Amoeba是一个以MySQL为底层数据存储,并对应用提供MySQL协议接口的proxy.它集中地响应应用的请求,依据用户事先设置的规则,将SQL请求发送到特定的数据库 ...
- 第六节:前后端交互之axios用法及async异步编程
一. axios用法 参考: API文档: https://www.kancloud.cn/yunye/axios/234845 GitHub: https://github.com/axios/ax ...
- 使用MQTT.fx客户端接入阿里云
一.前期准备. 1.关于MQTT连接的属性:https://www.cnblogs.com/mhtc/p/11112153.html 2.关于阿里云配置工具的使用:https://www.cnblog ...
- python3将json数据转换到excel中
#!/usr/bin/env python# coding=utf-8# json转换为excel import xlrdimport jsonimport osfrom openpyxl impor ...