【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 ...
随机推荐
- 03hive_DDL数据定义
一. DDL数据定义 创建数据库 1)create database db_hive; 2)避免要创建的数据库已经存在错误,增加 if not exists 判断. create database i ...
- laravel执行数据库迁移的过程中出现Illuminate\Database\QueryException : SQLSTATE[HY000] [2002] Operation timed out (SQL: select * from information_schema.tables where table_schema = shop and table_name = migrations
向customers表添加字段phone php artisan make:migration add_phone_to_customers_table 问题: 解决方法: 将DB_HOST配置项修改 ...
- ANSYS中 *VWRITE命令使用
目录 1. *VWRITE命令 2. Fortran字段描述符 1. *VWRITE命令 ANSYS输出结果到文件,采用*VWRITE命令,具体命令如下: *VWRITE,Par1,Par2,.... ...
- Plastic Bottle Manufacturer - Consumer Demand For Plastic Bottles Becomes Higher
Since transparent containers enable consumers to clearly see the contents, consumers are increasingl ...
- Python学习笔记:变量
什么是变量? 一般的理解是,变量是一个存储数据的容器 但是在python中的变量只存储数据的引用 变量的特性: 并不直接存储数据,而是引用着某个具体的数据 我们可以人为改变这个引用 定义变量 方式 变 ...
- 《开课》---创业学习--训练营直播第一课--HHR
1,分享三点:敬畏心,学习过程,带着目标学习. 2,融资是个非常专业的技术活. 3,一定不要盲目自信,在资本市场,融资永远是个小概率事件. 4,学习过程:每周解锁学习资料,固定的时间来进行作业答疑. ...
- Spring学习(九)
JdbcTemplate需要的jar包 1.Spring核心必须依赖的库:commons-logging-1.1.1.jar2.Spring IoC部分核心库: spring-beans-4.3.9. ...
- Java学习资源 - J2SE
java.lang包教程 Java集合类详解 Java回顾之集合 Java回顾之序列化 Java回顾之反射 深入理解Java:类加载机制及反射 Java 下高效的反射工具包 ReflectASM 使用 ...
- 关于java继承条件下的构造方法调用
首先是测试代码: class Grandparent { public Grandparent() { System.out.println("GrandParent Created.&qu ...
- [经验] 如何将 Java 项目发布到云服务器上并可以访问
环境: 云服务器 Linux centos7.6 1: 安装 Tomcat (apache-tomcat-9.0.26.tar.gz) 下载压缩包 --> 通过SSH上传到云服务器 --> ...