【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 ...
随机推荐
- 计算机二级-C语言-程序修改题-190108记录-字符串处理
//程序修改题:给定程序MODI1.C中函数fun的功能是:先将字符串s中的字符按正序存放到t串中,然后把s中的字符按逆序连接到t串的后面.例如:当s中的字符串为:“ABCDE”时,则t中的字符串应为 ...
- Dart语言学习(五)Dart Bool类型
Dart Bool类型和其他语言类似,比较简单 其特点有: 1.使用 bool 表示布尔类型 2.布尔值只有 true 和 false 3.布尔类型bool默认值是null bool isTrue = ...
- dist-packages vs site-packages
dist-packages 和 site-packages的区别 Reference: https://stackoverflow.com/questions/9387928/whats-the-di ...
- django 项目发布(centos 6.5 + python 3.5 + django1.9.8 + paramiko 2.0.2 + gunicorn )
环境 os centos 6.5 64bit python 3.5 django 1.9.8 paramiko 2.0.2 gunicorn 19.6.0 安装 centos install pyth ...
- 如何在centos里面安装php-posix
今天在虚拟机上安装一个系统的插件,出现了You must have POSIX and PCNTL functions to use Video Process,搜了一下缺少插件,那接下来就是安装了. ...
- TCP协议下的服务端并发,GIL全局解释器锁,死锁,信号量,event事件,线程q
TCP协议下的服务端并发,GIL全局解释器锁,死锁,信号量,event事件,线程q 一.TCP协议下的服务端并发 ''' 将不同的功能尽量拆分成不同的函数,拆分出来的功能可以被多个地方使用 TCP服务 ...
- mybatis 源码分析--日志分析
1. MyBatis 没有提供日志实现,需要接入第三方的日志组件,但是第三方的日志组件都各自的Log级别,而不相同 实现方式:适配器模式 Slf4jImpl 2. 自动扫描日志实现,并且第三方日志 ...
- css实现单行和多行省略号
1.单行省略 { width:300px; overflow: hidden; text-overflow:ellipsis; whitewhite-space: nowrap; } 注:单行省略必须 ...
- django.db.utils.OperationalError: (2003, "Can't connect to MySQL server on ‘127.0.0.1’)
报错信息如下: 检查发现原来是自己的sql没有启动 启动mysql后,
- 【工具类】Java中判断字符串是否为数字的五种方法
1 //方法一:用JAVA自带的函数 2 public static boolean isNumeric(String str){ 3 for (int i = str.length();--i> ...