hdu 3794 Magic Coupon

浙大计算机研究生保研复试上机考试-2011年

贪心:

注意:输入输出用scanf  printf 可以加快速度,用cin WA

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 #include<string>
 5 #include<cmath>
 6 #include<algorithm>
 7 using namespace std;
 8 #define MAX 1000000
 9 __int64 c[MAX+5];
10 __int64 p[MAX+5];
11 __int64 nc,np;
12 int main()
13 {
14     //freopen("INPUT.txt", "r", stdin);
15     while(cin>>nc&&nc>=0){
16         __int64 i=0;
17         for(;i<nc;i++){
18             scanf("%I64d",&c[i]);
19         }
20         cin>>np;
21         i=0;
22         for(;i<np;i++){
23             scanf("%I64d",&p[i]);
24         }
25         sort(c,c+nc);
26         sort(p,p+np);
27         i=0;
28         __int64 sum=0;
29         while(c[i]<0&&p[i]<0&&i<nc&&i<np){
30             sum+=c[i]*p[i];
31             i++;
32         }
33         __int64 cc=nc-1;
34         __int64 pp=np-1;
35         while(c[cc]>0&&p[pp]>0&&cc>=0&&pp>=0){
36             sum+=c[cc]*p[pp];
37             cc--;
38             pp--;
39         }
40         printf("%I64d\n",sum);
41     }
42     return 0;
43 }
时间: 2024-12-30 15:21:56

hdu 3794 Magic Coupon的相关文章

HDU 4149 Magic Potion

题意: a[i] ^ x = f[i] ( i = 1...8 ) 和 ( a[1] + a[2] + ... + a[8] ) ^ x = f[9] 现在f为已知  求x 思路: 从低位到高位确定x值  做法见注释 代码: #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int f[20],t,ans; int main() { int i,k,j; scanf(&

hdu 5125 magic balls(dp)

题目链接:hdu 5125 magic balls #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn = 1005; int N, M, dp[maxn][maxn], A[maxn], B[maxn]; int vec[maxn][maxn], c[maxn]; void init () { scanf("%d%d&quo

PAT 1037. Magic Coupon (25)

1037. Magic Coupon (25) 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 sho

1037. Magic Coupon (25)

题目例如以下: 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 so

HDU 2274 Magic WisKey

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2274 Magic WisKey Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 568    Accepted Submission(s): 323 Problem Description On New Year Festival, Liu

HDU 5834 Magic boy Bi Luo with his excited tree

题目:Magic boy Bi Luo with his excited tree 链接:http://acm.hdu.edu.cn/showproblem.php?pid=5834 题意:给一棵树,在树的每个结点可以收获一定的积分,每一条边会消耗一定的积分,每个结点积分取一次便完,但每次路过一条边,都会消耗积分,问从每一个结点出发,最多能捞多少积分.N范围10万,样例数1万. 思路: 不难的一道题,但细节较多,容易出错. 树形DP. 从i 点出发,大致可以分为向上 和 向下两种,先考虑向下的情

[搜索] hdu 4016 Magic Bitwise And Operation

主题链接: http://acm.hdu.edu.cn/showproblem.php?pid=4016 Magic Bitwise And Operation Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) Total Submission(s): 1315    Accepted Submission(s): 504 Problem Description Given n

1037. Magic Coupon

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

PAT1037. Magic Coupon

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