1037. Magic Coupon (25)

时间限制
100 ms
内存限制
32000 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

The magic shop in Mars is offering some magic coupons. Each coupon has an integer N printed on it, meaning that when you use this coupon with a product, you may get N times the value of that product back! What is more, the shop also offers some bonus product for free. However, if you apply a coupon with a positive N to this bonus product, you will have to pay the shop N times the value of the bonus product... but hey, magically, they have some coupons with negative N's!

For example, given a set of coupons {1 2 4 -1}, and a set of product values {7 6 -2 -3} (in Mars dollars M$) where a negative value corresponds to a bonus product. You can apply coupon 3 (with N being 4) to product 1 (with value M$7) to get M$28 back; coupon 2 to product 2 to get M$12 back; and coupon 4 to product 4 to get M$3 back. On the other hand, if you apply coupon 3 to product 4, you will have to pay M$12 to the shop.

Each coupon and each product may be selected at most once. Your task is to get as much money back as possible.

Input Specification:

Each input file contains one test case. For each case, the first line contains the number of coupons NC, followed by a line with NC coupon integers. Then the next line contains the number of products NP, followed by a line with NP product values. Here 1<= NC, NP <= 105, and it is guaranteed that all the numbers will not exceed 230.

Output Specification:

For each test case, simply print in a line the maximum amount of money you can get back.

Sample Input:

4
1 2 4 -1
4
7 6 -2 -3

Sample Output:

43

。。。。。。。。。。。。。。。。我的代码的也很乱

#include"iostream"
#include "algorithm"
#include "string"
#include "vector"
using namespace std;
#define max 100001

int nc[max],np[max];
bool mycompare(int a, int b)
{
return a>b;
}
int main()
{
int c,p,sum=0;
cin >> c;
for(int i=0;i<c;i++)
cin >> nc[i];
sort(nc,nc+c,mycompare);
cin >> p;
for(int i=0;i<p;i++)
cin >> np[i];
sort(np,np+p,mycompare);
int min = c<p? c:p;
int mx = c>p? c:p;
if(mx == min)
{
for(int i=0;i<min;i++)
if(nc[i]*np[i]>=0)
sum +=np[i]*nc[i];
if(sum==0)
sum=np[0]*nc[min-1]>np[min-1]*nc[0]?np[0]*nc[min-1]:np[min-1]*nc[0];//考虑 两个数组符号全部不相同时就去一个数最小的数
}
else
{
if(c==min)
{
for(int i=0;i<c;i++)
{
if(nc[i]*np[i]>=0)
sum +=nc[i]*np[i];
}
if(sum==0)
sum =np[0]*nc[min-1]>np[mx-1]*nc[0]?np[0]*nc[min-1]:np[mx-1]*nc[0];

}

else if(c==mx)
{
for(int i=0;i<p;i++)
{
if(nc[i]*np[i]>=0)
sum +=nc[i]*np[i];
}
if(sum==0)
sum =np[0]*nc[mx-1]>np[min-1]*nc[0]?np[0]*nc[mx-1]:np[min-1]*nc[0];

}
}
cout << sum <<endl;
return 0;
}

浙大pat 1037的更多相关文章

  1. 浙大 PAT 乙级 1001-1075 目录索引

    1001. 害死人不偿命的(3n+1)猜想 1002. 写出这个数 1003. 我要通过! 1004. 成绩排名 1005. 继续(3n+1)猜想 1006. 换个格式输出整数 1007. 素数对猜想 ...

  2. A题进行时--浙大PAT 1001-1010

    pat链接:http://pat.zju.edu.cn 1 #include<stdio.h> 2 int main(){ 3 int a,b; 4 int c; 5 while(scan ...

  3. 浙大pat 1035题解

    1035. Password (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To prepare f ...

  4. 浙大pat 1025题解

    1025. PAT Ranking (25) 时间限制 200 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programmi ...

  5. PAT 1037 在霍格沃茨找零钱(20)(代码+思路)

    1037 在霍格沃茨找零钱(20)(20 分) 如果你是哈利·波特迷,你会知道魔法世界有它自己的货币系统 -- 就如海格告诉哈利的:"十七个银西可(Sickle)兑一个加隆(Galleon) ...

  6. PAT——1037. 在霍格沃茨找零钱

    如果你是哈利·波特迷,你会知道魔法世界有它自己的货币系统 —— 就如海格告诉哈利的:“十七个银西可(Sickle)兑一个加隆(Galleon),二十九个纳特(Knut)兑一个西可,很容易.”现在,给定 ...

  7. PAT 1037 Magic Coupon[dp]

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

  8. PAT 1037. 在霍格沃茨找零钱(20)

    如果你是哈利·波特迷,你会知道魔法世界有它自己的货币系统 -- 就如海格告诉哈利的:"十七个银西可(Sickle)兑一个加隆(Galleon),二十九个纳特(Knut)兑一个西可,很容易.& ...

  9. A题进行时--浙大PAT 1021-1030

    1021: #include<stdio.h> #include<string.h> #include<vector> #include<queue> ...

随机推荐

  1. trove命令翻译(上)(只做翻译,未实验效果)

    The trove client is the command-line interface (CLI) for the Database service API and its extensions ...

  2. 第17章 使用PHP和MySQL实现身份验证

    1.对密码进行加密:sha1(string str,bool raw_output) //将返回一个40个字符的伪随机字符串,若raw_output为true,着得到一个20个字符的二进制字符串数据 ...

  3. Maven之(八)约定优于配置

    maven的配置文件看似很复杂,其实只需要根据项目的实际背景,设置个别的几个配置项而已.maven有自己的一套默认配置,使用者除非必要,并不需要去修改那些约定内容.这就是所谓的"约定优于配置 ...

  4. [趣味]WhirlPolygon——彩色旋转正多边形

    此程序用于在AutoCAD中以直线绘制彩色旋转正多边形供欣赏~ 此程序附属MagicTable(可到依云官网下载:http://www.yiyunsoftware.com/),安装之即可使用该程序. ...

  5. aforge通过角点匹配图片相似度

    我不知道什么原因,人品不好还是啥的 ExhaustiveTemplateMatching这个类无法高精确度的匹配图片 ........... 换一种方式,就好得多 /// <summary> ...

  6. 【python标准库】内建函数

    abs(x) 返回一个数的绝对值.参数可以是普通的整数,长整数或者浮点数.如果参数是个复数,返回它的模. all(iterable) 如果iterable的所有元素为真(或者iterable为空), ...

  7. 微信小程序使用场景及取名“潜”规则

    微信小程序使用场景举例: 1.查看公交 2.登记.选座 3.订票 4.K歌.叫代驾 5.快递查询 6.查看天气 7.医院挂号.拿药.缴费 8.加油充电 9.政务服务 微信公众号“数据三观”认为,小程序 ...

  8. CSU 1812 三角形和矩形

    湖南省第十二届大学生计算机程序设计竞赛$J$题 计算几何. #pragma comment(linker, "/STACK:1024000000,1024000000") #inc ...

  9. 深入了解css3新特性

    深入了解css3新特性:http://www.ibm.com/developerworks/cn/web/1202_zhouxiang_css3/

  10. ora2pg数据迁移

    1.安装strawberry-perl-5.242.安装ora2pg-17.4 #perl Makefile.PL #dmake && dmake install3.安装ora2pg相 ...