1037. Magic Coupon (25)
#include<iostream>
#include<vector>
#include<stdio.h>
#include<algorithm>
using namespace std; int cmp(int a,int b)
{
return a<b;
} int main()
{
int n,i,j,tem;
while(scanf("%d",&n)!=EOF)
{
getchar();
vector<int> v1;
for(i=;i<n;i++)
{
scanf("%d",&tem);
v1.push_back(tem);
}
getchar();
sort(v1.begin(),v1.end(),cmp); scanf("%d",&n);
getchar();
vector<int> v2;
for(i=;i<n;i++)
{
scanf("%d",&tem);
v2.push_back(tem);
}
sort(v2.begin(),v2.end(),cmp);
int sum = ;
i=;
while(i<v1.size()&&i<v2.size()&&v1[i]<&&v2[i]<)
{
sum+=(v1[i]*v2[i]);
i++;
} i=v1.size()-;j=v2.size()-; while(i>=&&j>=&&v1[i]>&&v2[j]>)
{ sum+=(v1[i]*v2[j]);
--i;
--j;
} printf("%d\n",sum);
} return ;
}
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 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甲题题解-1037. Magic Coupon (25)-贪心,水
题目说了那么多,就是给你两个序列,分别选取元素进行一对一相乘,求得到的最大乘积. 将两个序列的正和负数分开,排个序,然后分别将正1和正2前面的相乘,负1和负2前面的相乘,累加和即可. #include ...
- PAT (Advanced Level) 1037. Magic Coupon (25)
简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...
- 【PAT甲级】1037 Magic Coupon (25 分)
题意: 输入一个正整数N(<=1e5),接下来输入N个整数.再输入一个正整数M(<=1e5),接下来输入M个整数.每次可以从两组数中各取一个,求最大的两个数的乘积的和. AAAAAccep ...
- 1037 Magic Coupon (25 分)
1037 Magic Coupon (25 分) The magic shop in Mars is offering some magic coupons. Each coupon has an i ...
- PAT 1037 Magic Coupon[dp]
1037 Magic Coupon(25 分) The magic shop in Mars is offering some magic coupons. Each coupon has an in ...
- 1037 Magic Coupon
The magic shop in Mars is offering some magic coupons. Each coupon has an integer N printed on it, m ...
随机推荐
- Redis' High Availability
Redis Sentinel is a system designed to help managing Redis instances. It performs the following thre ...
- Android 自学之核心服务
所谓Android的核心服务主要包括熵服务(Entropy Service).电源管理器(Power Manager).Activity管理器(Activity Manager).通话寄存器(Tele ...
- VMware系统运维(二)安装Microsoft .NET 3.5
1.安装vmware vSphere 5.5 之前先安装Microsoft .NET 3.5. 2.安装Microsoft .NET3.5,添加角色和功能. 3.勾选.NET Framework 3. ...
- oracle--clob
最近,收到这样的异常邮件: Error updating database. Cause: java.sql.SQLException: ORA-01461: can bind a LONG val ...
- sqlserver2005数据库18456错误(转)
第一步.以windows验证模式进入数据库管理器.第二步:右击sa,选择属性:在常规选项卡中,重新填写密码和确认密码(改成个好记的).把强制实施密码策略去掉.第三步:点击状态选项卡:勾选授予和启用.然 ...
- 蓝牙 CoreBluetooth
baseK(相关基础知识)蓝牙常见名称和缩写 BLE:(Bluetooth low energy)蓝牙4.0设备因为低耗电,也叫BLEperipheral,central:外设和中心设备,发起链接的是 ...
- C# 计算文件的 Hash 值
/// <summary> /// 提供用于计算指定文件哈希值的方法 /// <example>例如计算文件的MD5值: /// <code> /// String ...
- Android从imageview中获得bitmap
第一种: 使用setDrawingCacheEnabled()和getDrawingCache()这两种方法,第一个是为了设置是否开启缓存,第二个就可以直接获得imageview中的缓存,一般来说需要 ...
- PC电脑运行Android模拟器总是弹出“视频源”窗体的原因和解决方案
原因: PC电脑运行Android模拟器时弹出“视频源”窗体,会让你"选择视频设备",如:HP TruevIsion HD,而这个视频设备就是你电脑中的内置摄像头,这个内置摄像头在 ...
- c#输出json,其中包含子json (可以含 无限级 子json)的方法思路
首页 给出 DataTable 转Json 的方法: public static string TableToJson(DataTable dt) { List<Dictionary<s ...